]> git.eshelyaron.com Git - emacs.git/commitdiff
Add display option for interactive ERC invocations
authorF. Jason Park <jp@neverwas.me>
Thu, 29 Dec 2022 14:43:19 +0000 (06:43 -0800)
committerF. Jason Park <jp@neverwas.me>
Sat, 8 Apr 2023 21:23:51 +0000 (14:23 -0700)
* lisp/erc/erc.el (erc-buffer-display, erc-receive-query-display):
Add aliases for `erc-join-buffer' and `erc-auto-query'.
(erc-interactive-display): Add new option to control display of server
buffers during interactive entry-point invocations.
(erc-select-read-args): Pass `erc-interactive-display' to entry
points.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Expect
buffer-display values from `erc-interactive-display'.
(erc-tls, erc--interactive): Also check `erc-join-buffer' in
environment when `erc-open' called.  (Bug#60428.)

lisp/erc/erc.el
test/lisp/erc/erc-tests.el

index e1abfee9ba363c2c9aa3c4ab60e567703b4e9bd7..4c856f49c04490553b67811e80b2780e6fe59f5f 100644 (file)
@@ -1501,6 +1501,7 @@ Defaults to the server buffer."
   "IRC port to use for encrypted connections if it cannot be \
 detected otherwise.")
 
+(defvaralias 'erc-buffer-display 'erc-join-buffer)
 (defcustom erc-join-buffer 'bury
   "Determines how to display a newly created IRC buffer.
 
@@ -1521,6 +1522,19 @@ The available choices are:
                  (const :tag "Use current buffer" buffer)
                  (const :tag "Use current buffer" t)))
 
+(defcustom erc-interactive-display 'buffer
+  "How and whether to display server buffers for M-x erc.
+See `erc-buffer-display' and friends for a description of
+possible values."
+  :package-version '(ERC . "5.6") ; FIXME sync on release
+  :group 'erc-buffers
+  :type '(choice (const :tag "Use value of `erc-join-buffer'" nil)
+                 (const :tag "Split window and select" window)
+                 (const :tag "Split window, don't select" window-noselect)
+                 (const :tag "New frame" frame)
+                 (const :tag "Bury new and don't display existing" bury)
+                 (const :tag "Use current buffer" buffer)))
+
 (defcustom erc-reconnect-display nil
   "How (and whether) to display a channel buffer upon reconnecting.
 
@@ -2278,6 +2292,8 @@ parameters SERVER and NICK."
                                (setq port erc-default-port-tls)))
                       #'erc-open-tls-stream))
          env)
