Skip to content

Instantly share code, notes, and snippets.

@sabof
Last active December 10, 2015 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabof/4483784 to your computer and use it in GitHub Desktop.
Save sabof/4483784 to your computer and use it in GitHub Desktop.
The code that generates the es-lib markdown documentation. Copy-pasted as it was - might need some tweaking to make it work for you
(defun* buffer-defuns (&optional (buffer (current-buffer)))
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(let (names)
(while (re-search-forward "^(defun[*]? \\(\\_<.+?\\_>\\)" nil t)
(push (intern (match-string-no-properties 1)) names))
names))))
(defun* buffer-macros (&optional (buffer (current-buffer)))
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(let (names)
(while (re-search-forward "^(defmacro[*]? \\(\\_<.+?\\_>\\)" nil t)
(push (intern (match-string-no-properties 1)) names))
names))))
(defun es-lib-index ()
(flet (( print-symbol-list (list)
(dolist (sym list)
(insert "* " (symbol-name sym) "\n")
(when (documentation sym)
(insert "\n```\n")
(let* ((parts (split-string (documentation sym) "\n"))
(last (last parts)))
;; (setf (first parts) (concat "<em>" (first parts)) )
;; (setf (car last) (concat (car last) "</em>"))
(apply 'insert
(mapcar
(lambda (part)
(concat ;; " "
part "\n"))
parts)))
(insert "```\n\n")
))))
(save-excursion
(save-window-excursion
(let* ((libs '("es-lib-lexical" "es-lib"))
defuns commands non-interactive macros)
(dolist (lib libs)
(find-library lib)
(eval-buffer)
(setq defuns (append (buffer-defuns) defuns))
(setq macros (append (buffer-macros) macros)))
(setq commands (remove-if-not 'commandp defuns))
(setq non-interactive (remove-if 'commandp defuns))
(dolist (sym '(commands non-interactive macros))
(set sym (cl-sort (symbol-value sym)
'string<
:key 'symbol-name)))
(with-temp-buffer
(insert "\n### Commands:\n\n")
(print-symbol-list commands)
(insert "\n### Non-interactive:\n\n")
(print-symbol-list non-interactive)
(insert "\n### Macros:\n\n")
(print-symbol-list macros)
(buffer-string)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment