>From f26186f56d1ae01b8db94476d6deb8348af07860 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 26 Sep 2021 00:41:23 -0700 Subject: [PATCH] Optionally exclude nicks from tracking in ERC * lisp/erc/erc-track.el (erc-track-exclude-nicks): Add option to exclude activity from specified nicks when mode-line tracking. (erc-track-modified-channels, erc-track--exclude-type-p, erc-track--exclude-nick-p): Consider new option `erc-track-exclude-nicks' when deciding whether to update tracking state. Add a couple helpers to assist with that. --- lisp/erc/erc-track.el | 21 +++++++++++++--- test/lisp/erc/erc-track-tests.el | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/lisp/erc/erc-track.el b/lisp/erc/erc-track.el index 5755384490..6343a6ca7e 100644 --- a/lisp/erc/erc-track.el +++ b/lisp/erc/erc-track.el @@ -103,6 +103,11 @@ erc-track-exclude-types channel (353)." :type 'erc-message-type) +(defcustom erc-track-exclude-nicks nil + "List of nicks to be ignored accross all networks and targets." + :type '(repeat string) + :set (lambda (sym val) (set sym (mapcar #'erc-downcase val)))) + (defcustom erc-track-exclude-server-buffer nil "If true, don't perform tracking on the server buffer. This is useful for excluding all the things like MOTDs from the @@ -774,6 +779,15 @@ erc-track-select-mode-line-face choice)) choice)))) +(defun erc-track--exclude-type-p (parsed) + (when erc-track-exclude-types + (member (erc-response.command parsed) erc-track-exclude-types))) + +(defun erc-track--exclude-nick-p (parsed) + (when-let ((erc-track-exclude-nicks) + (nick (erc-extract-nick (erc-response.sender parsed)))) + (member (erc-downcase nick) erc-track-exclude-nicks))) + (defun erc-track-modified-channels () "Hook function for `erc-insert-post-hook'. Check if the current buffer should be added to the mode line as a @@ -785,10 +799,9 @@ erc-track-modified-channels (not (member this-channel erc-track-exclude)) (not (and erc-track-exclude-server-buffer (erc-server-buffer-p))) - (not (erc-message-type-member - (or (erc-find-parsed-property) - (point-min)) - erc-track-exclude-types))) + (and-let* ((parsed (erc-get-parsed-vector (point-min))) + ((not (erc-track--exclude-type-p parsed))) + ((not (erc-track--exclude-nick-p parsed)))))) ;; If the active buffer is not visible (not shown in a ;; window), and not to be excluded, determine the kinds of ;; faces used in the current message, and unless the user diff --git a/test/lisp/erc/erc-track-tests.el b/test/lisp/erc/erc-track-tests.el index 0ce93bd45c..d6bc95085e 100644 --- a/test/lisp/erc/erc-track-tests.el +++ b/test/lisp/erc/erc-track-tests.el @@ -119,3 +119,46 @@ erc-track--erc-faces-in '(bold erc-current-nick-face) str1) (should (erc-faces-in str0)) (should (erc-faces-in str1)) )) + +(ert-deftest erc-track-exclude-nicks () + (let (erc-modified-channels-object + erc-modified-channels-alist + erc-track-exclude-nicks + (erc-insert-post-hook (list #'erc-track-modified-channels))) + + (cl-letf (((symbol-function 'erc-buffer-visible) (lambda (_) nil))) + (with-current-buffer (get-buffer-create "#c") + (erc-mode) + (setq erc-insert-marker (set-marker (make-marker) (point-max))) + + (ert-info ("Message from bob's triggers modeline activity") + (erc-display-message (make-erc-response :sender "bob!~u@localhost" + :command "PRIVMSG" + :command-args '("#c" "Hi")) + nil + (current-buffer) + (erc-format-privmessage "bob" "Hi" nil t)) + (should (equal + (erc-string-no-properties erc-modified-channels-object) + " [#c] "))) + + (ert-info ("Clear mode line by pretending to visit buffer #c") + (erc-modified-channels-remove-buffer (current-buffer)) + (erc-modified-channels-display) + (should (string-empty-p + (erc-string-no-properties erc-modified-channels-object)))) + + (ert-info ("Add bob to option `erc-track-exclude-nicks' and go again") + (push "bob" erc-track-exclude-nicks) + (erc-display-message (make-erc-response :sender "bob!~u@localhost" + :command "PRIVMSG" + :command-args '("#c" "Lo")) + nil + (current-buffer) + (erc-format-privmessage "bob" "Lo" nil t))) + + (ert-info ("Modeline remains untouched") + (should (string-empty-p + (erc-string-no-properties erc-modified-channels-object)))) + + (when noninteractive (kill-buffer)))))) -- 2.31.1