summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2014-01-26 01:12:10 +0100
committerGravatar Tom Willemse2014-01-26 01:12:10 +0100
commit3312852701fbf07bdc5cdb7a2401847f80f1c4c6 (patch)
tree874e4425fc9142fb448fb41ff396ab56d9d365cc
parent081ca68d0355cc2433d6780b1c2f7d3c1f090156 (diff)
downloadedocs-3312852701fbf07bdc5cdb7a2401847f80f1c4c6.tar.gz
edocs-3312852701fbf07bdc5cdb7a2401847f80f1c4c6.zip
Refrain from evaluating buffer
Evaluating the buffer requires that all required libraries and functions are present at the moment the documentation is generated. Because documentation generation may happen in an Emacs without X11 support or without all the libraries installed, this is not an optimal solution.
-rw-r--r--edocs.el48
1 files changed, 41 insertions, 7 deletions
diff --git a/edocs.el b/edocs.el
index 0aa55de..2df2807 100644
--- a/edocs.el
+++ b/edocs.el
@@ -84,6 +84,37 @@ and are not meant to be used outside the module. The default is
"defvar" "Variable"))
"Type -> name map for symbol types.")
+(defun edocs--get-doc (expr)
+ "Get a docstring from EXPR."
+ (cl-case (car expr)
+ ((defun defcustom defgroup defface)
+ (let ((doc (nth 3 expr)))
+ (when (stringp doc) doc)))
+ ((defvar defconst defgeneric)
+ (let ((doc (car (last expr))))
+ (when (and (= (length expr) 4)
+ (stringp doc))
+ doc)))
+ (define-minor-mode
+ (let ((doc (nth 2 expr)))
+ (when (stringp doc) doc)))
+ (defclass
+ (let ((doc (or (plist-git expr :documentation)
+ (nth 4 expr))))
+ (when (stringp doc) doc)))
+ (defmethod
+ (let ((doc1 (nth 3 expr))
+ (doc2 (nth 4 expr)))
+ (or (and (stringp doc1) doc1)
+ (and (stringp doc2) doc2))))))
+
+(defun edocs--get-arg-list (expr)
+ "Get argument list from EXPR if possible."
+ (when (eql (car expr) 'defun)
+ (format "%s" (or (nth 2 expr) "()"))))
+
+(cl-defstruct edocs-symbol name type doc args)
+
(defun edocs--list-symbols ()
"Get a list of all symbols in the buffer.
@@ -103,7 +134,10 @@ etc."
(let ((type (symbol-name (car expr)))
(name (symbol-name (cadr expr))))
(unless (string-match edocs-private-regexp name)
- (push (cons type name) ls))))))
+ (push (make-edocs-symbol
+ :name name :type type
+ :doc (edocs--get-doc expr)
+ :args (edocs--get-arg-list expr)) ls))))))
(end-of-file nil))
(reverse ls))))
@@ -238,9 +272,10 @@ See the docstring for `edocs--module-name' for more information."
KNOWN-SYMBOLS is used for referencing symbols found in other
parts of the module."
- (let* ((type (car symbol))
- (name (cdr symbol))
- (docs (edocs--get-docs type name)))
+ (let ((type (edocs-symbol-type symbol))
+ (name (edocs-symbol-name symbol))
+ (docs (edocs-symbol-doc symbol))
+ (args (edocs-symbol-args symbol)))
(mapc (lambda (doc)
(edocs--with-tag "div" nil
(insert "– ")
@@ -251,7 +286,7 @@ parts of the module."
(edocs--with-tag "a" `(("name" . ,name)
("href" . ,(concat "#" name)))
(insert name)))
- (insert " " (if (consp doc) (car doc) ""))
+ (insert " " (or args ""))
(edocs--with-tag "blockquote" '(("class" . "docstring"))
(insert (or (edocs--format-doc doc known-symbols)
"Not documented.")))))
@@ -270,7 +305,7 @@ into a buffer called `*edocs*' and switches to that buffer."
(binfo (package-buffer-info))
(commentary (lm-commentary))
(symbol-specs (edocs--list-symbols))
- (symbols (mapcar #'cdr symbol-specs)))
+ (symbols (mapcar #'edocs-symbol-type symbol-specs)))
(with-current-buffer buffer
(unless edocs-generate-only-body (edocs--insert-header))
(edocs--with-tag "div" '(("class" . "container"))
@@ -287,7 +322,6 @@ into a buffer called `*edocs*' and switches to that buffer."
(defun edocs--generate-batch-1 (file)
"Generate docs for FILE."
(with-current-buffer (find-file file)
- (eval-buffer)
(edocs-generate)
(write-file (concat (file-name-sans-extension file) ".html"))))