+    (when erc-interactive-display
+      (push `(erc-join-buffer . ,erc-interactive-display) env))
     (when opener
       (push `(erc-server-connect-function . ,opener) env))
     (when (and passwd (string= "" passwd))
@@ -4610,6 +4626,7 @@ To change how this query window is displayed, use `let' to bind
   (with-current-buffer server-buffer
     (erc--open-target target)))
 
+(defvaralias 'erc-receive-query-display 'erc-auto-query)
 (defcustom erc-auto-query 'window-noselect
   "If non-nil, create a query buffer each time you receive a private message.
 If the buffer doesn't already exist, it is created.
index c5905ab4f677afe36fedc4790305433353bc58a8..beb4b4cef7659f62df90847f350e8307f43565d9 100644 (file)
                    (list :server "irc.libera.chat"
                          :port 6697
                          :nick (user-login-name)
-                         '&interactive-env '((erc-server-connect-function
-                                              . erc-open-tls-stream))))))
+                         '&interactive-env
+                         '((erc-server-connect-function . erc-open-tls-stream)
+                           (erc-join-buffer . buffer))))))
 
   (ert-info ("Switches to TLS when port matches default TLS port")
     (should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r"
                    (list :server "irc.gnu.org"
                          :port 6697
                          :nick (user-login-name)
-                         '&interactive-env '((erc-server-connect-function
-                                              . erc-open-tls-stream))))))
+                         '&interactive-env
+                         '((erc-server-connect-function . erc-open-tls-stream)
+                           (erc-join-buffer . buffer))))))
 
   (ert-info ("Switches to TLS when URL is ircs://")
     (should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r"
                    (list :server "irc.gnu.org"
                          :port 6697
                          :nick (user-login-name)
-                         '&interactive-env '((erc-server-connect-function
-                                              . erc-open-tls-stream))))))
+                         '&interactive-env
+                         '((erc-server-connect-function . erc-open-tls-stream)
+                           (erc-join-buffer . buffer))))))
+
+  (setq-local erc-interactive-display nil) ; cheat to save space
 
   (ert-info ("Opt out of non-TLS warning manually")
     (should (equal (ert-simulate-keys "\r\r\r\rn\r"
                (lambda (&optional _) "tester"))
               ((symbol-function 'erc-open)
                (lambda (&rest r)
-                 (push `((erc-server-connect-function
+                 (push `((erc-join-buffer ,erc-join-buffer)
+                         (erc-server-connect-function
                           ,erc-server-connect-function))
                        env)
                  (push r calls))))
                        '("irc.libera.chat" 6697 "tester" "unknown" t
                          nil nil nil nil nil "user" nil)))
         (should (equal (pop env)
-                       '((erc-server-connect-function erc-open-tls-stream)))))
+                       '((erc-join-buffer bury)
+                         (erc-server-connect-function erc-open-tls-stream)))))
 
       (ert-info ("Full")
         (erc-tls :server "irc.gnu.org"
                        '("irc.gnu.org" 7000 "bob" "Bob's Name" t
                          "bob:changeme" nil nil nil t "bobo" GNU.org)))
         (should (equal (pop env)
-                       '((erc-server-connect-function erc-open-tls-stream)))))
+                       '((erc-join-buffer bury)
+                         (erc-server-connect-function erc-open-tls-stream)))))
 
       ;; Values are often nil when called by lisp code, which leads to
       ;; null params.  This is why `erc-open' recomputes almost
                        '(nil 7000 nil "Bob's Name" t
                              "bob:changeme" nil nil nil nil "bobo" nil)))
         (should (equal (pop env)
-                       '((erc-server-connect-function erc-open-tls-stream)))))
+                       '((erc-join-buffer bury)
+                         (erc-server-connect-function erc-open-tls-stream)))))
 
       (ert-info ("Interactive")
         (ert-simulate-keys "nick:sesame@localhost:6667\r\r"
                        '("localhost" 6667 "nick" "unknown" t "sesame"
                          nil nil nil nil "user" nil)))
         (should (equal (pop env)
-                       '((erc-server-connect-function
-                          erc-open-tls-stream)))))
+                       '((erc-join-buffer buffer)
+                         (erc-server-connect-function erc-open-tls-stream)))))
 
       (ert-info ("Custom connect function")
         (let ((erc-server-connect-function 'my-connect-func))
                          '("irc.libera.chat" 6697 "tester" "unknown" t
                            nil nil nil nil nil "user" nil)))
           (should (equal (pop env)
-                         '((erc-server-connect-function my-connect-func))))))
+                         '((erc-join-buffer bury)
+                           (erc-server-connect-function my-connect-func))))))
 
       (ert-info ("Advised default function overlooked") ; intentional
         (advice-add 'erc-server-connect-function :around #'ignore
                        '("irc.libera.chat" 6697 "tester" "unknown" t
                          nil nil nil nil nil "user" nil)))
         (should (equal (pop env)
-                       '((erc-server-connect-function erc-open-tls-stream))))
+                       '((erc-join-buffer bury)
+                         (erc-server-connect-function erc-open-tls-stream))))
         (advice-remove 'erc-server-connect-function 'erc-tests--erc-tls))
 
       (ert-info ("Advised non-default function honored")
             (should (equal (pop calls)
                            '("irc.libera.chat" 6697 "tester" "unknown" t
                              nil nil nil nil nil "user" nil)))
-            (should (equal (pop env) `((erc-server-connect-function ,f))))
+            (should (equal (pop env) `((erc-join-buffer bury)
+                                       (erc-server-connect-function ,f))))
             (advice-remove 'erc-server-connect-function
                            'erc-tests--erc-tls)))))))
 
                (lambda (&optional _) "tester"))
               ((symbol-function 'erc-open)
                (lambda (&rest r)
-                 (push `((erc-server-connect-function
+                 (push `((erc-join-buffer ,erc-join-buffer)
+                         (erc-server-connect-function
                           ,erc-server-connect-function))
                        env)
                  (push r calls))))
                        '("irc.libera.chat" 6697 "tester" "unknown" t nil
                          nil nil nil nil "user" nil)))
         (should (equal (pop env)
-                       '((erc-server-connect-function erc-open-tls-stream)))))
+                       '((erc-join-buffer buffer) (erc-server-connect-function
+                                                   erc-open-tls-stream)))))
 
       (ert-info ("Nick supplied, decline TLS upgrade")
         (ert-simulate-keys "\r\rdummy\r\rn\r"
                        '("irc.libera.chat" 6667 "dummy" "unknown" t nil
                          nil nil nil nil "user" nil)))
         (should (equal (pop env)
-                       '(
+                       '((erc-join-buffer buffer)
                          (erc-server-connect-function
                           erc-open-network-stream))))))))