[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gnugo abd1fa0 315/357: [gnugo int] Use ‘replace-regexp
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gnugo abd1fa0 315/357: [gnugo int] Use ‘replace-regexp-in-string’. |
Date: |
Sun, 29 Nov 2020 14:51:47 -0500 (EST) |
branch: externals/gnugo
commit abd1fa099bf7a422d1bfe71e0755dcaa58698e80
Author: Thien-Thi Nguyen <ttn@gnu.org>
Commit: Thien-Thi Nguyen <ttn@gnu.org>
[gnugo int] Use ‘replace-regexp-in-string’.
* packages/gnugo/gnugo.el (gnugo-refresh): ...here, for mode-line
elaboration.
Also, protect against mischievous "%". Suggested by Stefan Monnier,
<http://lists.gnu.org/archive/html/emacs-devel/2017-01/msg00265.html>.
---
gnugo.el | 46 ++++++++++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/gnugo.el b/gnugo.el
index a9e03aa..5b27b91 100644
--- a/gnugo.el
+++ b/gnugo.el
@@ -1249,34 +1249,40 @@ its move."
(setq cur gnugo-mode-line)
(gnugo-put :mode-line cur)
(gnugo-put :mode-line-form
- (cond ((stringp cur)
- (setq cur (copy-sequence cur))
- (let (acc cut c)
- (while (setq cut (string-match "~[bwpmtu]" cur))
- (aset cur cut ?%)
- (setq c (aref cur (cl-incf cut)))
- (aset cur cut ?s)
- (push
- `(,(intern (format "squig-%c" c))
- ,(cl-case c
- (?b '(or (gnugo-get :black-captures) 0))
- (?w '(or (gnugo-get :white-captures) 0))
- (?p '(gnugo-current-player))
- (?t '(let ((ws (gnugo-get :waiting-start)))
+ (if (consp cur)
+ cur
+ (let (v refs varlist)
+ (cl-flet
+ ((R (re rep)
+ (setq cur (replace-regexp-in-string
+ re rep cur t t))))
+ (R "%" "%%") ; hygiene
+ (R "~[bwpmtu]"
+ (lambda (match)
+ (prog1 "%s"
+ (push (setq v (intern match))
+ refs)
+ (pushnew
+ (list
+ v
+ (cl-case v
+ (~b '(or (gnugo-get :black-captures) 0))
+ (~w '(or (gnugo-get :white-captures) 0))
+ (~p '(gnugo-current-player))
+ (~t '(let ((ws (gnugo-get :waiting-start)))
(if ws
(cadr (time-since ws))
"-")))
- (?u '(or (gnugo-get :last-waiting) "-"))
- (?m '(let ((tree (gnugo-get :sgf-gametree))
+ (~u '(or (gnugo-get :last-waiting) "-"))
+ (~m '(let ((tree (gnugo-get :sgf-gametree))
(monkey (gnugo-get :monkey)))
(gethash (car (aref monkey 0))
(gnugo--tree-mnum tree)
;; should be unnecessary
"?")))))
- acc))
- `(let ,(delete-dups (copy-sequence acc))
- (format ,cur ,@(reverse (mapcar 'car acc))))))
- (t cur))))
+ varlist :key 'car)))))
+ `(let ,varlist
+ (format ,cur ,@(nreverse refs)))))))
(let ((form (gnugo-get :mode-line-form)))
(setq mode-line-process
(and form
- [elpa] externals/gnugo 1ce9fbb 312/357: [gnugo slog] Clear ‘inhibit-point-motion-hooks’., (continued)
- [elpa] externals/gnugo 1ce9fbb 312/357: [gnugo slog] Clear ‘inhibit-point-motion-hooks’., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 9208a24 317/357: * gnugo/gnugo.el (gnugo-refresh): Fix unknown function `pushnew`, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 61a7217 297/357: [gnugo maint] Add some headers to gnugo-frolic.el; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 5b213db 293/357: fixup! [gnugo imgen] New feature: gnugo-imgen, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 36a2fd5 291/357: [gnugo int] Accomodate XPM w/ :color-symbols property., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 2d4e59e 292/357: [gnugo imgen] New feature: gnugo-imgen, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 7478f81 302/357: [gnugo int] Bump required ‘xpm’ version to "1.0.1"., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo f1c7c8d 319/357: [gnugo int] Fix verse meter; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo da8901f 314/357: [gnugo] Release: 3.0.1, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo a667440 298/357: [gnugo int] Fix up gnugo-frolic.el ‘require’ forms., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo abd1fa0 315/357: [gnugo int] Use ‘replace-regexp-in-string’.,
Stefan Monnier <=
- [elpa] externals/gnugo 2e6bbe5 300/357: [gnugo int] Whitespace, comment munging; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo c0f6ed5 328/357: [gnugo int] Comment munging; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo cf36ccd 331/357: [gnugo int] Whitespace munging; nfc., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo a70a854 336/357: [gnugo] Add abstraction: gnugo-aqr, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 1eb43f1 342/357: [gnugo int] Add abstraction: gnugo--zonk-ovs, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo abb12ef 345/357: [gnugo] Include seki groups in game-over data., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 82c5b64 351/357: [gnugo imgen] New fit func to ignore bottom grid line, Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 152c53c 354/357: [gnugo] Move two funcs internal., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 5566285 026/357: [gnugo] Give names and docstrings to ‘lambda’ commands., Stefan Monnier, 2020/11/29
- [elpa] externals/gnugo 62a7c8d 052/357: [gnugo slog] Specify second arg to ‘unintern’., Stefan Monnier, 2020/11/29