emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master ef4a3c2a6d8 1/4: ; Fix example in display-buffer section of ERC m


From: F. Jason Park
Subject: master ef4a3c2a6d8 1/4: ; Fix example in display-buffer section of ERC manual
Date: Sun, 17 Sep 2023 19:24:03 -0400 (EDT)

branch: master
commit ef4a3c2a6d8ef854bed066ce25b31ff73e1d7664
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>

    ; Fix example in display-buffer section of ERC manual
    
    * doc/misc/erc.texi: Fix `display-buffer-alist' example and mention
    that it's only meant for users of Emacs 29 and above.
    * test/lisp/erc/erc-tests.el (erc-setup-buffer--custom-action): Add
    simplistic test case for example in manual.
---
 doc/misc/erc.texi          | 11 ++++++-----
 test/lisp/erc/erc-tests.el | 30 ++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi
index 6d7785a9b54..3297d8b17f0 100644
--- a/doc/misc/erc.texi
+++ b/doc/misc/erc.texi
@@ -1803,10 +1803,11 @@ Observe that ERC supplies the names of buffer-display 
options as
 the symbols @samp{erc-tls} or @samp{url}, the full lineup of which are
 listed below.
 
-In this second example, the user writes three predicates that somewhat
-resemble the ``@code{display-buffer}-like'' function above.  These too
-look for @var{action} alist keys sharing the names of buffer-display
-options (and, in one case, a module's minor mode).
+In this second example, for Emacs 29 and above, the user writes three
+predicates that somewhat resemble the ``@code{display-buffer}-like''
+function above.  These too look for @var{action} alist keys sharing
+the names of ERC's buffer-display options (and, in one case, a
+module's minor mode).
 
 @lisp
 (defun my-erc-disp-entry-p (_ action)
@@ -1821,7 +1822,7 @@ options (and, in one case, a module's minor mode).
 
 (defun my-erc-disp-chan-p (_ action)
   (or (assq 'erc-autojoin-mode action)
-      (and (memq (cdr (assq 'erc-buffer-display alist)) 'JOIN)
+      (and (eq (cdr (assq 'erc-buffer-display action)) 'JOIN)
            (member (erc-default-target) '("#emacs" "#fsf")))))
 @end lisp
 
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 3b278959dc1..05d45b2d027 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -560,6 +560,36 @@
                        (pop calls)))
         (should-not calls)))
 
+    ;; Mimic simplistic version of example in "(erc) display-buffer".
+    (when (>= emacs-major-version 29)
+      (let ((proc erc-server-process))
+        (with-temp-buffer
+          (should-not (eq (window-buffer) (current-buffer)))
+          (erc-mode)
+          (setq erc-server-process proc)
+
+          (cl-letf (((symbol-function 'erc--test-fun-p)
+                     (lambda (buf action)
+                       (should (eql 1 (alist-get 'erc-buffer-display action)))
+                       (push (cons 'erc--test-fun-p buf) calls)))
+                    ((symbol-function 'action-fn)
+                     (lambda (buf action)
+                       (should (eql 1 (alist-get 'erc-buffer-display action)))
+                       (should (eql 42 (alist-get 'foo action)))
+                       (push (cons 'action-fn buf) calls)
+                       (selected-window))))
+
+            (let ((erc--display-context '((erc-buffer-display . 1)))
+                  (display-buffer-alist
+                   `(((and (major-mode . erc-mode) erc--test-fun-p)
+                      action-fn (foo . 42))))
+                  (erc-buffer-display 'display-buffer))
+
+              (erc-setup-buffer (current-buffer))
+              (should (equal 'action-fn (car (pop calls))))
+              (should (equal 'erc--test-fun-p (car (pop calls))))
+              (should-not calls))))))
+
     (should (eq owin (selected-window)))
     (should (eq obuf (window-buffer)))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]