[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9120d7a32ea 02/12: Honor nil values in erc--restore-initialize-pr
From: |
F. Jason Park |
Subject: |
master 9120d7a32ea 02/12: Honor nil values in erc--restore-initialize-priors |
Date: |
Fri, 13 Oct 2023 10:49:36 -0400 (EDT) |
branch: master
commit 9120d7a32ea4906d7c9460add31d37c3ca38931e
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Honor nil values in erc--restore-initialize-priors
* lisp/erc/erc.el (erc--restore-initialize-priors): Don't produce
invalid "empty" `setq' form when parameter VARS contains defaults that
initialize to nil. This function is mainly used by local modules,
which were first made usable in ERC 5.5 (bug#57955).
* test/lisp/erc/erc-tests.el (erc--restore-initialize-priors): Fix
expected expansion, which is now slightly leaner. (Bug#60936)
---
lisp/erc/erc.el | 17 ++++++++---------
test/lisp/erc/erc-tests.el | 17 +++++++----------
2 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index fb236f1f189..16651b41eef 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1366,16 +1366,15 @@ buffer during local-module setup and `erc-mode-hook'
activation.")
(defmacro erc--restore-initialize-priors (mode &rest vars)
"Restore local VARS for MODE from a previous session."
(declare (indent 1))
- (let ((existing (make-symbol "existing"))
+ (let ((priors (make-symbol "priors"))
+ (initp (make-symbol "initp"))
;;
- restore initialize)
- (while-let ((k (pop vars)) (v (pop vars)))
- (push `(,k (alist-get ',k ,existing)) restore)
- (push `(,k ,v) initialize))
- `(if-let* ((,existing (or erc--server-reconnecting erc--target-priors))
- ((alist-get ',mode ,existing)))
- (setq ,@(mapcan #'identity (nreverse restore)))
- (setq ,@(mapcan #'identity (nreverse initialize))))))
+ forms)
+ (while-let ((k (pop vars)))
+ (push `(,k (if ,initp (alist-get ',k ,priors) ,(pop vars))) forms))
+ `(let* ((,priors (or erc--server-reconnecting erc--target-priors))
+ (,initp (and ,priors (alist-get ',mode ,priors))))
+ (setq ,@(mapcan #'identity (nreverse forms))))))
(defun erc--target-from-string (string)
"Construct an `erc--target' variant from STRING."
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 8a68eca6196..64b503832f3 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -796,18 +796,15 @@
(should (erc--valid-local-channel-p "&local")))))
(ert-deftest erc--restore-initialize-priors ()
- ;; This `pcase' expands to 100+k. Guess we could do something like
- ;; (and `(,_ ((,e . ,_) . ,_) . ,_) v) first and then return a
- ;; (equal `(if-let* ((,e ...)...)...) v) to cut it down to < 1k.
(should (pcase (macroexpand-1 '(erc--restore-initialize-priors erc-my-mode
foo (ignore 1 2 3)
- bar #'spam))
- (`(if-let* ((,e (or erc--server-reconnecting erc--target-priors))
- ((alist-get 'erc-my-mode ,e)))
- (setq foo (alist-get 'foo ,e)
- bar (alist-get 'bar ,e))
- (setq foo (ignore 1 2 3)
- bar #'spam))
+ bar #'spam
+ baz nil))
+ (`(let* ((,p (or erc--server-reconnecting erc--target-priors))
+ (,q (and ,p (alist-get 'erc-my-mode ,p))))
+ (setq foo (if ,q (alist-get 'foo ,p) (ignore 1 2 3))
+ bar (if ,q (alist-get 'bar ,p) #'spam)
+ baz (if ,q (alist-get 'baz ,p) nil)))
t))))
(ert-deftest erc--target-from-string ()
- master updated (bd297132016 -> baf778c7caa), F. Jason Park, 2023/10/13
- master 328a985651a 01/12: Skip post-minibuffer restore in erc-scrolltobottom-all, F. Jason Park, 2023/10/13
- master 9120d7a32ea 02/12: Honor nil values in erc--restore-initialize-priors,
F. Jason Park <=
- master d46c016fbd0 03/12: Sort and dedupe when loading modules in erc-open, F. Jason Park, 2023/10/13
- master a4bae965e06 07/12: Easily excise list-valued text prop members in ERC, F. Jason Park, 2023/10/13
- master c68dc7786fc 08/12: Manage some text props for ERC insertion-hook members, F. Jason Park, 2023/10/13
- master f8af241192b 10/12: Treat previous/next-line specially in erc-fill-wrap, F. Jason Park, 2023/10/13
- master 5e2be1e0ba6 09/12: Swap hook positions of erc-fill and erc-match-message, F. Jason Park, 2023/10/13
- master 1950ddebacb 04/12: Allow spoofing process marker in erc-display-line-1, F. Jason Park, 2023/10/13
- master 9c2f99b7d73 05/12: Use erc-display-message instead of erc-make-notice, F. Jason Park, 2023/10/13
- master baf778c7caa 12/12: More defcustom fixes in ERC (Bug#66520), F. Jason Park, 2023/10/13
- master f97fdf5e50e 06/12: Deprecate option erc-remove-parsed-property, F. Jason Park, 2023/10/13
- master 52af0a5fb97 11/12: Add command to refill buffer in erc-fill-wrap-mode, F. Jason Park, 2023/10/13