[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 3cfbebf 293/316: Port more Texinfo generation chan
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 3cfbebf 293/316: Port more Texinfo generation changes to Markdown |
Date: |
Mon, 15 Feb 2021 15:58:19 -0500 (EST) |
branch: externals/dash
commit 3cfbebfe3eb1007564f4a972169194455c3f2d91
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Port more Texinfo generation changes to Markdown
* dev/examples-to-docs.el (create-docs-file): Move 'nil -> '()
replacement from here...
(dash--print-lisp-as-md): ...to this new function.
(example-to-string): Use it to print Lisp in a buffer rather than
manipulating strings.
(defexamples): Move example-to-string call from here...
(function-to-md): ...to here, where it's needed. Replace s-replace
with more correct code.
(s-replace): Remove; no longer used.
* README.md: Regenerate.
---
README.md | 2 +-
dev/examples-to-docs.el | 50 ++++++++++++++++++++++++++-----------------------
2 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/README.md b/README.md
index 3fa054a..52de5e8 100644
--- a/README.md
+++ b/README.md
@@ -2868,7 +2868,7 @@ See `srfi-26` for detailed description.
```el
(funcall (-cut list 1 <> 3 <> 5) 2 4) ;; => '(1 2 3 4 5)
(-map (-cut funcall <> 5) `(1+ 1- ,(lambda (x) (/ 1.0 x)))) ;; => '(6 4 0.2)
-(-map (-cut <> 1 2 3) '(list vector string)) ;; => '((1 2 3) [1 2 3]
"\^A\^B\^C")
+(-map (-cut <> 1 2 3) '(list vector string)) ;; => '((1 2 3) [1 2 3] "\1\2\3")
```
#### -not `(pred)`
diff --git a/dev/examples-to-docs.el b/dev/examples-to-docs.el
index 430b46f..8beeddc 100644
--- a/dev/examples-to-docs.el
+++ b/dev/examples-to-docs.el
@@ -28,20 +28,29 @@
(defvar functions ())
+(defun dash--print-lisp-as-md (obj)
+ "Print Lisp OBJ suitably for Markdown."
+ (let ((print-quoted t)
+ (print-escape-control-characters t))
+ (save-excursion (prin1 obj)))
+ (while (re-search-forward
+ (rx (| (group ?\' symbol-start "nil" symbol-end) "\\?")) nil 'move)
+ ;; 'nil -> '(), `-any\?' -> `-any?'.
+ (replace-match (if (match-beginning 1) "'()" "?") t t)))
+
(defun example-to-string (example)
- (-let (((actual sym expected) example)
- (print-quoted t))
- (--> (cond
- ((eq sym '=>) (format "=> %S" expected))
- ((eq sym '~>) (format "~> %S" expected))
- ((eq sym '!!>) "Error")
- ((error "Invalid test case: %S" example)))
- (format "%S ;; %s" actual it)
- (replace-regexp-in-string "\\\\\\?" "?" it t t)
- (replace-regexp-in-string
- "[^\n[:print:]]"
- (lambda (s) (concat "\\" (text-char-description (string-to-char s))))
- it t t))))
+ (pcase-let ((`(,actual ,sym ,expected) example)
+ (print-quoted t))
+ (with-output-to-string
+ (with-current-buffer standard-output
+ (dash--print-lisp-as-md actual)
+ (insert " ;; ")
+ (cond ((memq sym '(=> ~>))
+ (princ sym)
+ (insert ?\s)
+ (dash--print-lisp-as-md expected))
+ ((eq sym '!!>) (insert "Error"))
+ ((error "Invalid test case: %S" example)))))))
(defun dash--describe (fn)
"Return the (ARGLIST DOCSTRING) of FN symbol.
@@ -62,8 +71,7 @@ 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)
@@ -128,13 +136,14 @@ Based on `describe-function-1'."
(defun function-to-md (function)
(if (stringp function)
- (concat "\n" (s-replace "### " "## " function) "\n")
+ (concat "\n" (replace-regexp-in-string (rx bos "### ") "## " function)
+ "\n")
(-let [(command-name signature docstring examples) function]
(format "#### %s `%s`\n\n%s\n\n```el\n%s\n```\n"
command-name
signature
(dash--format-docstring docstring)
- (mapconcat #'identity (-take 3 examples) "\n")))))
+ (mapconcat #'example-to-string (-take 3 examples) "\n")))))
(defun docs--chop-prefix (prefix s)
"Remove PREFIX if it is at the start of S."
@@ -159,10 +168,6 @@ Based on `describe-function-1'."
"!"
(format "%S %S"
command-name signature)))))
-(defun s-replace (old new s)
- "Replace OLD with NEW in S."
- (replace-regexp-in-string (regexp-quote old) new s t t))
-
(defun function-summary (function)
(if (stringp function)
(concat "\n" function "\n")
@@ -186,7 +191,6 @@ Based on `describe-function-1'."
(dash--replace-all "[[ function-list ]]"
(mapconcat #'function-summary functions "\n"))
(dash--replace-all "[[ function-docs ]]"
- (mapconcat #'function-to-md functions "\n"))
- (dash--replace-all "'nil" "'()"))))
+ (mapconcat #'function-to-md functions "\n")))))
;;; examples-to-docs.el ends here
- [elpa] externals/dash 7fc72d9 263/316: Fix Markdown quoting, (continued)
- [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, 2021/02/15
- [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 <=
- [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
- [elpa] externals/dash 5eea156 315/316: Absorb dash-functional into dash, ELPA Syncer, 2021/02/15
- [elpa] externals/dash eaf33b3 226/316: Add info-lookup-symbol support, ELPA Syncer, 2021/02/15