;;; yas-doc-helper.el --- Help generate documentation for YASnippet
-;; Copyright (C) 2012 João Távora
+;; Copyright (C) 2012, 2013 Free Software Foundation, Inc.
;; Author: João Távora <joaotavora@gmail.com>
;; Keywords: convenience
(eval-when-compile
(require 'cl))
(require 'org)
-(require 'org-publish)
+(or (require 'org-publish nil t)
+ (require 'ox-publish))
(require 'yasnippet) ; docstrings must be loaded
+(defun yas--org-raw-html (tag content)
+ ;; in version 8.0 org-mode changed the export syntax, see
+ ;; http://orgmode.org/worg/org-8.0.html#sec-8-1
+ (format (if (version< org-version "8.0.0")
+ "@<%s>%s@</%s>" ; old: @<tag>
+ "@@html:<%s>@@%s@@html:</%s>@@") ; new: @@html:<tag>@@
+ tag content tag))
+
(defun yas--document-symbol (symbol level)
(flet ((concat-lines (&rest lines)
(mapconcat #'identity lines "\n")))
(format "*WARNING*: no doc for symbol =%s=" symbol)))
(case-fold-search nil))
;; do some transformations on the body:
- ;; ARG becomes =arg=
+ ;; ARGxxx becomes @<code>arg@</code>xxx
;; FOO becomes /foo/
;; `bar' becomes [[#bar][=bar=]]
(setq body (replace-regexp-in-string
- "\\<[A-Z][A-Z-]+\\>"
+ "\\<\\([A-Z][-A-Z0-9]+\\)\\(\\sw+\\)?\\>"
#'(lambda (match)
- (setq match (downcase match))
- (format (if (member match args)
- "=%s=" "/%s/")
- match))
- body t)
+ (let* ((match1 (match-string 1 match))
+ (prefix (downcase match1))
+ (suffix (match-string 2 match))
+ (fmt (cond
+ ((member prefix args)
+ (yas--org-raw-html "code" "%s"))
+ ((null suffix) "/%s/"))))
+ (if fmt (format fmt prefix)
+ match1)))
+ body t t 1)
body (replace-regexp-in-string
"`\\([a-z-]+\\)'"
#'(lambda (match)
body))))
(defun yas--document-symbols (level &rest names-and-predicates)
- (let ((sym-lists (make-vector (length names-and-predicates) nil)))
+ (let ((sym-lists (make-vector (length names-and-predicates) nil))
+ (stars (make-string level ?*)))
(loop for sym in yas--exported-syms
do (loop for test in (mapcar #'cdr names-and-predicates)
for i from 0
(return))))
(loop for slist across sym-lists
for name in (mapcar #'car names-and-predicates)
- concat (format "\n** %s\n" name)
+ concat (format "\n%s %s\n" stars name)
concat (mapconcat (lambda (sym)
(yas--document-symbol sym (1+ level)))
slist "\n\n"))))
;; This lets all the org files be exported to HTML with
;; `org-publish-current-project' (C-c C-e P).
-(let* ((rev (or (with-temp-buffer
- (when (eq (call-process "git" nil t nil
- "rev-parse" "--verify" "HEAD") 0)
- (buffer-string)))
- yas--version))
- (dir (if load-file-name (file-name-directory load-file-name)
+(let* ((dir (if load-file-name (file-name-directory load-file-name)
default-directory))
+ (rev (with-temp-file (expand-file-name "html-revision" dir)
+ (or (when (eq (call-process "git" nil t nil
+ "rev-parse" "--verify" "HEAD") 0)
+ (buffer-string))
+ (princ yas--version (current-buffer)))))
(proj-plist
- (list
- :base-directory dir :publishing-directory dir
- :html-postamble
- (concat "<hr><p class='creator'>Generated by %c on %d from "
- rev "</p>\n"
- "<p class='xhtml-validation'>%v</p>\n")))
+ `(,@(when (fboundp 'org-html-publish-to-html)
+ '(:publishing-function org-html-publish-to-html))
+ :base-directory ,dir :publishing-directory ,dir
+ :html-preamble
+ ,(with-temp-buffer
+ (insert-file-contents (expand-file-name "nav-menu.html.inc" dir))
+ (buffer-string))
+ :html-postamble
+ ,(concat "<hr><p class='creator'>Generated by %c on %d from "
+ rev "</p>\n"
+ "<p class='xhtml-validation'>%v</p>\n")))
(project (assoc "yasnippet" org-publish-project-alist)))
(if project
(setcdr project proj-plist)
(provide 'yas-doc-helper)
-;;; yas-doc-helper.el ends here
;; Local Variables:
+;; indent-tabs-mode: nil
;; coding: utf-8
;; End:
+;;; yas-doc-helper.el ends here