Skip to content

Instantly share code, notes, and snippets.

@jleechpe
Created November 17, 2014 02:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jleechpe/bc1ef519964d7bd8bd13 to your computer and use it in GitHub Desktop.
Save jleechpe/bc1ef519964d7bd8bd13 to your computer and use it in GitHub Desktop.
Extract function information for use in an org file
(defun extract-information (sym)
(if (fboundp sym)
(cons 'function (or (help-split-fundoc (documentation sym) sym)
(documentation sym)))
(cons 'variable (documentation-property sym 'variable-documentation))))
(defun def-to-org-headline (sym &optional level)
(let* ((toplevel (or level 1))
(info (extract-information sym))
(name (format "%s" sym))
(type (format "%s" (car info)))
(arglist (if (and (equal (car info) 'function)
(consp (cdr info)))
(cadr info)))
(docstring (if (consp (cdr info))
(cddr info)
(cdr info)))
construct args props docs)
(setq construct `(headline (:title ,name :level ,toplevel)))
(setq props
`(property-drawer
()
(node-property (:key "Type"
:value ,type))))
(setq docs
`(paragraph () ,docstring))
(if arglist
(setq args
`(headline (:title "Argument List" :level ,(1+ toplevel))
(paragraph () ,arglist))))
(setq construct
(org-element-adopt-elements construct
props docs))
(if args (setq construct (org-element-adopt-elements construct args)))
construct))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment