unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60428: 29.0.60; ERC 5.4.1: Fix default-port regression in erc-select-read-args
@ 2022-12-30 14:15 J.P.
  0 siblings, 0 replies; 8+ messages in thread
From: J.P. @ 2022-12-30 14:15 UTC (permalink / raw)
  To: 60428; +Cc: emacs-erc

[-- Attachment #1: Type: text/plain, Size: 4934 bytes --]

Tags: patch

To reproduce from emacs -Q, do an M-x erc and accept the default offered
at every prompt. Assuming your IP is not blacklisted by Libera, you
should see a connection failure immediately because a TLS endpoint is
dialed but negotiation never occurs.

This all stems from a lapse in professionalism on my part: an
underrealized feature snuck in with the changes from bug#56514, but
missing logic made it impossible to connect using the default prompt
values, which should probably always succeed because some people don't
care about parameters and just want to get there somehow (so I'm told).
Alternatively, if a deliberate failure is indeed warranted (an arguably
valid position), the error message should at least explain as much.

FWIW, the missing feature was supposed to offer an interactive upgrade
to TLS upon detecting a user's intent to connect to the default server
and, on confirmation, adjust ERC's parameters on the fly. The proposed
patch abandons most of the envisioned niceties and instead employs a
hack to just force a non-local exit and schedule a call to `erc-tls'
when appropriate. It also instructs users to do that themselves in the
future (issue an M-x erc-tls, that is). Hopefully, this makes for an
acceptable compromise.

BTW, a POC patch set far more faithful to the original breadth of the
feature (and way less hacky) is also attached. Perhaps it'll inform
further exploration in this area down the road (but not for Emacs 29).

Thanks.

P.S. Shout out to the Libera users who brought this to my attention.


In GNU Emacs 29.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.35, cairo version 1.17.6) of 2022-12-29 built on localhost
Repository revision: d086cd6cf877c6ca7af6712f9b79b52dd0caa934
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
System Description: Fedora Linux 36 (Workstation Edition)

Configured using:
 'configure --enable-check-lisp-object-type --enable-checking=yes,glyphs
 'CFLAGS=-O0 -g3'
 PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec epa epg rfc6068 epg-config gnus-util
text-property-search mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils erc rx derived pcase url-parse url-vars
iso8601 time-date auth-source cl-seq eieio eieio-core cl-macs
password-cache json subr-x map thingatpt pp format-spec cl-loaddefs
cl-lib erc-backend erc-goodies erc-networks byte-opt gv bytecomp
byte-compile erc-common erc-compat erc-loaddefs rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
emacs)

Memory information:
((conses 16 91094 5621)
 (symbols 48 9313 0)
 (strings 32 24582 1551)
 (string-bytes 1 743674)
 (vectors 16 14587)
 (vector-slots 8 205402 10021)
 (floats 8 24 35)
 (intervals 56 234 0)
 (buffers 976 10))


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-default-port-regression-in-erc-select-read-args.patch --]
[-- Type: text/x-patch, Size: 5409 bytes --]

From 78fe57488bb69f8f48e31fcd1ffcc31f31253207 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 1/4] Fix default-port regression in erc-select-read-args

* lisp/erc/erc.el (erc-select-read-args): Fix incomplete feature
introduced by bug#56514.  Ensure connecting always possible with
non-TLS default port, but offer upgrade.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Expect a prompt
and possible `user-error' when calling `erc' interactively with all
default arguments.
---
 lisp/erc/erc.el            | 38 +++++++++++++++++++++++++++++---------
 test/lisp/erc/erc-tests.el | 13 +++++++++----
 2 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 16a0aba77b..98d55bb1ae 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2171,10 +2171,7 @@ erc-select-read-args
          ;; For legacy reasons, also accept a URL without a scheme.
          (url (url-generic-parse-url (erc--ensure-url input)))
          (server (url-host url))
-         (sp (and (or (string-suffix-p "s" (url-type url))
-                      (and (equal server erc-default-server)
-                           (not (string-prefix-p "irc://" input))))
-                  'ircs-u))
+         (sp (and (string-suffix-p "s" (url-type url)) erc-default-port-tls))
          (port (or (url-portspec url)
                    (erc-compute-port
                     (let ((d (erc-compute-port sp))) ; may be a string
@@ -2188,12 +2185,35 @@ erc-select-read-args
                      (read-string (format "Nickname (default is %S): " d)
                                   nil 'erc-nick-history-list d))))
          (passwd (or (url-password url)
-                     (if erc-prompt-for-password
-                         (read-passwd "Server password (optional): ")
-                       (with-suppressed-warnings ((obsolete erc-password))
-                         erc-password)))))
+                     (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)))))
     (when (and passwd (string= "" passwd))
       (setq passwd nil))
+    (when-let (((equal server erc-default-server))
+               ((eql port erc-default-port))
+               ((not (string-prefix-p "irc://" input))) ; ignore irc6://
+               (key (substitute-command-keys "\\[erc-tls]"))
+               ((y-or-n-p (concat
+                           "Switch to " key " now instead of connecting "
+                           (propertize "unencrypted" 'face 'error) "?"))))
+      (run-at-time nil nil
+                   (lambda ()
+                     (with-suppressed-warnings ((obsolete erc-password))
+                       (let ((erc-nick nick)
+                             (erc-password passwd))
+                         (with-temp-message (format "Switching to %s ..." key)
+                           (sit-for 1))
+                         (with-current-buffer (call-interactively #'erc-tls)
+                           (erc-display-error-notice
+                            nil (format "Please use %s directly from now on."
+                                        key)))))))
+      (user-error "Non-TLS connection to default server detected"))
     (list :server server :port port :nick nick :password passwd)))
 
 ;;;###autoload
@@ -2287,7 +2307,7 @@ erc-tls
 See info node `(erc) Network Identifier' for details.  Like USER
 and CLIENT-CERTIFICATE, this parameter cannot be specified
 interactively."
-  (interactive (let ((erc-default-port erc-default-port-tls))
+  (interactive (let ((erc-port (or erc-port erc-default-port-tls)))
 		 (erc-select-read-args)))
   (let ((erc-server-connect-function 'erc-open-tls-stream))
     (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 578b2641a6..400b92d29e 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1001,15 +1001,20 @@ erc--server-connect-dumb-ipv6-regexp
 
 (ert-deftest erc-select-read-args ()
 
-  (ert-info ("Defaults to TLS")
-    (should (equal (ert-simulate-keys "\r\r\r\r"
+  (ert-info ("Error signaled with default server and non-TLS port")
+    (should (pcase (should-error (ert-simulate-keys "\r\r\r\ry\r"
+                                   (erc-select-read-args)))
+              (`(user-error ,(rx "Non-TLS")) 'passed))))
+
+  (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 6697
+                         :port 6667
                          :nick (user-login-name)
                          :password nil))))
 
