From b60011843f6508f3a0a079795913de2d8ca7f903 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 19 Feb 2023 07:01:40 -0800 Subject: [PATCH 0/7] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (7): [5.6] Honor arbitrary CHANTYPES in ERC [5.6] Copy over upstream Compat macros to erc-compat [5.6] Leverage loaddefs for migrating ERC modules [5.6] Don't require erc-goodies in erc.el [5.6] Modify erc-mode-map in module definitions [5.6] Add missing colors to erc-irccontrols-mode [5.6] Convert ERC's Imenu integration into proper module lisp/erc/erc-backend.el | 2 +- lisp/erc/erc-button.el | 6 +- lisp/erc/erc-common.el | 39 +---- lisp/erc/erc-compat.el | 52 ++++-- lisp/erc/erc-goodies.el | 97 ++++++----- lisp/erc/erc-ibuffer.el | 1 + lisp/erc/erc-imenu.el | 23 ++- lisp/erc/erc-log.el | 8 +- lisp/erc/erc-match.el | 8 +- lisp/erc/erc-page.el | 4 + lisp/erc/erc-pcomplete.el | 2 + lisp/erc/erc-services.el | 1 + lisp/erc/erc-sound.el | 1 + lisp/erc/erc-speedbar.el | 1 + lisp/erc/erc-stamp.el | 4 + lisp/erc/erc.el | 97 +++++++---- test/lisp/erc/erc-goodies-tests.el | 251 +++++++++++++++++++++++++++++ test/lisp/erc/erc-tests.el | 187 +++++++++++++++++++-- 18 files changed, 649 insertions(+), 135 deletions(-) create mode 100644 test/lisp/erc/erc-goodies-tests.el Interdiff: diff --git a/lisp/erc/erc-imenu.el b/lisp/erc/erc-imenu.el index 3b5dd988c18..526afd32249 100644 --- a/lisp/erc/erc-imenu.el +++ b/lisp/erc/erc-imenu.el @@ -52,7 +52,8 @@ erc-unfill-notice (forward-line 1) (looking-at " ")) (forward-line 1)) - (end-of-line) (point))))) + (end-of-line) (point)))) + (inhibit-read-only t)) (with-temp-buffer (insert str) (goto-char (point-min)) @@ -132,7 +133,7 @@ erc-imenu-setup (when (and (local-variable-p 'imenu-create-index-function) imenu-create-index-function) (setq erc-imenu--create-index-function imenu-create-index-function)) - (setq-local imenu-create-index-function #'erc-create-imenu-index)) + (setq imenu-create-index-function #'erc-create-imenu-index)) ;;;###autoload(autoload 'erc-imenu-mode "erc-imenu" nil t) (define-erc-module imenu nil diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 6ad1303d48b..fb99482cb7e 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1544,10 +1544,14 @@ erc-reuse-frames (defun erc-channel-p (channel) "Return non-nil if CHANNEL seems to be an IRC channel name." (cond ((stringp channel) - (memq (aref channel 0) '(?# ?& ?+ ?!))) - ((and (bufferp channel) (buffer-live-p channel)) - (with-current-buffer channel - (erc-channel-p (erc-default-target)))) + (memq (aref channel 0) + (if-let ((types (erc--get-isupport-entry 'CHANTYPES 'single))) + (append types nil) + '(?# ?& ?+ ?!)))) + ((and-let* (((bufferp channel)) + ((buffer-live-p channel)) + (target (buffer-local-value 'erc--target channel))) + (erc-channel-p (erc--target-string target)))) (t nil))) ;; For the sake of compatibility, a historical quirk concerning this @@ -1840,12 +1844,20 @@ erc-modules :get (lambda (sym) ;; replace outdated names with their newer equivalents (erc-migrate-modules (symbol-value sym))) - :initialize #'custom-initialize-default + ;; Expect every built-in module to have the symbol property + ;; `erc--module' set to its canonical symbol (often itself). + :initialize (lambda (symbol exp) + ;; Use `cdddr' because (set :greedy t . ,entries) + (dolist (entry (cdddr (get 'erc-modules 'custom-type))) + (when-let* (((eq (car entry) 'const)) + (s (cadddr entry))) ; (const :tag "..." ,s) + (put s 'erc--module s))) + (custom-initialize-default symbol exp)) :set (lambda (sym val) ;; disable modules which have just been removed (when (and (boundp 'erc-modules) erc-modules val) (dolist (module erc-modules) - (unless (member module val) + (unless (memq module val) (let ((f (intern-soft (format "erc-%s-mode" module)))) (when (and (fboundp f) (boundp f)) (when (symbol-value f) @@ -1857,7 +1869,14 @@ erc-modules (when (symbol-value f) (funcall f 0)) (kill-local-variable f))))))))) - (set sym val) + (let (built-in third-party) + (dolist (v val) + (setq v (erc--normalize-module-symbol v)) + (if (get v 'erc--module) + (push v built-in) + (push v third-party))) + (set sym (append (sort built-in #'string-lessp) + (nreverse third-party)))) ;; this test is for the case where erc hasn't been loaded yet (when (fboundp 'erc-update-modules) (erc-update-modules))) @@ -1912,7 +1931,7 @@ erc-modules (const :tag "unmorse: Translate morse code in messages" unmorse) (const :tag "xdcc: Act as an XDCC file-server" xdcc) (repeat :tag "Others" :inline t symbol)) - :package-version '(ERC . "5.5") ; FIXME sync on release + :package-version '(ERC . "5.6") ; FIXME sync on release :group 'erc) (defun erc-update-modules () @@ -1923,15 +1942,17 @@ erc-update-modules (defun erc--find-mode (sym) (setq sym (erc--normalize-module-symbol sym)) - (let ((mode (intern-soft (concat "erc-" (symbol-name sym) "-mode")))) - (or mode - (and (require (or (get sym 'erc--feature) - (intern (concat "erc-" (symbol-name sym)))) - nil 'noerror) - (setq mode (intern-soft (concat "erc-" (symbol-name sym) - "-mode"))) - (fboundp mode) - mode)))) + (if-let* ((mode (intern-soft (concat "erc-" (symbol-name sym) "-mode"))) + ((or (boundp mode) + (and (fboundp mode) + (autoload-do-load (symbol-function mode) mode))))) + mode + (and (require (or (get sym 'erc--feature) + (intern (concat "erc-" (symbol-name sym)))) + nil 'noerror) + (setq mode (intern-soft (concat "erc-" (symbol-name sym) "-mode"))) + (fboundp mode) + mode))) (defun erc--update-modules () (let (local-modes) @@ -6859,8 +6880,6 @@ erc-format-lag-time (cond (lag (format "lag:%.0f" lag)) (t "")))) -;; erc-goodies is required at end of this file. - ;; TODO when ERC drops Emacs 28, replace the expressions in the format ;; spec below with functions. (defun erc-update-mode-line-buffer (buffer) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 816469d9894..c57d7689ed4 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -447,6 +447,27 @@ erc-downcase (should (equal (erc-downcase "Tilde~") "tilde~" )) (should (equal (erc-downcase "\\O/") "|o/" ))))) +(ert-deftest erc-channel-p () + (let ((erc--isupport-params (make-hash-table)) + erc-server-parameters) + + (should (erc-channel-p "#chan")) + (should (erc-channel-p "##chan")) + (should (erc-channel-p "&chan")) + (should (erc-channel-p "+chan")) + (should (erc-channel-p "!chan")) + (should-not (erc-channel-p "@chan")) + + (push '("CHANTYPES" . "#&@+!") erc-server-parameters) + + (should (erc-channel-p "!chan")) + (should (erc-channel-p "#chan")) + + (with-current-buffer (get-buffer-create "#chan") + (setq erc--target (erc--target-from-string "#chan"))) + (should (erc-channel-p (get-buffer "#chan")))) + (kill-buffer "#chan")) + (ert-deftest erc--valid-local-channel-p () (ert-info ("Local channels not supported") (let ((erc--isupport-params (make-hash-table))) @@ -1254,6 +1275,17 @@ erc-tests--modules replace ring sasl scrolltobottom services smiley sound spelling stamp track truncate unmorse xdcc)) +;; Ensure the `:initialize' function for `erc-modules' successfully +;; tags all built-in modules with the internal property `erc--module'. + +(ert-deftest erc-modules--internal-property () + (let (ours) + (mapatoms (lambda (s) + (when-let ((v (get s 'erc--module)) + ((eq v s))) + (push s ours)))) + (should (equal (sort ours #'string-lessp) erc-tests--modules)))) + (ert-deftest erc--normalize-module-symbol () (dolist (mod erc-tests--modules) (should (eq (erc--normalize-module-symbol mod) mod))) -- 2.39.1