From 448686bf96105833cd3e3ee319118c1672d95ca0 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 1 Jan 2023 17:36:36 -0800 Subject: [PATCH 0/4] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (4): Fix default-port regression in erc-select-read-args [5.6] Be smarter about switching to TLS from M-x erc [5.6] Add display option for interactive ERC invocations [5.6] Optionally prompt for more ERC entry-point params doc/misc/erc.texi | 2 +- lisp/erc/erc.el | 87 +++++++++++++++++++++++++++++--------- test/lisp/erc/erc-tests.el | 66 +++++++++++++++++++++-------- 3 files changed, 118 insertions(+), 37 deletions(-) Interdiff: diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 2fcdb513b5d..7f2dd89342b 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1486,7 +1486,8 @@ erc-interactive-display possible values." :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA :group 'erc-buffers - :type '(choice (const :tag "Split window and select" window) + :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) @@ -2180,7 +2181,7 @@ erc-select-read-args With prefix arg, also prompt for user and full name." (require 'url-parse) (let* ((input (let ((d (erc-compute-server))) - (read-string (format "Server (default is %S): " d) + (read-string (format "Server or URL (default is %S): " d) nil 'erc-server-history-list d))) ;; For legacy reasons, also accept a URL without a scheme. (url (url-generic-parse-url (erc--ensure-url input))) @@ -2199,34 +2200,33 @@ erc-select-read-args (read-string (format "Nickname (default is %S): " d) nil 'erc-nick-history-list d)))) (user (and current-prefix-arg - (let ((d (or (url-user url) (erc-compute-user)))) + (let ((d (erc-compute-user (url-user url)))) (read-string (format "User (default is %S): " d) nil nil d)))) (full (and current-prefix-arg - (let ((d (or (url-user url) (erc-compute-full-name)))) + (let ((d (erc-compute-full-name (url-user url)))) (read-string (format "Full name (default is %S): " d) nil nil d)))) - (passwd (or (url-password url) - (let* - ((p (with-suppressed-warnings - ((obsolete erc-password)) - erc-password)) - (m (if p - (format "Server password (default is %S): " p) - "Server password (optional): "))) - (if erc-prompt-for-password (read-passwd m nil p) p)))) - (opener erc-server-connect-function)) + (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password)) + (or (url-password url) erc-password))) + (m (if p + (format "Server password (default is %S): " p) + "Server password (optional): "))) + (if erc-prompt-for-password (read-passwd m nil p) p))) + (opener (and (or sp (eql port erc-default-port-tls) + (and (equal server erc-default-server) + (not (string-prefix-p "irc://" input)) + (eql port erc-default-port) + (y-or-n-p "Connect using TLS instead? ") + (setq port erc-default-port-tls))) + #'erc-open-tls-stream))) (when (and passwd (string= "" passwd)) (setq passwd nil)) - (when (and (equal server erc-default-server) - (not (string-prefix-p "irc://" input)) - (or (not (eql port erc-default-port)) - (and (y-or-n-p "Connect using TLS instead? ") - (setq port erc-default-port-tls)))) - (setq opener #'erc-open-tls-stream)) `( :server ,server :port ,port :nick ,nick ,@(and user `(:user ,user)) ,@(and passwd `(:password ,passwd)) ,@(and full `(:full-name ,full)) - buffer-display ,erc-interactive-display connect-function ,opener))) + ,@(and erc-interactive-display + `(buffer-display ,erc-interactive-display)) + ,@(and opener `(connect-function ,opener))))) ;;;###autoload @@ -2238,8 +2238,7 @@ erc (full-name (erc-compute-full-name)) id ;; For interactive use - ((buffer-display erc-buffer-display) - erc-buffer-display) + ((buffer-display erc-join-buffer) erc-join-buffer) ((connect-function erc-server-connect-function) erc-server-connect-function)) "ERC is a powerful, modular, and extensible IRC client. @@ -2284,10 +2283,12 @@ erc-tls client-certificate id ;; For interactive use - ((buffer-display erc-buffer-display) - erc-buffer-display) + ((buffer-display erc-join-buffer) erc-join-buffer) ((connect-function erc-server-connect-function) - #'erc-open-tls-stream)) + (if (eq erc-server-connect-function + #'erc-open-network-stream) + #'erc-open-tls-stream + erc-server-connect-function))) "ERC is a powerful, modular, and extensible IRC client. This function is the main entry point for ERC over TLS. @@ -2334,12 +2335,7 @@ erc-tls interactively. \(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)" - (interactive (let ((erc-server-connect-function - (if (eq erc-server-connect-function - #'erc-open-network-stream) - #'erc-open-tls-stream - erc-server-connect-function)) - (erc-port (or erc-port erc-default-port-tls))) + (interactive (let ((erc-default-port erc-default-port-tls)) (erc-select-read-args))) (progn (erc-open server port nick full-name t password diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 9d09df44883..d05b0efe2ed 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1001,7 +1001,7 @@ erc--server-connect-dumb-ipv6-regexp (ert-deftest erc-select-read-args () - (ert-info ("Doesn't default to TLS") + (ert-info ("Prompts for switch to TLS by default") (should (equal (ert-simulate-keys "\r\r\r\ry\r" (erc-select-read-args)) (list :server "irc.libera.chat" @@ -1010,44 +1010,58 @@ erc-select-read-args 'buffer-display 'buffer 'connect-function #'erc-open-tls-stream)))) + (ert-info ("Switches to TLS when port matches default TLS port") + (should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r" + (erc-select-read-args)) + (list :server "irc.gnu.org" + :port 6697 + :nick (user-login-name) + 'buffer-display 'buffer + 'connect-function #'erc-open-tls-stream)))) + + (ert-info ("Switches to TLS when URL is ircs://") + (should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r" + (erc-select-read-args)) + (list :server "irc.gnu.org" + :port 6697 + :nick (user-login-name) + 'buffer-display 'buffer + 'connect-function #'erc-open-tls-stream)))) + + (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" (erc-select-read-args)) (list :server "irc.libera.chat" :port 6667 - :nick (user-login-name) - 'buffer-display 'buffer - 'connect-function #'erc-open-network-stream)))) + :nick (user-login-name))))) - (ert-info ("Override non-TLS warning via URL scheme") + (ert-info ("Override default TLS") (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r" (erc-select-read-args)) (list :server "irc.libera.chat" :port 6667 - :nick (user-login-name) - 'buffer-display 'buffer - 'connect-function #'erc-open-network-stream)))) + :nick (user-login-name))))) (ert-info ("Address includes port") (should (equal (ert-simulate-keys "localhost:6667\rnick\r\r" (erc-select-read-args)) (list :server "localhost" :port 6667 - :nick "nick" - 'buffer-display 'buffer - 'connect-function #'erc-open-network-stream)))) + :nick "nick")))) (ert-info ("Address includes nick, password skipped via option") (should (equal (ert-simulate-keys "nick@localhost:6667\r" (let (erc-prompt-for-password) - (butlast (erc-select-read-args) 4))) + (erc-select-read-args))) (list :server "localhost" :port 6667 :nick "nick")))) (ert-info ("Address includes nick and password") - (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r" - (butlast (erc-select-read-args) 4)) + (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r" + (erc-select-read-args)) (list :server "localhost" :port 6667 :nick "nick" @@ -1055,29 +1069,29 @@ erc-select-read-args (ert-info ("IPv6 address plain") (should (equal (ert-simulate-keys "::1\r\r\r\r" - (butlast (erc-select-read-args) 4)) + (erc-select-read-args)) (list :server "[::1]" :port 6667 :nick (user-login-name))))) (ert-info ("IPv6 address with port") (should (equal (ert-simulate-keys "[::1]:6667\r\r\r" - (butlast (erc-select-read-args) 4)) + (erc-select-read-args)) (list :server "[::1]" :port 6667 :nick (user-login-name))))) (ert-info ("IPv6 address includes nick") (should (equal (ert-simulate-keys "nick@[::1]:6667\r\r" - (butlast (erc-select-read-args) 4)) + (erc-select-read-args)) (list :server "[::1]" :port 6667 :nick "nick")))) (ert-info ("Extra args use URL nick by default") - (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r" + (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r\r" (let ((current-prefix-arg '(4))) - (butlast (erc-select-read-args) 4))) + (erc-select-read-args))) (list :server "localhost" :port 6667 :nick "nick" -- 2.38.1