aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2021-10-20 03:52:18 -0700
committerF. Jason Park2022-06-30 15:03:26 -0700
commite958a2b726fdcb5a4f58169e6f4f384f5786f86a (patch)
treefa3e5b3971ea799432080b3a4eaf51905a3d0e00
parent529e46f1287ddb6fc16779a3f14016d0c305037c (diff)
downloademacs-e958a2b726fdcb5a4f58169e6f4f384f5786f86a.tar.gz
emacs-e958a2b726fdcb5a4f58169e6f4f384f5786f86a.zip
Discourage ill-defined use of buffer targets in ERC
* lisp/erc/erc.el (erc-default-recipients, erc-default-target): Explain that the variable has fallen out of favor and that the function may have been used historically by third-party code for detecting channel subscription status, even though that's never been the case internally since at least the adoption of version control. Recommend newer alternatives. (erc--current-buffer-joined-p): Add possibly temporary predicate for detecting whether a buffer's target is a joined channel. The existing means are inconsistent, as discussed in bug#48598. The mere fact that they are disparate is unfriendly to new contributors. For example, in the function `erc-autojoin-channels', the `process-status' of the `erc-server-process' is used to detect whether a buffer needs joining. That's fine in that specific situation, but it won't work elsewhere. And neither will checking whether `erc-default-target' is nil, so long as `erc-delete-default-channel' and friends remain in play. (erc-add-default-channel, erc-delete-default-channel, erc-add-query, erc-delete-query): Deprecate these helpers, which rely on an unused usage variant of `erc-default-recipients'. * lisp/erc/erc-services.el: remove stray `erc-default-recipients' declaration. * lisp/erc/erc-backend.el (erc-server-NICK, erc-server-JOIN, erc-server-KICK, erc-server-PART): wrap deprecated helpers to suppress warnings. * lisp/erc/erc-join.el (erc-autojoin-channels): Use helper to detect whether a buffer needs joining. Prefer this to server liveliness, as explained above.
-rw-r--r--lisp/erc/erc-backend.el10
-rw-r--r--lisp/erc/erc-join.el2
-rw-r--r--lisp/erc/erc-track.el2
-rw-r--r--lisp/erc/erc.el41
4 files changed, 48 insertions, 7 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index bb423eadc0f..305422195b3 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -1339,7 +1339,9 @@ add things to `%s' instead."
1339 erc-server-process)) 1339 erc-server-process))
1340 (when buffer 1340 (when buffer
1341 (set-buffer buffer) 1341 (set-buffer buffer)
1342 (erc-add-default-channel chnl) 1342 (with-suppressed-warnings
1343 ((obsolete erc-add-default-channel))
1344 (erc-add-default-channel chnl))
1343 (erc-server-send (format "MODE %s" chnl))) 1345 (erc-server-send (format "MODE %s" chnl)))
1344 (erc-with-buffer (chnl proc) 1346 (erc-with-buffer (chnl proc)
1345 (erc-channel-begin-receiving-names)) 1347 (erc-channel-begin-receiving-names))
@@ -1376,7 +1378,8 @@ add things to `%s' instead."
1376 (erc-with-buffer 1378 (erc-with-buffer
1377 (buffer) 1379 (buffer)
1378 (erc-remove-channel-users)) 1380 (erc-remove-channel-users))
1379 (erc-delete-default-channel ch buffer) 1381 (with-suppressed-warnings ((obsolete erc-delete-default-channel))
1382 (erc-delete-default-channel ch buffer))
1380 (erc-update-mode-line buffer)) 1383 (erc-update-mode-line buffer))
1381 ((string= nick (erc-current-nick)) 1384 ((string= nick (erc-current-nick))
1382 (erc-display-message 1385 (erc-display-message
@@ -1465,7 +1468,8 @@ add things to `%s' instead."
1465 (erc-with-buffer 1468 (erc-with-buffer
1466 (buffer) 1469 (buffer)
1467 (erc-remove-channel-users)) 1470 (erc-remove-channel-users))
1468 (erc-delete-default-channel chnl buffer) 1471 (with-suppressed-warnings ((obsolete erc-delete-default-channel))
1472 (erc-delete-default-channel chnl buffer))
1469 (erc-update-mode-line buffer) 1473 (erc-update-mode-line buffer)
1470 (when erc-kill-buffer-on-part 1474 (when erc-kill-buffer-on-part
1471 (kill-buffer buffer)))))) 1475 (kill-buffer buffer))))))
diff --git a/lisp/erc/erc-join.el b/lisp/erc/erc-join.el
index b9788c192bc..425de4dc564 100644
--- a/lisp/erc/erc-join.el
+++ b/lisp/erc/erc-join.el
@@ -176,7 +176,7 @@ This function is run from `erc-nickserv-identified-hook'."
176 (erc-downcase current))))))))) 176 (erc-downcase current)))))))))
177 (when (or (not buffer) 177 (when (or (not buffer)
178 (not (with-current-buffer buffer 178 (not (with-current-buffer buffer
179 (erc-server-process-alive)))) 179 (erc--current-buffer-joined-p))))
180 (erc-server-join-channel server chan)))))))) 180 (erc-server-join-channel server chan))))))))
181 ;; Return nil to avoid stomping on any other hook funcs. 181 ;; Return nil to avoid stomping on any other hook funcs.
182 nil) 182 nil)
diff --git a/lisp/erc/erc-track.el b/lisp/erc/erc-track.el
index 9118d7b994f..e8117f9a89b 100644
--- a/lisp/erc/erc-track.el
+++ b/lisp/erc/erc-track.el
@@ -353,8 +353,6 @@ of `erc-track-shorten-start' characters."
353 (> (length s) erc-track-shorten-cutoff)) 353 (> (length s) erc-track-shorten-cutoff))
354 erc-track-shorten-start)) 354 erc-track-shorten-start))
355 355
356(defvar erc-default-recipients)
357
358(defun erc-all-buffer-names () 356(defun erc-all-buffer-names ()
359 "Return all channel or query buffer names. 357 "Return all channel or query buffer names.
360Note that we cannot use `erc-channel-list' with a nil argument, 358Note that we cannot use `erc-channel-list' with a nil argument,
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 078a446a1c3..9f17816b8d4 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1907,6 +1907,21 @@ all channel buffers on all servers."
1907 1907
1908;; Some local variables 1908;; Some local variables
1909 1909
1910;; TODO eventually deprecate this variable
1911;;
1912;; In the ancient, pre-CVS days (prior to June 2001), this list may
1913;; have been used for supporting the changing of a buffer's target on
1914;; the fly (mid-session). Such usage, which allowed cons cells like
1915;; (QUERY . bob) to serve as the list's head, was either never fully
1916;; integrated or was partially clobbered prior to the introduction of
1917;; version control. But vestiges remain (see `erc-dcc-chat-mode').
1918;; And despite appearances, no evidence has emerged that ERC ever
1919;; supported one-to-many target buffers. If such a thing was aspired
1920;; to, it was never realized.
1921;;
1922;; New library code should use the `erc--target' struct instead.
1923;; Third-party code can continue to use this until a getter for
1924;; `erc--target' (or whatever replaces it) is exported.
1910(defvar-local erc-default-recipients nil 1925(defvar-local erc-default-recipients nil
1911 "List of default recipients of the current buffer.") 1926 "List of default recipients of the current buffer.")
1912 1927
@@ -5868,6 +5883,27 @@ See also `erc-downcase'."
5868 5883
5869;; default target handling 5884;; default target handling
5870 5885
5886(defun erc--current-buffer-joined-p ()
5887 "Return whether the current target buffer is joined."
5888 ;; This may be a reliable means of detecting subscription status,
5889 ;; but it's also roundabout and awkward. Perhaps it's worth
5890 ;; discussing adding a joined slot to `erc--target' for this.
5891 (cl-assert erc--target)
5892 (and (erc--target-channel-p erc--target)
5893 (erc-get-channel-user (erc-current-nick)) t))
5894
5895;; This function happens to return nil in channel buffers previously
5896;; parted or those from which a user had been kicked. While this
5897;; "works" for detecting whether a channel is currently subscribed to,
5898;; new code should consider using
5899;;
5900;; (erc-get-channel-user (erc-current-nick))
5901;;
5902;; instead. For retrieving a target regardless of subscription or
5903;; connection status, use replacements based on `erc--target'.
5904;; (Coming soon.)
5905;;
5906;; TODO deprecate this
5871(defun erc-default-target () 5907(defun erc-default-target ()
5872 "Return the current default target (as a character string) or nil if none." 5908 "Return the current default target (as a character string) or nil if none."
5873 (let ((tgt (car erc-default-recipients))) 5909 (let ((tgt (car erc-default-recipients)))
@@ -5878,12 +5914,14 @@ See also `erc-downcase'."
5878 5914
5879(defun erc-add-default-channel (channel) 5915(defun erc-add-default-channel (channel)
5880 "Add CHANNEL to the default channel list." 5916 "Add CHANNEL to the default channel list."
5917 (declare (obsolete "use `erc-cmd-JOIN' or similar instead" "29.1"))
5881 (let ((chl (downcase channel))) 5918 (let ((chl (downcase channel)))
5882 (setq erc-default-recipients 5919 (setq erc-default-recipients
5883 (cons chl erc-default-recipients)))) 5920 (cons chl erc-default-recipients))))
5884 5921
5885(defun erc-delete-default-channel (channel &optional buffer) 5922(defun erc-delete-default-channel (channel &optional buffer)
5886 "Delete CHANNEL from the default channel list." 5923 "Delete CHANNEL from the default channel list."
5924 (declare (obsolete "use `erc-cmd-PART' or similar instead" "29.1"))
5887 (with-current-buffer (if (and buffer 5925 (with-current-buffer (if (and buffer
5888 (bufferp buffer)) 5926 (bufferp buffer))
5889 buffer 5927 buffer
@@ -5895,6 +5933,7 @@ See also `erc-downcase'."
5895 "Add QUERY'd NICKNAME to the default channel list. 5933 "Add QUERY'd NICKNAME to the default channel list.
5896 5934
5897The previous default target of QUERY type gets removed." 5935The previous default target of QUERY type gets removed."
5936 (declare (obsolete "use `erc-cmd-QUERY' or similar instead" "29.1"))
5898 (let ((d1 (car erc-default-recipients)) 5937 (let ((d1 (car erc-default-recipients))
5899 (d2 (cdr erc-default-recipients)) 5938 (d2 (cdr erc-default-recipients))
5900 (qt (cons 'QUERY (downcase nickname)))) 5939 (qt (cons 'QUERY (downcase nickname))))
@@ -5905,7 +5944,7 @@ The previous default target of QUERY type gets removed."
5905 5944
5906(defun erc-delete-query () 5945(defun erc-delete-query ()
5907 "Delete the topmost target if it is a QUERY." 5946 "Delete the topmost target if it is a QUERY."
5908 5947 (declare (obsolete "use one query buffer per target instead" "29.1"))
5909 (let ((d1 (car erc-default-recipients)) 5948 (let ((d1 (car erc-default-recipients))
5910 (d2 (cdr erc-default-recipients))) 5949 (d2 (cdr erc-default-recipients)))
5911 (if (and (listp d1) 5950 (if (and (listp d1)