-  (ert-info ("Override default TLS")
+  (ert-info ("Override non-TLS warning via URL scheme")
     (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-POC-Offer-TLS-by-default-for-M-x-erc.patch --]
[-- Type: text/x-patch, Size: 10134 bytes --]

From c2108baadd06a2301e379d41fcb5bbe9f03c2baf Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 2/4] [POC] Offer TLS by default for M-x erc

* lisp/erc/erc.el (erc-select-read-args): Offer to use TLS when user
runs M-x erc and opts for default server and port.  But do this
immediately instead of calling `erc-tls' interactively and imposing a
review of just-chosen values.  Also remove error warnings and ensure
`erc-tls' still works by setting `erc-server-connect-function' to
`erc-open-tls-stream' when appropriate.
(erc, erc-tls): Add internal keyword arguments for interactive use,
but don't make them colon-prefixed, i.e., `keywordp'.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Modify return
values to expect additional `connect-function' keyword argument.
---
 lisp/erc/erc.el            | 59 +++++++++++++++++++++-----------------
 test/lisp/erc/erc-tests.el | 42 +++++++++++++--------------
 2 files changed, 52 insertions(+), 49 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 98d55bb1ae..86149f7d2f 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2192,29 +2192,19 @@ erc-select-read-args
                           (m (if p
                                  (format "Server password (default is %S): " p)
                                "Server password (optional): ")))
-                       (if erc-prompt-for-password (read-passwd m nil p) p)))))
+                       (if erc-prompt-for-password (read-passwd m nil p) p))))
+         (opener erc-server-connect-function))
     (when (and passwd (string= "" passwd))
       (setq passwd nil))
-    (when-let (((equal server erc-default-server))
-               ((eql port erc-default-port))
-               ((not (string-prefix-p "irc://" input))) ; ignore irc6://
-               (key (substitute-command-keys "\\[erc-tls]"))
-               ((y-or-n-p (concat
-                           "Switch to " key " now instead of connecting "
-                           (propertize "unencrypted" 'face 'error) "?"))))
-      (run-at-time nil nil
-                   (lambda ()
-                     (with-suppressed-warnings ((obsolete erc-password))
-                       (let ((erc-nick nick)
-                             (erc-password passwd))
-                         (with-temp-message (format "Switching to %s ..." key)
-                           (sit-for 1))
-                         (with-current-buffer (call-interactively #'erc-tls)
-                           (erc-display-error-notice
-                            nil (format "Please use %s directly from now on."
-                                        key)))))))
-      (user-error "Non-TLS connection to default server detected"))
-    (list :server server :port port :nick nick :password passwd)))
+    (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 passwd `(:password ,passwd)) connect-function ,opener)))
+
 
 ;;;###autoload
 (cl-defun erc (&key (server (erc-compute-server))
@@ -2223,7 +2213,10 @@ erc
                     (user   (erc-compute-user))
                     password
                     (full-name (erc-compute-full-name))
-                    id)
+                    id
+                    ;; For interactive use
+                    ((connect-function erc-server-connect-function)
+                     erc-server-connect-function))
   "ERC is a powerful, modular, and extensible IRC client.
 This function is the main entry point for ERC.
 
