Download
(defun wikidoc-grab-list (prefix &optional no-private)
"Grab a list or functions matching PREFIX possibly with NO-PRIVATE"
(let ((prefix-sym (symbol-name prefix))
(res '()))
(mapatoms
(lambda (atom)
(let ((sn (symbol-name atom)))
(and (fboundp atom)
(if (string-prefix-p prefix-sym sn)
(if no-private
(if (not (string-match "[^-]+--.*" sn))
(setq res (cons atom res)))
(setq res (cons atom res)))))))
obarray)
res))
(defun wikidoc--convert-line (line)
"Converts a single LINE of function documentation.
This deals with things like quoted LISP forms which can be turned into links"
(save-match-data
(while (string-match ".*\\('[^']+'\\).*" line)
(setq line (replace-match
(format "[[%s]]" (let ((name (match-string 1 line)))
(save-match-data
(string-match "'\\([^']+\\)'" name)
(match-string 1 name))))
nil nil line 1))) line))
(defun wikidoc--convert (str)
"Convert function documentation type doc STR to creole."
(let (in-pre)
(concat
(mapconcat
(lambda (line)
(cond
((string-match "^ " line)
(if in-pre
line
(progn
(setq in-pre 't)
(concat "{{{\n" (wikidoc--convert-line line)))))
((and in-pre (not (string-match "^ " line)))
(setq in-pre nil)
(concat "}}}\n" (wikidoc--convert-line line)))
('t
(wikidoc--convert-line line))))
(split-string str "\n")
"\n")
(if in-pre "\n}}}\n"))))
(defun wikidoc-insert (elisp-prefix buffer)
"Make creole doc for functions beginning with ELISP-PREFIX in BUFFER.
When called interactively with a PREFIX argument this function
will use the current buffer for BUFFER.
Otherwise the BUFFER will be created named like:
*wikidoc-ELISP-PREFIX*
If Transient Mark mode is set in the specified buffer the active
region is killed before the new wiki text is inserted.
"
(interactive
(let ((elisp-prefix (completing-read "elisp prefix: " obarray 't nil nil nil)))
(list (intern elisp-prefix)
(if current-prefix-arg
(current-buffer)
nil))))
(let* ((lst (sort
(wikidoc-grab-list elisp-prefix 't)
'string-lessp))
(mapfn (lambda (fn)
(with-current-buffer buffer
(insert (format "=== %s %s ===\n\n%s\n\n\n"
(symbol-name fn)
(let ((args (help-function-arglist fn)))
(upcase (format "%s" args)))
(wikidoc--convert (documentation fn))))))))
(if (not (bufferp buffer))
(progn
(setq buffer (get-buffer-create (format "*wikidoc-%s*" elisp-prefix)))
(mapc mapfn lst)
(switch-to-buffer buffer))
(progn
(if (use-region-p)
(delete-region (region-beginning) (region-end)))
(mapc mapfn lst)))))
(provide 'wikidoc)