Simplify docs-generation using dash.

master
Magnar Sveen 14 years ago
parent a2941cda63
commit dc6f46cff3
  1. 34
      examples-to-docs.el

@ -1,17 +1,15 @@
(require 'dash)
(defvar functions '()) (defvar functions '())
(defun example-to-string (example) (defun example-to-string (example)
(let ((actual (car example)) (let ((actual (car example))
(expected (cadr (cdr example)))) (expected (cadr (cdr example))))
(replace-regexp-in-string (--> (format "%S ;; => %S" actual expected)
"\r" "\\r" (replace-regexp-in-string "\\\\\\?" "?" it)
(replace-regexp-in-string (replace-regexp-in-string "\n" "\\n" it t t)
"\t" "\\t" (replace-regexp-in-string "\t" "\\t" it t t)
(replace-regexp-in-string (replace-regexp-in-string "\r" "\\r" it t t))))
"\n" "\\n"
(replace-regexp-in-string
"\\\\\\?" "?"
(format "%S ;; => %S" actual expected)) t t) t t) t t)))
(defun examples-to-strings (examples) (defun examples-to-strings (examples)
(let (result) (let (result)
@ -42,9 +40,9 @@
(defun quote-docstring (docstring) (defun quote-docstring (docstring)
(let (case-fold-search) (let (case-fold-search)
(setq docstring (replace-regexp-in-string "\\b\\([A-Z][A-Z-]*[0-9]*\\)\\b" 'quote-and-downcase docstring t)) (--> docstring
(setq docstring (replace-regexp-in-string "`\\([^ ]+\\)'" "`\\1`" docstring t))) (replace-regexp-in-string "\\b\\([A-Z][A-Z-]*[0-9]*\\)\\b" 'quote-and-downcase it t)
docstring) (replace-regexp-in-string "`\\([^ ]+\\)'" "`\\1`" it t))))
(defun function-to-md (function) (defun function-to-md (function)
(let ((command-name (car function)) (let ((command-name (car function))
@ -55,7 +53,7 @@
command-name command-name
signature signature
docstring docstring
(mapconcat 'identity (three-first examples) "\n")))) (mapconcat 'identity (-take 3 examples) "\n"))))
(defun docs--chop-suffix (suffix s) (defun docs--chop-suffix (suffix s)
"Remove SUFFIX if it is at end of S." "Remove SUFFIX if it is at end of S."
@ -106,13 +104,3 @@
(insert (mapconcat 'function-to-md functions "\n")) (insert (mapconcat 'function-to-md functions "\n"))
(simplify-quotes)))) (simplify-quotes))))
(defun three-first (list)
(let (first)
(when (car list)
(setq first (cons (car list) first))
(when (cadr list)
(setq first (cons (cadr list) first))
(when (car (cddr list))
(setq first (cons (car (cddr list)) first)))))
(nreverse first)))

Loading…
Cancel
Save