>From 2d35563e0ac22686bb69100536692cb026fc67f2 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 11 Nov 2022 00:12:34 -0800 Subject: [PATCH 0/5] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (5): Accommodate ircs:// URLs in url-irc and browse-url Refactor erc-select-read-args Default to TLS port when calling erc-tls from lisp Add optional server param to erc-networks--determine Improve new connections in erc-handle-irc-url doc/misc/erc.texi | 28 +++ etc/NEWS | 20 ++ lisp/erc/erc-backend.el | 6 + lisp/erc/erc-compat.el | 19 ++ lisp/erc/erc-networks.el | 9 +- lisp/erc/erc.el | 192 ++++++++++----- lisp/net/browse-url.el | 24 ++ lisp/url/url-irc.el | 32 ++- test/lisp/erc/erc-networks-tests.el | 17 ++ test/lisp/erc/erc-scenarios-misc.el | 28 +++ test/lisp/erc/erc-tests.el | 226 ++++++++++++++++++ .../lisp/erc/resources/join/legacy/foonet.eld | 2 +- test/lisp/net/browse-url-tests.el | 9 + 13 files changed, 537 insertions(+), 75 deletions(-) Interdiff: diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi index d01eab1bbb..9742fc3c22 100644 --- a/doc/misc/erc.texi +++ b/doc/misc/erc.texi @@ -998,10 +998,10 @@ Integrations @subheading URL For anything to work, you'll want to set @code{url-irc-function} to -@code{url-irc-erc}. As a rule of thumb, libraries that rely directly -on @code{url-retrieve} should be good to go out the box from Emacs -29.1 onward. On older versions of Emacs, you may need to -@code{(require 'erc)} beforehand. @pxref{Retrieving URLs,,, url, URL}. +@code{url-irc-erc}. As a rule of thumb, libraries relying directly on +@code{url-retrieve} should be fine out the box from Emacs 29.1 onward. +On older versions of Emacs, you may need to @code{(require 'erc)} +beforehand. @pxref{Retrieving URLs,,, url, URL}. For other apps and libraries, such as those relying on the higher-level @code{browse-url}, you'll oftentimes be asked to specify @@ -1012,22 +1012,11 @@ Integrations need a function as well: @lisp - '("\\birc6?s?://[][a-z0-9.,@@_:+%?&/#-]+" - 0 t erc-browse-url-handler 0) + '("\\birc6?s?://[][a-z0-9.,@@_:+%?&/#-]+" 0 t browse-url-irc 0) @end lisp -@defun erc-browse-url-handler url &rest args -An autoloaded convenience function for use in options like those -mentioned above. @var{url} must be a string. In Emacs 29 and above, -the function @code{browse-url-irc} can be used instead. -@end defun - @noindent -Keep in mind that when fiddling with these options, it may be easier -(and more polite) to connect to a local server or a test network, like -@samp{ircs://testnet.ergo.chat/#test}, since these generally don't -require authentication. - +Users on Emacs 28 and below may need to use @code{browse-url} instead. @node Options @section Options diff --git a/lisp/erc/erc-compat.el b/lisp/erc/erc-compat.el index 683d19dfc7..340d90ba96 100644 --- a/lisp/erc/erc-compat.el +++ b/lisp/erc/erc-compat.el @@ -32,6 +32,7 @@ ;;; Code: (require 'compat nil 'noerror) +(eval-when-compile (require 'url-parse)) ;;;###autoload(autoload 'erc-define-minor-mode "erc-compat") (define-obsolete-function-alias 'erc-define-minor-mode @@ -168,20 +169,23 @@ erc-compat--with-memoization `(cl--generic-with-memoization ,table ,@forms)) (t `(progn ,@forms)))) -(declare-function browse-url-irc "browse-url" (url &rest _)) +(defvar url-irc-function) -(defun erc-compat--browse-url-irc (string &rest _) - "Parse STRING and call `url-irc'." +(defun erc-compat--29-browse-url-irc (string &rest _) + (cl-assert (< emacs-major-version 29)) (require 'url-irc) - (if (< emacs-major-version 29) - ;; `url-irc' binds this in Emacs 29+. - (let ((url-current-object (url-generic-parse-url string))) - (url-irc url-current-object)) - (browse-url-irc string))) + (let* ((url (url-generic-parse-url string)) + (url-irc-function + (if (function-equal url-irc-function 'url-irc-erc) + (lambda (host port chan user pass) + (erc-handle-irc-url host port chan user pass (url-type url))) + url-irc-function))) + (url-irc url))) (when (< emacs-major-version 29) - (add-to-list 'browse-url-default-handlers - '("\\`irc6?s?://" . erc-compat--browse-url-irc))) + (unless (assoc "\\`irc6?s?://" browse-url-default-handlers) + (push '("\\`irc6?s?://" . erc-compat--29-browse-url-irc) + browse-url-default-handlers))) (provide 'erc-compat) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 51a97c8de1..cfd1c34ef0 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -7195,7 +7195,7 @@ erc--url-default-connect-function (apply (if ircsp #'erc-tls #'erc) args))) ;;;###autoload -(defun erc-handle-irc-url (host port channel nick password scheme) +(defun erc-handle-irc-url (host port channel nick password &optional scheme) "Use ERC to IRC on HOST:PORT in CHANNEL. If ERC is already connected to HOST:PORT, simply /join CHANNEL. Otherwise, connect to HOST:PORT as NICK and /join CHANNEL. @@ -7247,14 +7247,6 @@ erc-handle-irc-url (with-current-buffer server-buffer (erc-cmd-JOIN channel key)))))) -(defvar url-irc-function) - -;;;###autoload -(defun erc-browse-url-handler (url &rest _) - "Launch an ERC session when given an irc:// URL." - (let ((url-irc-function 'url-irc-erc)) - (erc-compat--browse-url-irc url))) - (provide 'erc) ;;; erc.el ends here diff --git a/test/lisp/erc/erc-scenarios-misc.el b/test/lisp/erc/erc-scenarios-misc.el index ded620ccc1..8557a77906 100644 --- a/test/lisp/erc/erc-scenarios-misc.el +++ b/test/lisp/erc/erc-scenarios-misc.el @@ -177,4 +177,32 @@ erc-scenarios-dcc-chat-accept (erc-scenarios-common-say "Hi") (funcall expect 10 "Hola"))))) +(defvar url-irc-function) + +(ert-deftest erc-scenarios-handle-irc-url () + :tags '(:expensive-test) + (erc-scenarios-common-with-cleanup + ((erc-scenarios-common-dialog "join/legacy") + (dumb-server (erc-d-run "localhost" t 'foonet)) + (port (process-contact dumb-server :service)) + (expect (erc-d-t-make-expecter)) + (url-irc-function 'url-irc-erc) + (erc-url-connect-function + (lambda (scheme &rest r) + (ert-info ("Connect to foonet") + (should (equal scheme "irc")) + (with-current-buffer (apply #'erc `(:full-name "tester" ,@r)) + (should (string= (buffer-name) + (format "127.0.0.1:%d" port))) + (current-buffer)))))) + + (with-temp-buffer + (insert (format ";; irc://tester:changeme@127.0.0.1:%d/#chan" port)) + (goto-char 10) + (browse-url-at-point)) + + (ert-info ("Connected") + (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "#chan")) + (funcall expect 10 "welcome"))))) + ;;; erc-scenarios-misc.el ends here diff --git a/test/lisp/erc/resources/join/legacy/foonet.eld b/test/lisp/erc/resources/join/legacy/foonet.eld index 344ba7c1da..4025094a59 100644 --- a/test/lisp/erc/resources/join/legacy/foonet.eld +++ b/test/lisp/erc/resources/join/legacy/foonet.eld @@ -1,5 +1,5 @@ ;; -*- mode: lisp-data; -*- -((pass 1 "PASS :changeme")) +((pass 10 "PASS :changeme")) ((nick 1 "NICK tester")) ((user 1 "USER user 0 * :tester") (0 ":irc.foonet.org 001 tester :Welcome to the foonet IRC Network tester") -- 2.38.1