; 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.
This commit is contained in:
parent
7d2870dc85
commit
ef4a3c2a6d
2 changed files with 36 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)))))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue