aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
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 /lisp
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)
Diffstat (limited to 'lisp')
-rw-r--r--lisp/erc/erc.el88
1 files changed, 51 insertions, 37 deletions
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 ;-)"