summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-12-09 00:06:34 +0100
committerGravatar Tom Willemse2013-12-09 00:06:34 +0100
commitd88ad750c22eefd4f65eb768d10a3d4e4d4e04f4 (patch)
tree26b4a506121836d72eaf5e789370251ea4b5798e
parent473969a654f1d8da799e769352a437226b919ee4 (diff)
downloadedocs-d88ad750c22eefd4f65eb768d10a3d4e4d4e04f4.tar.gz
edocs-d88ad750c22eefd4f65eb768d10a3d4e4d4e04f4.zip
Update for use with -batch switch
- Require the `package' and `help-fns' libraries which aren't loaded when using the `-batch' switch with Emacs. - Add options to specify which style sheet to use and whether to only print the body (so no `<doctype>' or `<html>' etc.) - Reverse the list of symbols to show up in the same order as they appear in the buffer. - Replace `case' with a `cond', I didn't realize `case' was part of the cl-lib. - Add function to be used with the `-batch' switch.
-rw-r--r--edocs.el70
1 files changed, 47 insertions, 23 deletions
diff --git a/edocs.el b/edocs.el
index 3f876bf..a80d5da 100644
--- a/edocs.el
+++ b/edocs.el
@@ -25,6 +25,15 @@
;;; Code:
+(require 'package)
+(require 'help-fns)
+
+(defvar edocs-stylesheet-location "style.css"
+ "Where to find the Cascading Style Sheet for the exported docs.")
+
+(defvar edocs-generate-only-body nil
+ "Whether to genereate only the body and no header/footer info.")
+
(defun edocs--list-symbols ()
"Get a list of all symbols in the buffer.
@@ -46,29 +55,29 @@ etc."
(match-beginning 1) (match-end 1))
(buffer-substring-no-properties
(match-beginning 2) (match-end 2))) ls))))
- ls))
+ (reverse ls)))
(defun edocs--get-docs (type name)
"Get docs of TYPE for symbol NAME."
(let ((type (intern type))
(obj (intern name)))
- (case type
- ((defun define-minor-mode)
- (cons (format "%s" (or (help-function-arglist obj :preserve-names)
- "()"))
- (documentation obj)))
- ((defcustom defvar defconst defclass)
- (documentation-property obj 'variable-documentation))
- (defgroup
- (documentation-property obj 'group-documentation))
- (defgeneric
- (mapcar (lambda (itm)
- (cons (format "%s" (cons (list (car (nth 2 itm))
- (car itm))
- (cdr (nth 2 itm))))
- (nth 3 itm)))
- (aref (plist-get (symbol-plist obj)
- 'eieio-method-tree) 2))))))
+ (cond
+ ((memq type '(defun define-minor-mode))
+ (cons (format "%s" (or (help-function-arglist obj :preserve-names)
+ "()"))
+ (documentation obj)))
+ ((memq type '(defcustom defvar defconst defclass))
+ (documentation-property obj 'variable-documentation))
+ ((eql type 'defgroup)
+ (documentation-property obj 'group-documentation))
+ ((eql type 'defgeneric)
+ (mapcar (lambda (itm)
+ (cons (format "%s" (cons (list (car (nth 2 itm))
+ (car itm))
+ (cdr (nth 2 itm))))
+ (nth 3 itm)))
+ (aref (plist-get (symbol-plist obj)
+ 'eieio-method-tree) 2))))))
(defun edocs--get-type-display (type-name)
"Get the display text for TYPE-NAME."
@@ -87,9 +96,13 @@ etc."
(let ((buffer (get-buffer-create "*edocs*"))
(binfo (package-buffer-info)))
(with-current-buffer buffer
- (insert "<!DOCTYPE html>\n"
- "<html><body>"
- "<h1>" (aref binfo 0) " <small>" (aref binfo 2)
+ (unless edocs-generate-only-body
+ (insert "<!DOCTYPE html>\n"
+ "<html><head>"
+ "<link href=\"" edocs-stylesheet-location
+ "\" rel=\"stylesheet\"></head><body>"))
+ (insert "<div class=\"container\">"
+ "<h1>" (aref binfo 0) " <small>&mdash; " (aref binfo 2)
"</small></h1><p>"
(replace-regexp-in-string
";; " "" (replace-regexp-in-string
@@ -99,7 +112,7 @@ etc."
(let ((docs (edocs--get-docs (car itm) (cdr itm))))
(with-current-buffer buffer
(mapc (lambda (doc)
- (insert "<div>&mdash; "
+ (insert "<div>&ndash; "
(edocs--get-type-display (car itm))
" <tt>" (cdr itm) "</tt> "
(if (consp doc) (car doc) "")
@@ -116,8 +129,19 @@ etc."
docs)))))
(edocs--list-symbols))
(with-current-buffer buffer
- (insert "</body></html>"))
+ (insert "</div>")
+ (unless edocs-generate-only-body
+ (insert "</body></html>")))
(switch-to-buffer buffer)))
+(defun edocs-generate-batch ()
+ "Generate module docs using batch operations."
+ (mapc (lambda (file)
+ (with-current-buffer (find-file file)
+ (eval-buffer)
+ (edocs-generate)
+ (write-file (concat (file-name-sans-extension file) ".html"))))
+ command-line-args-left))
+
(provide 'edocs)
;;; edocs.el ends here