From cbbb19ced674dc8c42c95238577abb9849a75b87 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. (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. (Bug#67688) * 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 03218d08d80..6df17aa3f0a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -278,6 +278,11 @@ elaborate and error-prone escaping (to protect them from the shell). When answering the prompt with "diff" or "=", it now shows the diffs between the auto save file and the current file. +--- +** '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 @@ schemes (e.g. \"ftp\"); in that case, only convert those URLs." :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 @@ Looks at `ffap-ftp-default-user', returns \"\" for \"localhost\"." ((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 @@ Uses the face `ffap' if it is defined, or else `highlight'." (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.39.2