[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash baf9147 285/316: Simplify Texinfo generation
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash baf9147 285/316: Simplify Texinfo generation |
Date: |
Mon, 15 Feb 2021 15:58:18 -0500 (EST) |
branch: externals/dash
commit baf91479fd83f9ddcd030e3f730a21c55f1e6523
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Simplify Texinfo generation
* dev/examples-to-info.el (defexamples): Move example-to-string
transformation from here...
(function-to-info): ...to here, where it's needed.
(def-example-group): Use text properties to distinguish groups.
All users changed.
(simplify-quotes, goto-and-remove): Remove, replacing with...
(dash--replace-all): ...this simpler function.
(create-info-file): Don't modify 'functions' destructively for more
idempotency. Use simple relative file names. Simplify with
dash--replace-all.
(function-to-node): Remove; no longer used.
---
dev/examples-to-info.el | 90 ++++++++++++++++---------------------------------
1 file changed, 29 insertions(+), 61 deletions(-)
diff --git a/dev/examples-to-info.el b/dev/examples-to-info.el
index ce445ad..b896e13 100644
--- a/dev/examples-to-info.el
+++ b/dev/examples-to-info.el
@@ -79,13 +79,12 @@ Based on `describe-function-1'."
(defmacro defexamples (cmd &rest examples)
`(push (cons ',cmd
(nconc (dash--describe ',cmd)
- (list (mapcar #'example-to-string
- (-partition 3 ',examples)))))
+ (list (-partition 3 ',examples))))
functions))
(defmacro def-example-group (group desc &rest examples)
`(progn
- (push ,(concat "### " group) functions)
+ (push ,(propertize group 'dash-group t) functions)
(when ,desc
(push ,desc functions))
,@examples))
@@ -118,9 +117,6 @@ Based on `describe-function-1'."
((match-beginning 3) (replace-match "@enddots{}" t t))
((replace-match "@dots{}" t t))))))))
-(defun function-to-node (function)
- (concat (replace-regexp-in-string (rx bos "### ") "* " function t t) "::"))
-
(defun function-to-info (function)
(pcase function
(`(,command-name ,signature ,docstring ,examples)
@@ -134,68 +130,40 @@ Based on `describe-function-1'."
command-name
signature
(format-docstring docstring)
- (mapconcat #'identity (-take 3 examples) "\n"))))
- ((rx bos "### ")
- (setq function (substring function (match-end 0)))
+ (mapconcat #'example-to-string (-take 3 examples) "\n"))))
+ ((pred (get-text-property 0 'dash-group))
(concat "\n@node " function "\n@section " function))
(_ (concat "\n" function))))
-(defun simplify-quotes ()
- (goto-char (point-min))
- (while (re-search-forward (rx (or "'nil" "(quote nil)")) nil t)
- (replace-match "'()" t t))
- (goto-char (point-min))
- (while (search-forward "(quote " nil t)
- (forward-char -7)
- (let ((p (point)))
- (forward-sexp 1)
- (delete-char -1)
- (goto-char p)
- (delete-char 7)
- (insert "'")))
- (goto-char (point-min))
- (while (search-forward "(function " nil t)
- (forward-char -10)
- (let ((p (point)))
- (forward-sexp 1)
- (delete-char -1)
- (goto-char p)
- (delete-char 10)
- (insert "#'"))))
-
-(defun goto-and-remove (s)
+(defun dash--replace-all (old new &optional regexp)
+ "Replace occurrences of OLD with NEW in current buffer.
+If REGEXP is non-nil, interpret OLD as a regexp."
+ (or regexp (setq old (regexp-quote old)))
(goto-char (point-min))
- (search-forward s)
- (delete-char (- (length s))))
+ (while (re-search-forward old nil t)
+ (replace-match new t t)))
(defun create-info-file ()
- (let ((functions (nreverse functions)))
- (with-temp-file "./dash.texi"
- (insert-file-contents "./dash-template.texi")
+ (let ((functions (reverse functions)))
+ (with-temp-file "dash.texi"
+ (insert-file-contents "dash-template.texi")
(dolist (pkg '(dash dash-functional))
- (goto-and-remove (format "@c [[ %s-version ]]" pkg))
- (insert (lm-version (format "%s.el" pkg))))
-
- (goto-and-remove "@c [[ function-nodes ]]")
- (insert (mapconcat 'function-to-node
- (-filter (lambda (s)
- (when (stringp s)
- (string-match "^### " s)))
- functions)
- "\n"))
-
- (goto-and-remove "@c [[ function-nodes ]]")
- (insert (mapconcat 'function-to-node
- (-filter (lambda (s)
- (when (stringp s)
- (string-match "^### " s)))
- functions)
- "\n"))
-
- (goto-and-remove "@c [[ function-docs ]]")
- (insert (mapconcat 'function-to-info functions "\n"))
-
- (simplify-quotes))))
+ (dash--replace-all (format "@c [[ %s-version ]]" pkg)
+ (lm-version (format "%s.el" pkg))))
+
+ (dash--replace-all
+ "@c [[ function-nodes ]]"
+ (mapconcat (lambda (s) (concat "* " s "::"))
+ (-filter (lambda (s)
+ (and (stringp s)
+ (get-text-property 0 'dash-group s)))
+ functions)
+ "\n"))
+
+ (dash--replace-all "@c [[ function-docs ]]"
+ (mapconcat #'function-to-info functions "\n"))
+
+ (dash--replace-all (rx (or "'nil" "(quote nil)")) "'()" t))))
;;; examples-to-info.el ends here
- [elpa] externals/dash ff5ed7a 261/316: Extend -keep docs and tests, (continued)
- [elpa] externals/dash ff5ed7a 261/316: Extend -keep docs and tests, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 5d8de45 262/316: ; Fix recent typo in -filter & -remove docstrings, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7fc72d9 263/316: Fix Markdown quoting, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e5e5363 272/316: Merge pull request #367 from HKey/fix-handling-nil, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8bd2887 269/316: Move pre-commit.sh under dev/, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8599380 270/316: Optimize -is-prefix? and -is-suffix?, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 5362be7 275/316: Use actual advertised function signature in manual, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 926eb0b 280/316: Add forceful Makefile targets, ELPA Syncer, 2021/02/15
- [elpa] externals/dash eedc2af 279/316: Fix docstring Texinfo generation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7ee12ee 283/316: Use buffers for Texinfo generation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash baf9147 285/316: Simplify Texinfo generation,
ELPA Syncer <=
- [elpa] externals/dash 7ec3975 292/316: Avoid deleting docs in old Emacs versions, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3cfbebf 293/316: Port more Texinfo generation changes to Markdown, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 03748d8 297/316: Prefer '() over () in printed examples, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6ffcd89 299/316: Print actual error messages in README, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4f3238b 300/316: Strip leading zeros from octal escapes in Emacs 26, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 2028805 302/316: Don't quote error messages in Texinfo examples, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6c41b32 301/316: Move case-fold-search binding to where it's used, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1c711f1 303/316: Unquote results in Texinfo examples, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1bf9ddb 304/316: Makefile aesthetics, ELPA Syncer, 2021/02/15
- [elpa] externals/dash da0415b 312/316: * NEWS.md (2.18): Start news for upcoming release., ELPA Syncer, 2021/02/15