1 ;;; yas-doc-helper.el --- Help generate documentation for YASnippet
3 ;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
5 ;; Author: João Távora <joaotavora@gmail.com>
6 ;; Keywords: convenience
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; Some functions to help generate YASnippet docs
27 (defun yas--document-symbol (symbol level)
28 (flet ((concat-lines (&rest lines)
29 (mapconcat #'identity lines "\n")))
30 (let* ((stars (make-string level ?*))
31 (heading (cond ((fboundp symbol)
32 (format "%s =%s= (%s)"
35 (mapconcat #'symbol-name
36 (help-function-arglist symbol t) " ")))
38 (format "%s =%s=\n" stars symbol))))
40 (concat-lines ":PROPERTIES:"
41 (format ":CUSTOM_ID: %s" symbol)
43 (body (or (cond ((boundp symbol)
44 (documentation-property symbol 'variable-documentation t))
46 (documentation-property symbol 'function-documentation t))
48 (format "*WARNING*: no symbol named =%s=" symbol)))
49 (format "*WARNING*: no doc for symbol =%s=" symbol)))
50 (case-fold-search nil))
51 ;; do some transformations on the body: FOO becomes /foo/ and
52 ;; `bar' becomes [[#bar][=bar=]]
53 (setq body (replace-regexp-in-string
54 "[A-Z][A-Z-]+" #'(lambda (match)
55 (format "/%s/" (downcase match)))
57 body (replace-regexp-in-string "`\\([a-z-]+\\)'" #'(lambda (match)
58 (let* ((name (downcase (match-string 1 match)))
60 (if (and (or (boundp sym)
63 (string-match "^yas-" name)))
64 (format "[[#%s][=%s=]]"
66 (format "=%s=" name))))
68 ;; output the paragraph
74 (defun yas--document-symbols (level &rest names-and-predicates)
75 (let ((sym-lists (make-vector (length names-and-predicates) (list)))
77 (loop for sym in yas--exported-syms
78 do (loop for test in (mapcar #'cdr names-and-predicates)
80 do (when (funcall test sym)
81 (push sym (aref sym-lists i))
83 (loop for slist across sym-lists
84 for name in (mapcar #'car names-and-predicates)
88 (format "\n** %s\n" name)
89 (mapconcat #'yas--document-symbol slist "\n\n")))))
92 (defun yas--internal-link-snippet ()
94 (yas-expand-snippet "[[#$1][=${1:`yas/selected-text`}=]]"))
96 (define-key org-mode-map [M-f8] 'yas--internal-link-snippet)
98 (provide 'yas-doc-helper)
99 ;;; yas-doc-helper.el ends here