From c348a0162a84f97627bb7b9b613d6c88a12a03e7 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 29 Dec 2022 06:43:19 -0800 Subject: [PATCH 3/3] [5.6] 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/compat.el: Don't require `url-parse' when compiling. Add forward declaration for `url-type'. * lisp/erc/erc.el: Don't require `url-parse' when compiling. Add forward declarations for url accessors of url struct from url-parse library. (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. (Bug#60428.) --- doc/misc/erc.texi | 2 +- lisp/erc/erc-compat.el | 3 ++- lisp/erc/erc.el | 28 +++++++++++++++++++++------- test/lisp/erc/erc-tests.el | 13 ++++++++++++- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi index d5ec0f48e1c..d60d7fc8f2d 100644 --- a/doc/misc/erc.texi +++ b/doc/misc/erc.texi @@ -952,7 +952,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-compat.el b/lisp/erc/erc-compat.el index 5601ede27a5..d475d9cf458 100644 --- a/lisp/erc/erc-compat.el +++ b/lisp/erc/erc-compat.el @@ -32,7 +32,7 @@ ;;; Code: (require 'compat nil 'noerror) -(eval-when-compile (require 'cl-lib) (require 'url-parse)) +(eval-when-compile (require 'cl-lib)) ;;;###autoload(autoload 'erc-define-minor-mode "erc-compat") (define-obsolete-function-alias 'erc-define-minor-mode @@ -378,6 +378,7 @@ erc-compat--with-memoization (t `(progn ,@forms)))) (defvar url-irc-function) +(declare-function url-type "url-parse" (cl-x)) (defun erc-compat--29-browse-url-irc (string &rest _) (require 'url-irc) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 9dbca09bb35..f1a51341924 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -69,7 +69,7 @@ (require 'auth-source) (require 'time-date) (require 'iso8601) -(eval-when-compile (require 'subr-x) (require 'url-parse)) +(eval-when-compile (require 'subr-x)) (defconst erc-version "5.4.1" "This version of ERC.") @@ -139,6 +139,12 @@ tabbar--local-hlf (defvar motif-version-string) (defvar gtk-version-string) +(declare-function url-host "url-parse" (cl-x)) +(declare-function url-password "url-parse" (cl-x)) +(declare-function url-portspec "url-parse" (cl-x)) +(declare-function url-type "url-parse" (cl-x)) +(declare-function url-user "url-parse" (cl-x)) + ;; tunable connection and authentication parameters (defcustom erc-server nil @@ -2192,8 +2198,8 @@ erc--ensure-url ;;;###autoload (defun erc-select-read-args () - "Prompt the user for values of nick, server, port, and password." - (require 'url-parse) + "Prompt the user for values of nick, server, port, and password. +With prefix arg, also prompt for user and full name." (let* ((input (let ((d (erc-compute-server))) (read-string (format "Server or URL (default is %S): " d) nil 'erc-server-history-list d))) @@ -2213,6 +2219,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 (erc-compute-user (url-user url)))) + (read-string (format "User (default is %S): " d) + nil nil d)))) + (full (and current-prefix-arg + (let ((d (erc-compute-full-name (url-user url)))) + (read-string (format "Full name (default is %S): " d) + nil nil d)))) (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password)) (or (url-password url) erc-password))) (m (if p @@ -2233,8 +2247,8 @@ erc-select-read-args (push `(erc-server-connect-function . ,opener) env)) (when (and passwd (string= "" passwd)) (setq passwd nil)) - `( :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)) ,@(and env `(&interactive-env ,env))))) (defmacro erc--with-entrypoint-environment (env &rest body) @@ -2342,8 +2356,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 4edd72aade4..68b4413da44 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1096,7 +1096,18 @@ erc-select-read-args (erc-select-read-args)) (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\r" + (let ((current-prefix-arg '(4))) + (erc-select-read-args))) + (list :server "localhost" + :port 6667 + :nick "nick" + :user "nick" + :password "sesame" + :full-name "nick"))))) (ert-deftest erc-tls () (let (calls env) -- 2.39.1