From 7769b62cd23bf3eb879c34e0c78ed7f367791993 Mon Sep 17 00:00:00 2001 From: Visuwesh Date: Tue, 12 Dec 2023 21:14:12 +0530 Subject: [PATCH] Make ffap correctly guess remote file names at point * lisp/ffap.el (ffap-lax-url): Set it to nil so that remote file names may be matched. (bug#67688) (ffap-fixup-email): New function. (ffap-guesser): Specially handle email addresses now that ffap-lax-url is nil as user@host fails to be matched as an email address with that setting. * etc/NEWS: Announce the new value of the defcustom. --- etc/NEWS | 5 +++++ lisp/ffap.el | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 29f4e5c0b66..3e527fcd2ad 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -258,6 +258,11 @@ called in the '--eval' expression, which is useful when those arguments contain arbitrary characters that otherwise might require elaborate and error-prone escaping (to protect them from the shell). +--- +** 'ffap-lax-url' now defaults to nil. +Previously, it was set to 'ffap-lax-url' to t but this broke remote file +name detection. + * Editing Changes in Emacs 30.1 diff --git a/lisp/ffap.el b/lisp/ffap.el index 530e3da182e..9cea11cf540 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el @@ -152,15 +152,15 @@ ffap-url-unwrap-remote :group 'ffap :version "24.3") -(defcustom ffap-lax-url t +(defcustom ffap-lax-url nil "If non-nil, allow lax URL matching. The default non-nil value might produce false URLs in C++ code with symbols like \"std::find\". On the other hand, setting this to nil will disable recognition of URLs that are not -well-formed, such as \"user@host\" or \"\"." +well-formed." :type 'boolean :group 'ffap - :version "25.2") ; nil -> t + :version "30.1") (defcustom ffap-ftp-default-user "anonymous" "User name in FTP file names generated by `ffap-host-to-filename'. @@ -609,6 +609,13 @@ ffap-fixup-url ((and ffap-url-unwrap-remote (ffap-url-unwrap-remote url))) (url))) +(defun ffap-fixup-email (email) + "Clean up EMAIL and return it as a mailto: URL." + (when (stringp email) + (if (string-prefix-p "mailto:" email) + email + (concat "mailto:" email)))) + ;;; File Name Handling: @@ -1571,6 +1578,7 @@ ffap-guesser (ffap-fixup-url (or (ffap-url-at-point) (ffap-gopher-at-point)))) (ffap-file-at-point) ; may yield url! + (ffap-fixup-email (thing-at-point 'email)) (ffap-fixup-machine (ffap-machine-at-point)))) (defun ffap-prompter (&optional guess suffix) -- 2.42.0