@@ -2246,7 +2239,9 @@ erc
 whereas `erc-compute-port' and `erc-compute-nick' will be invoked
 for the values of the other parameters.
 
-See `erc-tls' for the meaning of ID."
+See `erc-tls' for the meaning of ID.
+
+\(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME ID)"
   (interactive (erc-select-read-args))
   (erc-open server port nick full-name t password nil nil nil nil user id))
 
@@ -2262,7 +2257,10 @@ erc-tls
                         password
                         (full-name (erc-compute-full-name))
                         client-certificate
-                        id)
+                        id
+                        ;; For interactive use
+                        ((connect-function erc-server-connect-function)
+                         #'erc-open-tls-stream))
   "ERC is a powerful, modular, and extensible IRC client.
 This function is the main entry point for ERC over TLS.
 
@@ -2306,10 +2304,17 @@ erc-tls
 the server buffer and identifying the connection unequivocally.
 See info node `(erc) Network Identifier' for details.  Like USER
 and CLIENT-CERTIFICATE, this parameter cannot be specified
-interactively."
-  (interactive (let ((erc-port (or erc-port erc-default-port-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)))
 		 (erc-select-read-args)))
-  (let ((erc-server-connect-function 'erc-open-tls-stream))
+  (progn
     (erc-open server port nick full-name t password
               nil nil nil client-certificate user id)))
 
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 400b92d29e..fb23aa3c0a 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1001,10 +1001,13 @@ erc--server-connect-dumb-ipv6-regexp
 
 (ert-deftest erc-select-read-args ()
 
-  (ert-info ("Error signaled with default server and non-TLS port")
-    (should (pcase (should-error (ert-simulate-keys "\r\r\r\ry\r"
-                                   (erc-select-read-args)))
-              (`(user-error ,(rx "Non-TLS")) 'passed))))
+  (ert-info ("Doesn't default to TLS")
+    (should (equal (ert-simulate-keys "\r\r\r\ry\r"
+                     (erc-select-read-args))
+                   (list :server "irc.libera.chat"
+                         :port 6697
+                         :nick (user-login-name)
+                         'connect-function #'erc-open-tls-stream))))
 
   (ert-info ("Opt out of non-TLS warning manually")
     (should (equal (ert-simulate-keys "\r\r\r\rn\r"
@@ -1012,7 +1015,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6667
                          :nick (user-login-name)
-                         :password nil))))
+                         'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Override non-TLS warning via URL scheme")
     (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r"
@@ -1020,29 +1023,27 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6667
                          :nick (user-login-name)
-                         :password nil))))
+                         'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Address includes port")
-    (should (equal (ert-simulate-keys
-                       "localhost:6667\rnick\r\r"
+    (should (equal (ert-simulate-keys "localhost:6667\rnick\r\r"
                      (erc-select-read-args))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
-                         :password nil))))
+                         'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Address includes nick, password skipped via option")
     (should (equal (ert-simulate-keys "nick@localhost:6667\r"
                      (let (erc-prompt-for-password)
-                       (erc-select-read-args)))
+                       (butlast (erc-select-read-args) 2)))
                    (list :server "localhost"
                          :port 6667
-                         :nick "nick"
-                         :password nil))))
+                         :nick "nick"))))
 
   (ert-info ("Address includes nick and password")
     (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r"
-                     (erc-select-read-args))
+                     (butlast (erc-select-read-args) 2))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
@@ -1050,27 +1051,24 @@ erc-select-read-args
 
   (ert-info ("IPv6 address plain")
     (should (equal (ert-simulate-keys "::1\r\r\r\r"
-                     (erc-select-read-args))
+                     (butlast (erc-select-read-args) 2))
                    (list :server "[::1]"
                          :port 6667
-                         :nick (user-login-name)
-                         :password nil))))
+                         :nick (user-login-name)))))
 
   (ert-info ("IPv6 address with port")
     (should (equal (ert-simulate-keys "[::1]:6667\r\r\r"
-                     (erc-select-read-args))
+                     (butlast (erc-select-read-args) 2))
                    (list :server "[::1]"
                          :port 6667
-                         :nick (user-login-name)
-                         :password nil))))
+                         :nick (user-login-name)))))
 
   (ert-info ("IPv6 address includes nick")
     (should (equal (ert-simulate-keys "nick@[::1]:6667\r\r"
-                     (erc-select-read-args))
+                     (butlast (erc-select-read-args) 2))
                    (list :server "[::1]"
                          :port 6667
-                         :nick "nick"
-                         :password nil)))))
+                         :nick "nick")))))
 
 (ert-deftest erc-tls ()
   (let (calls)
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-POC-Display-buffers-differently-for-M-x-erc.patch --]
[-- Type: text/x-patch, Size: 6805 bytes --]

From 6dd5bf870aec52b44080676301849c6d5059985a Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 3/4] [POC] Display buffers differently for M-x erc

