1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Modify erc-mode-map in module definitions

* lisp/erc/erc-button.el (erc-button-mode, erc-button-enable,
erc-button-disable): Replace call to `erc-button-setup' with one to
`erc--modify-local-map'.  This means `erc-button-setup' is now dead
code from a client perspective.
* lisp/erc/erc-goodies.el (erc-irccontrols-enable,
erc-irccontrols-disable, erc-irccontrols-mode): Bind
`erc-toggle-interpret-controls' in module definition so it's only
available when the module is active.
* lisp/erc/erc-log.el (erc-log-mode, erc-log-enable, erc-log-disable):
Move top-level `define-key' into module definition.
* lisp/erc/erc-match.el (erc-match-mode, erc-match-enable,
erc-match-disable): Move top-level `define-key' into module
definition.
* lisp/erc/erc.el (erc-mode-map): Remove C-c C-c binding for
`erc-toggle-interpret-controls'.
(erc--modify-local-map): Add helper for global modules to use when
modifying `erc-mode-map'.
* test/lisp/erc/erc-tests.el (erc--modify-local-map): Add test.
Ensure modifications to `erc-mode-map' on loading `erc' and via
`erc-mode-hook' still work.  (Bug#60954.)
This commit is contained in:
F. Jason Park 2023-01-19 21:07:27 -08:00
parent 5011554529
commit 9aa2806fdc
6 changed files with 73 additions and 13 deletions

View file

@ -492,6 +492,50 @@
(should (equal (erc--target-from-string "&Bitlbee")
#s(erc--target-channel-local "&Bitlbee" &bitlbee)))))
(ert-deftest erc--modify-local-map ()
(when (and (bound-and-true-p erc-irccontrols-mode)
(fboundp 'erc-irccontrols-mode))
(erc-irccontrols-mode -1))
(when (and (bound-and-true-p erc-match-mode)
(fboundp 'erc-match-mode))
(erc-match-mode -1))
(let* (calls
(inhibit-message noninteractive)
(cmd-foo (lambda () (interactive) (push 'foo calls)))
(cmd-bar (lambda () (interactive) (push 'bar calls))))
(ert-info ("Add non-existing")
(erc--modify-local-map t "C-c C-c" cmd-foo "C-c C-k" cmd-bar)
(with-temp-buffer
(set-window-buffer (selected-window) (current-buffer))
(use-local-map erc-mode-map)
(execute-kbd-macro "\C-c\C-c")
(execute-kbd-macro "\C-c\C-k"))
(should (equal calls '(bar foo))))
(setq calls nil)
(ert-info ("Add existing") ; Attempt to swap definitions fails
(erc--modify-local-map t "C-c C-c" cmd-bar "C-c C-k" cmd-foo)
(with-temp-buffer
(set-window-buffer (selected-window) (current-buffer))
(use-local-map erc-mode-map)
(execute-kbd-macro "\C-c\C-c")
(execute-kbd-macro "\C-c\C-k"))
(should (equal calls '(bar foo))))
(setq calls nil)
(ert-info ("Remove existing")
(ert-with-message-capture messages
(erc--modify-local-map nil "C-c C-c" cmd-foo "C-c C-k" cmd-bar)
(with-temp-buffer
(set-window-buffer (selected-window) (current-buffer))
(use-local-map erc-mode-map)
(execute-kbd-macro "\C-c\C-c")
(execute-kbd-macro "\C-c\C-k"))
(should (string-search "C-c C-c is undefined" messages))
(should (string-search "C-c C-k is undefined" messages))
(should-not calls)))))
(ert-deftest erc-ring-previous-command-base-case ()
(ert-info ("Create ring when nonexistent and do nothing")
(let (erc-input-ring