From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "J.P." Newsgroups: gmane.emacs.bugs Subject: bug#60428: 29.0.60; ERC 5.4.1: Fix default-port regression in erc-select-read-args Date: Fri, 30 Dec 2022 06:15:30 -0800 Message-ID: <87mt750ygt.fsf__39774.8210163385$1672409818$gmane$org@neverwas.me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24224"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-erc@gnu.org To: 60428@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 30 15:16:49 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pBGBi-00063S-Px for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 30 Dec 2022 15:16:47 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pBGB2-0004aG-VF; Fri, 30 Dec 2022 09:16:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBGB1-0004ZH-97; Fri, 30 Dec 2022 09:16:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pBGB0-00086l-LI; Fri, 30 Dec 2022 09:16:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pBGB0-0005lJ-1R; Fri, 30 Dec 2022 09:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: emacs-erc@gnu.org, bug-gnu-emacs@gnu.org Resent-Date: Fri, 30 Dec 2022 14:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60428 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: emacs-erc@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.167240975122114 (code B ref -1); Fri, 30 Dec 2022 14:16:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Dec 2022 14:15:51 +0000 Original-Received: from localhost ([127.0.0.1]:33770 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBGAn-0005kb-JU for submit@debbugs.gnu.org; Fri, 30 Dec 2022 09:15:51 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:34122) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pBGAj-0005kR-QI for submit@debbugs.gnu.org; Fri, 30 Dec 2022 09:15:47 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pBGAj-0004TH-Hj for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2022 09:15:45 -0500 Original-Received: from mail-108-mta149.mxroute.com ([136.175.108.149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pBGAf-0007x0-Ne for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2022 09:15:45 -0500 Original-Received: from mail-111-mta2.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta149.mxroute.com (ZoneMTA) with ESMTPSA id 18563635a40000011e.001 for (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Fri, 30 Dec 2022 14:15:33 +0000 X-Zone-Loop: db2ce0cf8bff659831714013ef2d07910293160a24e0 X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=neverwas.me ; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From:Sender: Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=99wbx7Lx3lwvwDW53eAzhjCXw+FO1mEtiWZp62IzV0Y=; b=j1KE552HoGx9VaAeQXNb6eeNLY itfYNnNWNkQc5KDaMJtFs6nU+/WA5ViuV/MjFNON/yoe75wJH+qGnU0fcPyjYmaTZ4vTWAM46coeM H3PO2xqhXumvQvkXsAyu7SEMG4N9AMl75Sgsd9IAGgZncdRvpFUS3neHsjmfnqwswK6J1CAznTIRZ PANrqQTZlkatisiULEsEzV4PGrCmwvK1ACHEEBR/wWj0N73ApM2L74VlbyskGdahf1l3FuBW5CLIJ fUrFe4Kk0qnYdGO/xEe97qoufeH4k7qxogeeMkYuYzuGFpb/HPG+fDWGWuXaNIphnSyUhrKnqPnZ9 Y62DAyFw==; X-Authenticated-Id: masked@neverwas.me Received-SPF: pass client-ip=136.175.108.149; envelope-from=jp@neverwas.me; helo=mail-108-mta149.mxroute.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:252118 Archived-At: --=-=-= Content-Type: text/plain 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)) --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-default-port-regression-in-erc-select-read-args.patch >From 78fe57488bb69f8f48e31fcd1ffcc31f31253207 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-POC-Offer-TLS-by-default-for-M-x-erc.patch >From c2108baadd06a2301e379d41fcb5bbe9f03c2baf Mon Sep 17 00:00:00 2001 From: "F. Jason Park" 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0003-POC-Display-buffers-differently-for-M-x-erc.patch >From 6dd5bf870aec52b44080676301849c6d5059985a Mon Sep 17 00:00:00 2001 From: "F. Jason Park" 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0004-POC-Optionally-prompt-for-more-ERC-entry-point-param.patch >From 66575cffd38d576f93348b089ec77e1b6e1dad57 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" 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 --=-=-=--