* lisp/erc/erc.el (erc-buffer-display): Add alias for
`erc-join-buffer'.
(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.
(erc, erc-tls): Add interactive-only to control initial buffer
display.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Expect
buffer-display values from `erc-interactive-display'.
---
 lisp/erc/erc.el            | 20 +++++++++++++++++++-
 test/lisp/erc/erc-tests.el | 14 +++++++++-----
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 86149f7d2f..049e8af350 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1459,6 +1459,7 @@ erc-default-port-tls
   "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.
 
@@ -1479,6 +1480,18 @@ erc-join-buffer
                  (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.4.1") ; FIXME increment upon publishing to ELPA
+  :group 'erc-buffers
+  :type '(choice (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.
 
@@ -2203,7 +2216,8 @@ erc-select-read-args
                         (setq port erc-default-port-tls))))
       (setq opener #'erc-open-tls-stream))
     `( :server ,server :port ,port :nick ,nick
-       ,@(and passwd `(:password ,passwd)) connect-function ,opener)))
+       ,@(and passwd `(:password ,passwd))
+       buffer-display ,erc-interactive-display connect-function ,opener)))
 
 
 ;;;###autoload
@@ -2215,6 +2229,8 @@ erc
                     (full-name (erc-compute-full-name))
                     id
                     ;; For interactive use
+                    ((buffer-display erc-buffer-display)
+                     erc-buffer-display)
                     ((connect-function erc-server-connect-function)
                      erc-server-connect-function))
   "ERC is a powerful, modular, and extensible IRC client.
@@ -2259,6 +2275,8 @@ erc-tls
                         client-certificate
                         id
                         ;; For interactive use
+                        ((buffer-display erc-buffer-display)
+                         erc-buffer-display)
                         ((connect-function erc-server-connect-function)
                          #'erc-open-tls-stream))
   "ERC is a powerful, modular, and extensible IRC client.
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index fb23aa3c0a..6d60c9e274 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1007,6 +1007,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6697
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-tls-stream))))
 
   (ert-info ("Opt out of non-TLS warning manually")
@@ -1015,6 +1016,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6667
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Override non-TLS warning via URL scheme")
@@ -1023,6 +1025,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6667
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Address includes port")
@@ -1031,19 +1034,20 @@ erc-select-read-args
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-network-stream))))
 
   (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) 2)))
+                       (butlast (erc-select-read-args) 4)))
                    (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) 2))
+                     (butlast (erc-select-read-args) 4))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
@@ -1051,21 +1055,21 @@ erc-select-read-args
 
   (ert-info ("IPv6 address plain")
     (should (equal (ert-simulate-keys "::1\r\r\r\r"
-                     (butlast (erc-select-read-args) 2))
+                     (butlast (erc-select-read-args) 4))
                    (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) 2))
+                     (butlast (erc-select-read-args) 4))
                    (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) 2))
+                     (butlast (erc-select-read-args) 4))
                    (list :server "[::1]"
                          :port 6667
                          :nick "nick")))))
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-POC-Optionally-prompt-for-more-ERC-entry-point-param.patch --]
[-- Type: text/x-patch, Size: 4767 bytes --]

From 66575cffd38d576f93348b089ec77e1b6e1dad57 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 4/4] [POC] Optionally prompt for more ERC entry-point params

* doc/misc/erc.texi: Update statement about availability of user param
when entry points called interactively.
* lisp/erc/erc.el (erc-select-read-args): Allow optionally calling
entry points with a prefix arg to access params `user' and
`:full-name'.
(erc-tls): Update doc string.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Add test for
extra args.
---
 doc/misc/erc.texi          |  2 +-
 lisp/erc/erc.el            | 19 ++++++++++++++-----
 test/lisp/erc/erc-tests.el | 13 ++++++++++++-
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi
index 249b58c73d..2e3b635f5e 100644
--- a/doc/misc/erc.texi
+++ b/doc/misc/erc.texi
@@ -932,7 +932,7 @@ SASL
 your @samp{NickServ} password.  To make this work, customize
 @code{erc-sasl-user} and @code{erc-sasl-password} or specify the
 @code{:user} and @code{:password} keyword arguments when invoking
-@code{erc-tls}.  Note that @code{:user} cannot be given interactively.
+@code{erc-tls}.
 
 @item @code{external} (via Client TLS Certificate)
 This works in conjunction with the @code{:client-certificate} keyword
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 049e8af350..585fba079f 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2176,7 +2176,8 @@ erc--ensure-url
 
 ;;;###autoload
 (defun erc-select-read-args ()
-  "Prompt the user for values of nick, server, port, and password."
+  "Prompt the user for values of nick, server, port, and password.
+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)
@@ -2197,6 +2198,14 @@ erc-select-read-args
                    (let ((d (erc-compute-nick)))
                      (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))))
+                      (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))))
+                      (read-string (format "Full name (default is %S): " d)
+                                   nil nil d))))
          (passwd (or (url-password url)
                      (let*
                          ((p (with-suppressed-warnings
@@ -2215,8 +2224,8 @@ erc-select-read-args
                    (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 passwd `(:password ,passwd))
