[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fix/bug-48598 31030f2568 14/27: Add eventual replacement for erc-default
From: |
F. Jason Park |
Subject: |
fix/bug-48598 31030f2568 14/27: Add eventual replacement for erc-default-recipients |
Date: |
Fri, 8 Apr 2022 03:06:48 -0400 (EDT) |
branch: fix/bug-48598
commit 31030f25684d5312bcca9fd8d7bd0220fa48f6b9
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Add eventual replacement for erc-default-recipients
* lisp/erc/erc.el (erc--target, erc--target-channel,
erc--target-channel-local): Add new structs to hold info on a buffer's
target; stored in a local variable of the same name.
(erc-open): Create above items in non server buffers.
* lisp/erc/erc-backend.el (erc-server-NICK): Recreate `erc--target'
when necessary.
---
lisp/erc/erc-backend.el | 4 ++--
lisp/erc/erc.el | 30 ++++++++++++++++++++++++++++++
test/lisp/erc/erc-tests.el | 12 ++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 48045595c7..8bb25a0090 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -1421,8 +1421,8 @@ add things to `%s' instead."
(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--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 131850c19a..6ecfcd341c 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1380,6 +1380,35 @@ if ARG is omitted or nil.
(put ',enable 'definition-name ',name)
(put ',disable 'definition-name ',name))))
+;; The rationale for favoring inheritance here (nicer dispatch) is
+;; kinda flimsy since there aren't yet any actual methods.
+
+(cl-defstruct erc--target
+ (string "" :type string :documentation "Received name of target.")
+ (symbol nil :type symbol :documentation "Case-mapped name as symbol."))
+
+(cl-defstruct (erc--target-channel (:include erc--target)))
+
+(cl-defstruct (erc--target-channel-local (:include erc--target-channel)))
+
+(defun erc--target-from-string (string)
+ "Construct an `erc--target' variant from STRING."
+ (funcall (if (erc-channel-p string)
+ (if (erc-valid-local-channel-p string)
+ #'make-erc--target-channel-local
+ #'make-erc--target-channel)
+ #'make-erc--target)
+ :string string :symbol (intern (erc-downcase string))))
+
+(defvar-local erc--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--target
+ (erc--target-string erc--target)))
+
(defun erc-once-with-server-event (event f)
"Run function F the next time EVENT occurs in the `current-buffer'.
@@ -2080,6 +2109,7 @@ Returns the buffer for the given server or channel."
(set-marker erc-insert-marker (point))
;; stack of default recipients
(setq erc-default-recipients tgt-list)
+ (setq erc--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 ff232577e9..e60899969d 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -435,6 +435,18 @@
(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-channel "#chan" \#chan)))
+
+ (should (equal (erc--target-from-string "Bob")
+ #s(erc--target "Bob" bob)))
+
+ (let ((erc--isupport-params (make-hash-table)))
+ (puthash 'CHANTYPES '("&#") erc--isupport-params)
+ (should (equal (erc--target-from-string "&Bitlbee")
+ #s(erc--target-channel-local "&Bitlbee" &bitlbee)))))
+
(ert-deftest erc-ring-previous-command-base-case ()
(ert-info ("Create ring when nonexistent and do nothing")
(let (erc-input-ring
- fix/bug-48598 1978c3178c 10/27: Update ISUPPORT handling in ERC, (continued)
- fix/bug-48598 1978c3178c 10/27: Update ISUPPORT handling in ERC, F. Jason Park, 2022/04/08
- fix/bug-48598 6ee4329b46 02/27: Initialize erc-server-filter-data in erc-backend, F. Jason Park, 2022/04/08
- fix/bug-48598 3c6694d114 20/27: Don't call erc-auto-query twice on PRIVMSG, F. Jason Park, 2022/04/08
- fix/bug-48598 50b3aa88fc 11/27: Recognize ascii and strict CASEMAPPINGs in ERC, F. Jason Park, 2022/04/08
- fix/bug-48598 f9794dea43 15/27: Discourage ill-defined use of buffer targets in ERC, F. Jason Park, 2022/04/08
- fix/bug-48598 bb117dfacb 05/27: [SQUASH-ME] Remove duplicate ERC prompt on reconnect, F. Jason Park, 2022/04/08
- fix/bug-48598 c25371f9d7 08/27: Don't set erc-server-announced-name unless known, F. Jason Park, 2022/04/08
- fix/bug-48598 8558f9434a 12/27: Make ERC respect spaces in server passwords, F. Jason Park, 2022/04/08
- fix/bug-48598 a9ef01ec76 06/27: Customize displaying of ERC buffers on reconnect, F. Jason Park, 2022/04/08
- fix/bug-48598 eef4fa00e8 01/27: Rework mutual dependency between erc and erc-backend, F. Jason Park, 2022/04/08
- fix/bug-48598 31030f2568 14/27: Add eventual replacement for erc-default-recipients,
F. Jason Park <=
- fix/bug-48598 6ece132c35 09/27: Require erc-networks in erc.el, F. Jason Park, 2022/04/08
- fix/bug-48598 346381ffe5 17/27: Address long-standing ERC buffer-naming issues, F. Jason Park, 2022/04/08
- fix/bug-48598 bd8efa668b 18/27: SQUASH-ME: Add user-oriented test scenarios for ERC, F. Jason Park, 2022/04/08
- fix/bug-48598 242c8374b0 22/27: Favor network identities in erc-join, F. Jason Park, 2022/04/08
- fix/bug-48598 11e9bb2b2f 25/27: SQUASH-ME: Add ERC test scenarios involving auth-source, F. Jason Park, 2022/04/08
- fix/bug-48598 ab2d93e564 27/27: Update ERC's Info doc with network-ID related changes, F. Jason Park, 2022/04/08
- fix/bug-48598 dd5a99e891 26/27: SQUASH-ME: Add ERC test scenario for erc-cmd-JOIN, F. Jason Park, 2022/04/08