From: F. Jason Park Date: Fri, 13 Jan 2023 14:03:15 +0000 (-0800) Subject: Don't preserve non-module minor modes in erc-open X-Git-Tag: emacs-29.0.90~696 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=183e749270208ad7f63114ea8ab05e7612a645a1;p=emacs.git Don't preserve non-module minor modes in erc-open * lisp/erc/erc-common.el (define-erc-module): Add symbol property `erc-module' to minor modes defined as part of a module. * lisp/erc/erc.el (erc--merge-local-modes): Be more conservative when persisting local minor-mode state across ERC sessions. User and third-party modes that were not defined via `define-erc-modules' should be left alone. (erc-open): Run major-mode hooks and enable minor modes after prompt has been set up. This ensures that module-setup code can access a fully initialized `erc-input-marker'. * test/lisp/erc/erc-tests.el (erc--merge-local-modes): Add mocks for `erc-module' symbol property and a test case covering some foreign ERC mode. (define-erc-module--global, define-erc-module--local): Expect the `erc-module' symbol property to be defined for mode symbols and aliases. (Bug#60784.) --- diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el index 9eb4f1a9000..994555acecf 100644 --- a/lisp/erc/erc-common.el +++ b/lisp/erc/erc-common.el @@ -202,12 +202,13 @@ if ARG is omitted or nil. (,disable))) ,(erc--assemble-toggle local-p name enable mode t enable-body) ,(erc--assemble-toggle local-p name disable mode nil disable-body) - ,(when (and alias (not (eq name alias))) - `(defalias - ',(intern - (format "erc-%s-mode" - (downcase (symbol-name alias)))) - #',mode)) + ,@(and-let* ((alias) + ((not (eq name alias))) + (aname (intern (format "erc-%s-mode" + (downcase (symbol-name alias)))))) + `((defalias ',aname #',mode) + (put ',aname 'erc-module ',(erc--normalize-module-symbol name)))) + (put ',mode 'erc-module ',(erc--normalize-module-symbol name)) ;; For find-function and find-variable. (put ',mode 'definition-name ',name) (put ',enable 'definition-name ',name) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index e7f81f24ac4..7f51b7bfb2e 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1958,7 +1958,8 @@ nil." (let ((out (list (reverse new-modes)))) (pcase-dolist (`(,k . ,v) old-vars) (when (and (string-prefix-p "erc-" (symbol-name k)) - (string-suffix-p "-mode" (symbol-name k))) + (string-suffix-p "-mode" (symbol-name k)) + (get k 'erc-module)) (if v (cl-pushnew k (car out)) (setf (car out) (delq k (car out))) @@ -2082,9 +2083,7 @@ Returns the buffer for the given server or channel." (erc-determine-parameters server port nick full-name user passwd) - (save-excursion (run-mode-hooks)) - (dolist (mod (car delayed-modules)) (funcall mod +1)) - (dolist (var (cdr delayed-modules)) (set var nil)) + ;; FIXME consolidate this prompt-setup logic with the pass above. ;; set up prompt (unless continued-session @@ -2097,6 +2096,10 @@ Returns the buffer for the given server or channel." (erc-display-prompt) (goto-char (point-max))) + (save-excursion (run-mode-hooks) + (dolist (mod (car delayed-modules)) (funcall mod +1)) + (dolist (var (cdr delayed-modules)) (set var nil))) + ;; Saving log file on exit (run-hook-with-args 'erc-connect-pre-hook buffer) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 85506c3d27e..40a2d2de657 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1251,18 +1251,28 @@ (setq calls nil))))) (ert-deftest erc--merge-local-modes () - - (ert-info ("No existing modes") - (let ((old '((a) (b . t))) - (new '(erc-c-mode erc-d-mode))) - (should (equal (erc--merge-local-modes new old) - '((erc-c-mode erc-d-mode)))))) - - (ert-info ("Active existing added, inactive existing removed, deduped") - (let ((old '((a) (erc-b-mode) (c . t) (erc-d-mode . t) (erc-e-mode . t))) - (new '(erc-b-mode erc-d-mode))) - (should (equal (erc--merge-local-modes new old) - '((erc-d-mode erc-e-mode) . (erc-b-mode))))))) + (cl-letf (((get 'erc-b-mode 'erc-module) 'b) + ((get 'erc-c-mode 'erc-module) 'c) + ((get 'erc-d-mode 'erc-module) 'd) + ((get 'erc-e-mode 'erc-module) 'e)) + + (ert-info ("No existing modes") + (let ((old '((a) (b . t))) + (new '(erc-c-mode erc-d-mode))) + (should (equal (erc--merge-local-modes new old) + '((erc-c-mode erc-d-mode)))))) + + (ert-info ("Active existing added, inactive existing removed, deduped") + (let ((old '((a) (erc-b-mode) (c . t) (erc-d-mode . t) (erc-e-mode . t))) + (new '(erc-b-mode erc-d-mode))) + (should (equal (erc--merge-local-modes new old) + '((erc-d-mode erc-e-mode) . (erc-b-mode)))))) + + (ert-info ("Non-module erc-prefixed mode ignored") + (let ((old '((erc-b-mode) (erc-f-mode . t) (erc-d-mode . t))) + (new '(erc-b-mode))) + (should (equal (erc--merge-local-modes new old) + '((erc-d-mode) . (erc-b-mode)))))))) (ert-deftest define-erc-module--global () (let ((global-module '(define-erc-module mname malias @@ -1300,13 +1310,15 @@ Some docstring" (ignore c) (ignore d)) (defalias 'erc-malias-mode #'erc-mname-mode) + (put 'erc-malias-mode 'erc-module 'mname) + (put 'erc-mname-mode 'erc-module 'mname) (put 'erc-mname-mode 'definition-name 'mname) (put 'erc-mname-enable 'definition-name 'mname) (put 'erc-mname-disable 'definition-name 'mname)))))) (ert-deftest define-erc-module--local () - (let* ((global-module '(define-erc-module mname malias + (let* ((global-module '(define-erc-module mname nil ; no alias "Some docstring" ((ignore a) (ignore b)) ((ignore c) (ignore d)) @@ -1353,8 +1365,7 @@ When called interactively, do so in all buffers for the current connection." (setq erc-mname-mode nil) (ignore c) (ignore d)))) - (defalias 'erc-malias-mode #'erc-mname-mode) - + (put 'erc-mname-mode 'erc-module 'mname) (put 'erc-mname-mode 'definition-name 'mname) (put 'erc-mname-enable 'definition-name 'mname) (put 'erc-mname-disable 'definition-name 'mname))))))