+    `( :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)))
 
 
@@ -2320,8 +2329,8 @@ erc-tls
 
 When present, ID should be a symbol or a string to use for naming
 the server buffer and identifying the connection unequivocally.
-See info node `(erc) Network Identifier' for details.  Like USER
-and CLIENT-CERTIFICATE, this parameter cannot be specified
+See info node `(erc) Network Identifier' for details.  Like
+CLIENT-CERTIFICATE, this parameter cannot be specified
 interactively.
 
 \(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)"
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 6d60c9e274..e3df32d773 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1072,7 +1072,18 @@ erc-select-read-args
                      (butlast (erc-select-read-args) 4))
                    (list :server "[::1]"
                          :port 6667
-                         :nick "nick")))))
+                         :nick "nick"))))
+
+  (ert-info ("Extra args use URL nick by default")
+    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r"
+                     (let ((current-prefix-arg '(4)))
+                       (butlast (erc-select-read-args) 4)))
+                   (list :server "localhost"
+                         :port 6667
+                         :nick "nick"
+                         :user "nick"
+                         :password "sesame"
+                         :full-name "nick")))))
 
 (ert-deftest erc-tls ()
   (let (calls)
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-04-14 14:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87mt750ygt.fsf@neverwas.me>
2023-01-02  1:41 ` bug#60428: 29.0.60; ERC 5.4.1: Fix default-port regression in erc-select-read-args J.P.
     [not found] ` <87h6x9yapz.fsf@neverwas.me>
2023-01-19 14:18   ` bug#60428: 30.0.50; ERC >5.5: Make M-x erc a more welcoming entry point J.P.
2023-02-07 15:21 ` J.P.
2023-02-19 15:05 ` J.P.
     [not found] ` <87h6vhwv9u.fsf@neverwas.me>
2023-04-08 23:06   ` J.P.
2023-04-11  3:29 ` J.P.
     [not found] ` <874jpnqeoc.fsf@neverwas.me>
2023-04-14 14:01   ` J.P.
2022-12-30 14:15 bug#60428: 29.0.60; ERC 5.4.1: Fix default-port regression in erc-select-read-args J.P.

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).