aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2023-04-10 17:58:05 -0700
committerF. Jason Park2023-05-05 17:18:01 -0700
commit5de90fa9611ec796a0c459dbcd32a246ff76543c (patch)
tree7045c7aed005bc0c2a0ac2e7bf0c71dbd4f335fe
parent8654cea5843aa2fa2074f317d338451eadae092f (diff)
downloademacs-5de90fa9611ec796a0c459dbcd32a246ff76543c.tar.gz
emacs-5de90fa9611ec796a0c459dbcd32a246ff76543c.zip
Extend erc-interactive-display to cover /JOINs
* lisp/erc/erc.el (erc-display): Mention that buffer-related display options live in the customization group `erc-buffers'. (erc-buffer-display, erc-join-buffer): Swap alias and aliased so that the favored name, `erc-buffer-display', appears in the definition and in the Customize menu. Also note related buffer-display options in the doc string. (erc-query-display, erc-interactive-display): Make the former an alias of the latter, new in ERC 5.6, because their roles were functionally redundant and thus confusing. Inherit the default value from `erc-query-display' because users are more familiar with the pop-up window behavior than a single-window replacement. (erc-reconnect-display): Use preferred name for cross-referencing fallback option `erc-buffer-display' in doc string, and explain how /reconnect handling differs. (erc--setup-buffer-hook): Add new internal hook for modules that operate on windows and frames, such as erc-speedbar and erc-status-sidebar. (erc-open): Run `erc--setup-buffer-hook' after `erc-setup-buffer' so hook members know their code isn't tied to `erc-setup-buffer' itself, which may be used in other contexts, but rather to a new ERC buffer on which some display-related action has just been performed. (erc--called-as-input-p): New variable for "slash" commands, like `erc-cmd-FOO', to detect whether they're being called "interactively" as a result of input given at ERC's prompt. (erc-process-input-line): Bind `erc--called-as-input-p' when running slash commands. (erc-cmd-JOIN): When called interactively, schedule a callback to wrap the response handler and control how new buffers are thus displayed. (erc-cmd-QUERY): Use preferred alias for `erc-query-display'. * test/lisp/erc/erc-scenarios-base-buffer-display.el: (erc-scenarios-base-buffer-display--interactive-default): New test. * test/lisp/erc/erc-tests.el (erc-process-input-line, erc-select-read-args, erc-tls, erc--interactive): Change expected default value of `erc-interactive-display' from `buffer' to `window'. (Bug#62833)
-rw-r--r--etc/ERC-NEWS17
-rw-r--r--lisp/erc/erc.el88
-rw-r--r--test/lisp/erc/erc-scenarios-base-buffer-display.el37
-rw-r--r--test/lisp/erc/erc-tests.el13
4 files changed, 105 insertions, 50 deletions
diff --git a/etc/ERC-NEWS b/etc/ERC-NEWS
index 6897993c628..57dce501760 100644
--- a/etc/ERC-NEWS
+++ b/etc/ERC-NEWS
@@ -37,15 +37,18 @@ decade overdue, this is no longer the case. Other UX improvements in
37this area aim to make the process of connecting interactively slightly 37this area aim to make the process of connecting interactively slightly
38more streamlined and less repetitive, even for veteran users. 38more streamlined and less repetitive, even for veteran users.
39 39
40** New buffer-display option 'erc-interactive-display'. 40** Revised buffer-display handling for interactive commands.
41A point of friction for new users and one only just introduced with 41A point of friction for new users and one only just introduced with
42ERC 5.5 has been the lack of visual feedback when first connecting via 42ERC 5.5 has been the lack of visual feedback when first connecting via
43M-x erc. As explained below in the news for 5.5, the discovery of a 43M-x erc or when issuing a "/JOIN" command at the prompt. As explained
44security issue led to new ERC buffers being "buried" on creation. On 44below, in the news for 5.5, the discovery of a security issue led to
45further reflection, this was judged to have been an overcorrection in 45most new ERC buffers being "buried" on creation. On further
46the case of interactive invocations, hence the new option 46reflection, this was judged to have been an overcorrection in the case
47'erc-interactive-display', which is set to 'buffer' (i.e., "take me 47of interactive invocations, hence the borrowing of an old option,
48there") by default. 48'erc-query-display', and the bestowing of a new alias,
49'erc-interactive-display', which better describes its expanded role as
50a more general buffer-display knob for interactive commands ("/QUERY"
51still among them).
49 52
50Accompanying this addition are "display"-suffixed aliases for related 53Accompanying this addition are "display"-suffixed aliases for related
51options 'erc-join-buffer' and 'erc-auto-query', which users have 54options 'erc-join-buffer' and 'erc-auto-query', which users have
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 22b92a0d31b..13f6da2d5be 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -98,7 +98,9 @@
98 :group 'erc) 98 :group 'erc)
99 99
100(defgroup erc-display nil 100(defgroup erc-display nil
101 "Settings for how various things are displayed." 101 "Settings controlling how various things are displayed.
102See the customization group `erc-buffers' for display options
103concerning buffers."
102 :group 'erc) 104 :group 'erc)
103 105
104(defgroup erc-mode-line-and-header nil 106(defgroup erc-mode-line-and-header nil
@@ -1507,9 +1509,9 @@ Defaults to the server buffer."
1507 "IRC port to use for encrypted connections if it cannot be \ 1509 "IRC port to use for encrypted connections if it cannot be \
1508detected otherwise.") 1510detected otherwise.")
1509 1511
1510(defvaralias 'erc-buffer-display 'erc-join-buffer) 1512(defvaralias 'erc-join-buffer 'erc-buffer-display)
1511(defcustom erc-join-buffer 'bury 1513(defcustom erc-buffer-display 'bury
1512 "Determines how to display a newly created IRC buffer. 1514 "How to display a newly created ERC buffer.
1513 1515
1514The available choices are: 1516The available choices are:
1515 1517
@@ -1518,7 +1520,9 @@ The available choices are:
1518 `frame' - in another frame, 1520 `frame' - in another frame,
1519 `bury' - bury it in a new buffer, 1521 `bury' - bury it in a new buffer,
1520 `buffer' - in place of the current buffer, 1522 `buffer' - in place of the current buffer,
1521 any other value - in place of the current buffer." 1523
1524See related options `erc-interactive-display',
1525`erc-reconnect-display', and `erc-receive-query-display'."
1522 :package-version '(ERC . "5.5") 1526 :package-version '(ERC . "5.5")
1523 :group 'erc-buffers 1527 :group 'erc-buffers
1524 :type '(choice (const :tag "Split window and select" window) 1528 :type '(choice (const :tag "Split window and select" window)
@@ -1528,13 +1532,17 @@ The available choices are:
1528 (const :tag "Use current buffer" buffer) 1532 (const :tag "Use current buffer" buffer)
1529 (const :tag "Use current buffer" t))) 1533 (const :tag "Use current buffer" t)))
1530 1534
1531(defcustom erc-interactive-display 'buffer 1535(defvaralias 'erc-query-display 'erc-interactive-display)
1532 "How and whether to display server buffers for M-x erc. 1536(defcustom erc-interactive-display 'window
1533See `erc-buffer-display' and friends for a description of 1537 "How to display buffers as a result of user interaction.
1534possible values." 1538This affects commands like /QUERY and /JOIN when issued
1539interactively at the prompt. It does not apply when calling a
1540handler for such a command, like `erc-cmd-JOIN', from lisp code.
1541See `erc-buffer-display' for a full description of available
1542values."
1535 :package-version '(ERC . "5.6") ; FIXME sync on release 1543 :package-version '(ERC . "5.6") ; FIXME sync on release
1536 :group 'erc-buffers 1544 :group 'erc-buffers
1537 :type '(choice (const :tag "Use value of `erc-join-buffer'" nil) 1545 :type '(choice (const :tag "Use value of `erc-buffer-display'" nil)
1538 (const :tag "Split window and select" window) 1546 (const :tag "Split window and select" window)
1539 (const :tag "Split window, don't select" window-noselect) 1547 (const :tag "Split window, don't select" window-noselect)
1540 (const :tag "New frame" frame) 1548 (const :tag "New frame" frame)
@@ -1542,15 +1550,14 @@ possible values."
1542 (const :tag "Use current buffer" buffer))) 1550 (const :tag "Use current buffer" buffer)))
1543 1551
1544(defcustom erc-reconnect-display nil 1552(defcustom erc-reconnect-display nil
1545 "How (and whether) to display a channel buffer upon reconnecting. 1553 "How and whether to display a channel buffer when auto-reconnecting.
1546 1554This only affects automatic reconnections and is ignored, like
1547This only affects automatic reconnections and is ignored when 1555all other buffer-display options, when issuing a /RECONNECT or
1548issuing a /reconnect command or reinvoking `erc-tls' with the 1556successfully reinvoking `erc-tls' with similar arguments. See
1549same args (assuming success, of course). See `erc-join-buffer' 1557`erc-buffer-display' for a description of possible values."
1550for a description of possible values."
1551 :package-version '(ERC . "5.5") 1558 :package-version '(ERC . "5.5")
1552 :group 'erc-buffers 1559 :group 'erc-buffers
1553 :type '(choice (const :tag "Use value of `erc-join-buffer'" nil) 1560 :type '(choice (const :tag "Use value of `erc-buffer-display'" nil)
1554 (const :tag "Split window and select" window) 1561 (const :tag "Split window and select" window)
1555 (const :tag "Split window, don't select" window-noselect) 1562 (const :tag "Split window, don't select" window-noselect)
1556 (const :tag "New frame" frame) 1563 (const :tag "New frame" frame)
@@ -2044,6 +2051,9 @@ to display-buffer machinery."
2044 (display-buffer-use-some-frame buffer 2051 (display-buffer-use-some-frame buffer
2045 `((frame-predicate . ,ercp) ,@alist))))) 2052 `((frame-predicate . ,ercp) ,@alist)))))
2046 2053
2054(defvar erc--setup-buffer-hook nil
2055 "Internal hook for module setup involving windows and frames.")
2056
2047(defun erc-setup-buffer (buffer) 2057(defun erc-setup-buffer (buffer)
2048 "Consults `erc-join-buffer' to find out how to display `BUFFER'." 2058 "Consults `erc-join-buffer' to find out how to display `BUFFER'."
2049 (pcase (if (zerop (erc-with-server-buffer 2059 (pcase (if (zerop (erc-with-server-buffer
@@ -2251,7 +2261,8 @@ Returns the buffer for the given server or channel."
2251 ;; we can't log to debug buffer, it may not exist yet 2261 ;; we can't log to debug buffer, it may not exist yet
2252 (message "erc: old buffer %s, switching to %s" 2262 (message "erc: old buffer %s, switching to %s"
2253 old-buffer buffer)) 2263 old-buffer buffer))
2254 (erc-setup-buffer buffer)) 2264 (erc-setup-buffer buffer)
2265 (run-hooks 'erc--setup-buffer-hook))
2255 2266
2256 buffer)) 2267 buffer))
2257 2268
@@ -3057,6 +3068,10 @@ present."
3057 (let ((prop-val (erc-get-parsed-vector position))) 3068 (let ((prop-val (erc-get-parsed-vector position)))
3058 (and prop-val (member (erc-response.command prop-val) list)))) 3069 (and prop-val (member (erc-response.command prop-val) list))))
3059 3070
3071(defvar erc--called-as-input-p nil
3072 "Non-nil when a user types a \"/slash\" command.
3073Remains bound until `erc-cmd-SLASH' returns.")
3074
3060(defvar-local erc-send-input-line-function 'erc-send-input-line 3075(defvar-local erc-send-input-line-function 'erc-send-input-line
3061 "Function for sending lines lacking a leading user command. 3076 "Function for sending lines lacking a leading user command.
3062When a line typed into a buffer contains an explicit command, like /msg, 3077When a line typed into a buffer contains an explicit command, like /msg,
@@ -3110,7 +3125,8 @@ this function from interpreting the line as a command."
3110 (if (and command-list 3125 (if (and command-list
3111 (not no-command)) 3126 (not no-command))
3112 (let* ((cmd (nth 0 command-list)) 3127 (let* ((cmd (nth 0 command-list))
3113 (args (nth 1 command-list))) 3128 (args (nth 1 command-list))
3129 (erc--called-as-input-p t))
3114 (condition-case nil 3130 (condition-case nil
3115 (if (listp args) 3131 (if (listp args)
3116 (apply cmd args) 3132 (apply cmd args)
@@ -3584,6 +3600,21 @@ were most recently invited. See also `invitation'."
3584 (erc-get-channel-user (erc-current-nick))))) 3600 (erc-get-channel-user (erc-current-nick)))))
3585 (switch-to-buffer existing) 3601 (switch-to-buffer existing)
3586 (setq erc--server-last-reconnect-count 0) 3602 (setq erc--server-last-reconnect-count 0)
3603 (when-let* ; bind `erc-join-buffer' when /JOIN issued
3604 ((erc--called-as-input-p)
3605 (fn (lambda (proc parsed)
3606 (when-let* ; `fn' wrapper already removed from hook
3607 (((equal (car (erc-response.command-args parsed))
3608 channel))
3609 (sn (erc-extract-nick (erc-response.sender parsed)))
3610 ((erc-nick-equal-p sn (erc-current-nick)))
3611 (erc-join-buffer (or erc-interactive-display
3612 erc-join-buffer)))
3613 (run-hook-with-args-until-success
3614 'erc-server-JOIN-functions proc parsed)
3615 t))))
3616 (erc-with-server-buffer
3617 (erc-once-with-server-event "JOIN" fn)))
3587 (erc-server-join-channel nil chnl key)))) 3618 (erc-server-join-channel nil chnl key))))
3588 t) 3619 t)
3589 3620
@@ -3947,27 +3978,10 @@ just as you provided it. Use this command with care!"
3947 (t nil))) 3978 (t nil)))
3948(put 'erc-cmd-QUOTE 'do-not-parse-args t) 3979(put 'erc-cmd-QUOTE 'do-not-parse-args t)
3949 3980
3950(defcustom erc-query-display 'window
3951 "How to display query buffers when using the /QUERY command to talk to someone.
3952
3953The default behavior is to display the message in a new window
3954and bring it to the front. See the documentation for
3955`erc-join-buffer' for a description of the available choices.
3956
3957See also `erc-auto-query' to decide how private messages from
3958other people should be displayed."
3959 :group 'erc-query
3960 :type '(choice (const :tag "Split window and select" window)
3961 (const :tag "Split window, don't select" window-noselect)
3962 (const :tag "New frame" frame)
3963 (const :tag "Bury in new buffer" bury)
3964 (const :tag "Use current buffer" buffer)
3965 (const :tag "Use current buffer" t)))
3966
3967(defun erc-cmd-QUERY (&optional user) 3981(defun erc-cmd-QUERY (&optional user)
3968 "Open a query with USER. 3982 "Open a query with USER.
3969How the query is displayed (in a new window, frame, etc.) depends 3983How the query is displayed (in a new window, frame, etc.) depends
3970on the value of `erc-query-display'." 3984on the value of `erc-interactive-display'."
3971 ;; FIXME: The doc string used to say at the end: 3985 ;; FIXME: The doc string used to say at the end:
3972 ;; "If USER is omitted, close the current query buffer if one exists 3986 ;; "If USER is omitted, close the current query buffer if one exists
3973 ;; - except this is broken now ;-)" 3987 ;; - except this is broken now ;-)"
diff --git a/test/lisp/erc/erc-scenarios-base-buffer-display.el b/test/lisp/erc/erc-scenarios-base-buffer-display.el
index d511c8ff738..3ed7a83653e 100644
--- a/test/lisp/erc/erc-scenarios-base-buffer-display.el
+++ b/test/lisp/erc/erc-scenarios-base-buffer-display.el
@@ -118,4 +118,41 @@
118 118
119 (should (eq (window-buffer) (messages-buffer)))))) 119 (should (eq (window-buffer) (messages-buffer))))))
120 120
121
122;; This shows that the option `erc-interactive-display' overrides
123;; `erc-join-buffer' during cold opens and interactive /JOINs.
124
125(ert-deftest erc-scenarios-base-buffer-display--interactive-default ()
126 :tags '(:expensive-test)
127 (should (eq erc-join-buffer 'bury))
128 (should (eq erc-interactive-display 'window))
129
130 (erc-scenarios-common-with-cleanup
131 ((erc-scenarios-common-dialog "join/legacy")
132 (dumb-server (erc-d-run "localhost" t 'foonet))
133 (port (process-contact dumb-server :service))
134 (url (format "tester:changeme@127.0.0.1:%d\r\r" port))
135 (expect (erc-d-t-make-expecter))
136 (erc-server-flood-penalty 0.1)
137 (erc-server-auto-reconnect t)
138 (erc-user-full-name "tester"))
139
140 (ert-info ("Connect to foonet")
141 (with-current-buffer (let (inhibit-interaction)
142 (ert-simulate-keys url
143 (call-interactively #'erc)))
144 (should (string= (buffer-name) (format "127.0.0.1:%d" port)))
145
146 (erc-d-t-wait-for 10 "Server buffer shown"
147 (eq (window-buffer) (current-buffer)))
148 (funcall expect 10 "debug mode")
149 (erc-scenarios-common-say "/JOIN #chan")))
150
151 (ert-info ("Wait for output in #chan")
152 (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan"))
153 (funcall expect 10 "welcome")
154 (erc-d-t-ensure-for 3 "Channel #chan shown"
155 (eq (window-buffer) (current-buffer)))
156 (funcall expect 10 "be prosperous")))))
157
121;;; erc-scenarios-base-buffer-display.el ends here 158;;; erc-scenarios-base-buffer-display.el ends here
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 29bda7e742d..88b9babf206 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1292,6 +1292,7 @@
1292 (cl-letf (((symbol-function 'erc-cmd-MSG) 1292 (cl-letf (((symbol-function 'erc-cmd-MSG)
1293 (lambda (line) 1293 (lambda (line)
1294 (push line calls) 1294 (push line calls)
1295 (should erc--called-as-input-p)
1295 (funcall orig-erc-cmd-MSG line))) 1296 (funcall orig-erc-cmd-MSG line)))
1296 ((symbol-function 'erc-server-buffer) 1297 ((symbol-function 'erc-server-buffer)
1297 (lambda () (current-buffer))) 1298 (lambda () (current-buffer)))
@@ -1469,7 +1470,7 @@
1469 :nick (user-login-name) 1470 :nick (user-login-name)
1470 '&interactive-env 1471 '&interactive-env
1471 '((erc-server-connect-function . erc-open-tls-stream) 1472 '((erc-server-connect-function . erc-open-tls-stream)
1472 (erc-join-buffer . buffer)))))) 1473 (erc-join-buffer . window))))))
1473 1474
1474 (ert-info ("Switches to TLS when port matches default TLS port") 1475 (ert-info ("Switches to TLS when port matches default TLS port")
1475 (should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r" 1476 (should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r"
@@ -1479,7 +1480,7 @@
1479 :nick (user-login-name) 1480 :nick (user-login-name)
1480 '&interactive-env 1481 '&interactive-env
1481 '((erc-server-connect-function . erc-open-tls-stream) 1482 '((erc-server-connect-function . erc-open-tls-stream)
1482 (erc-join-buffer . buffer)))))) 1483 (erc-join-buffer . window))))))
1483 1484
1484 (ert-info ("Switches to TLS when URL is ircs://") 1485 (ert-info ("Switches to TLS when URL is ircs://")
1485 (should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r" 1486 (should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r"
@@ -1489,7 +1490,7 @@
1489 :nick (user-login-name) 1490 :nick (user-login-name)
1490 '&interactive-env 1491 '&interactive-env
1491 '((erc-server-connect-function . erc-open-tls-stream) 1492 '((erc-server-connect-function . erc-open-tls-stream)
1492 (erc-join-buffer . buffer)))))) 1493 (erc-join-buffer . window))))))
1493 1494
1494 (setq-local erc-interactive-display nil) ; cheat to save space 1495 (setq-local erc-interactive-display nil) ; cheat to save space
1495 1496
@@ -1625,7 +1626,7 @@
1625 '("localhost" 6667 "nick" "unknown" t "sesame" 1626 '("localhost" 6667 "nick" "unknown" t "sesame"
1626 nil nil nil nil "user" nil))) 1627 nil nil nil nil "user" nil)))
1627 (should (equal (pop env) 1628 (should (equal (pop env)
1628 '((erc-join-buffer buffer) 1629 '((erc-join-buffer window)
1629 (erc-server-connect-function erc-open-tls-stream))))) 1630 (erc-server-connect-function erc-open-tls-stream)))))
1630 1631
1631 (ert-info ("Custom connect function") 1632 (ert-info ("Custom connect function")
@@ -1686,7 +1687,7 @@
1686 '("irc.libera.chat" 6697 "tester" "unknown" t nil 1687 '("irc.libera.chat" 6697 "tester" "unknown" t nil
1687 nil nil nil nil "user" nil))) 1688 nil nil nil nil "user" nil)))
1688 (should (equal (pop env) 1689 (should (equal (pop env)
1689 '((erc-join-buffer buffer) (erc-server-connect-function 1690 '((erc-join-buffer window) (erc-server-connect-function
1690 erc-open-tls-stream))))) 1691 erc-open-tls-stream)))))
1691 1692
1692 (ert-info ("Nick supplied, decline TLS upgrade") 1693 (ert-info ("Nick supplied, decline TLS upgrade")
@@ -1696,7 +1697,7 @@
1696 '("irc.libera.chat" 6667 "dummy" "unknown" t nil 1697 '("irc.libera.chat" 6667 "dummy" "unknown" t nil
1697 nil nil nil nil "user" nil))) 1698 nil nil nil nil "user" nil)))
1698 (should (equal (pop env) 1699 (should (equal (pop env)
1699 '((erc-join-buffer buffer) 1700 '((erc-join-buffer window)
1700 (erc-server-connect-function 1701 (erc-server-connect-function
1701 erc-open-network-stream)))))))) 1702 erc-open-network-stream))))))))
1702 1703