From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Tue, 19 Oct 2021 22:53:03 -0700 Subject: [PATCH 08/28] Add eventual replacement for erc-default-recipients * lisp/erc/erc.el (erc--target, erc--buffer-target): Add new defstruct available locally through latter in all target buffers. (erc-open): Create above items in non server buffers. * lisp/erc/erc-backend.el (erc-server-NICK): Recreate `erc--buffer-target' when necessary. --- lisp/erc/erc-backend.el | 4 ++-- lisp/erc/erc.el | 29 +++++++++++++++++++++++++++++ test/lisp/erc/erc-tests.el | 11 +++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index dedc041f51..e7256cd793 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -1388,8 +1388,8 @@ define-erc-response-handler (erc-buffer-filter (lambda () (when (equal (erc-default-target) nick) - (setq erc-default-recipients - (cons nn (cdr erc-default-recipients))) + (setq erc-default-recipients (cons nn (cdr erc-default-recipients)) + erc--buffer-target (erc--target-from-string nn)) (rename-buffer nn t) ; bug#12002 (erc-update-mode-line) (cl-pushnew (current-buffer) bufs)))) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index ae386cc096..0c2cbb9d82 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1352,6 +1352,34 @@ define-erc-module (put ',enable 'definition-name ',name) (put ',disable 'definition-name ',name)))) +;; ERASE ME: instead of this, we could have an erc--target-channel +;; type and (:include erc--target), but then erc--target-channel-p +;; would be no simpler than what we have here. +(cl-defstruct (erc--target + (:constructor + erc--target-from-string + (string + &aux + (symbol (intern (erc-downcase string))) + (channel-p (and (erc-channel-p string) t)) + (local-p (and channel-p + (erc-valid-local-channel-p string) + t))))) + ;; Use local-p instead of localp so accessor is hyphenated. + (string "" :type string :documentation "Received name of target.") + (symbol nil :type symbol :documentation "Case-mapped name as symbol.") + (channel-p nil :type boolean :documentation "Whether we're a channel.") + (local-p nil :type boolean :documentation "Whether we're a local channel.")) + +(defvar-local erc--buffer-target nil + "Info about a buffer's target, if any.") + +;; Temporary internal getter to ease transition to `erc--target' everywhere. +(defun erc--default-target () + "Return target string or nil." + (when erc--buffer-target + (erc--target-string erc--buffer-target))) + (defun erc-once-with-server-event (event f) "Run function F the next time EVENT occurs in the `current-buffer'. @@ -2042,6 +2070,7 @@ erc-open (set-marker erc-insert-marker (point)) ;; stack of default recipients (setq erc-default-recipients tgt-list) + (setq erc--buffer-target (and channel (erc--target-from-string channel))) (setq erc-server-current-nick nil) ;; Initialize erc-server-users and erc-channel-users (if connect diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index e1454305c2..d9112c7b0a 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -227,6 +227,17 @@ erc-local-channel-p (should-not (erc-valid-local-channel-p "#chan")) (should (erc-valid-local-channel-p "&local"))))) +(ert-deftest erc--target-from-string () + (should (equal (erc--target-from-string "#chan") + #s(erc--target "#chan" \#chan t nil))) + + (should (equal (erc--target-from-string "Bob") + #s(erc--target "Bob" bob nil nil))) + + (let ((erc-isupport-parameters '((CHANTYPES "#&")))) + (should (equal (erc--target-from-string "&Bitlbee") + #s(erc--target "&Bitlbee" &bitlbee t t))))) + (ert-deftest erc-ring-previous-command-base-case () (ert-info ("Create ring when nonexistent and do nothing") (let (erc-input-ring -- 2.31.1