1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Fix 'ffap-string-at-point' under 'ffap-file-name-with-spaces'

* lisp/ffap.el (ffap-file-name-with-spaces): Doc fix.
(ffap-string-at-point): Don't reject '~foo/' and 'd:/bar' file
names when 'ffap-file-name-with-spaces' is non-nil.

* test/lisp/ffap-tests.el (ffap-test-with-spaces): Add tests, and
fix expected results to not strip Windows drive letters.
This commit is contained in:
Eli Zaretskii 2025-06-08 11:21:05 +03:00
parent b7560fb63d
commit ff8c0648fb
2 changed files with 35 additions and 13 deletions

View file

@ -1140,7 +1140,7 @@ The arguments CHARS, BEG and END are handled as described in
"Last string returned by the function `ffap-string-at-point'.") "Last string returned by the function `ffap-string-at-point'.")
(defcustom ffap-file-name-with-spaces nil (defcustom ffap-file-name-with-spaces nil
"If non-nil, enable looking for paths with spaces in `ffap-string-at-point'. "If non-nil, allow file names with spaces in `ffap-string-at-point'.
Enabling this variable may lead to `find-file-at-point' guessing Enabling this variable may lead to `find-file-at-point' guessing
wrong more often when trying to find a file name intermingled wrong more often when trying to find a file name intermingled
with normal text, but can be useful when working on systems that with normal text, but can be useful when working on systems that
@ -1286,10 +1286,16 @@ return an empty string, and set `ffap-string-at-point-region' to `(1 1)'."
(if (and ffap-file-name-with-spaces (if (and ffap-file-name-with-spaces
(memq mode '(nil file))) (memq mode '(nil file)))
(when (setq dir-separator (ffap-dir-separator-near-point)) (when (setq dir-separator (ffap-dir-separator-near-point))
(while (re-search-backward (let ((dirsep-re (regexp-quote dir-separator))
(regexp-quote dir-separator) (line-beg (line-beginning-position)))
(line-beginning-position) t) (while (re-search-backward dirsep-re line-beg t)
(goto-char (match-beginning 0)))) (goto-char (match-beginning 0)))
(if (and (looking-at dirsep-re)
(looking-back
;; Either "~[USER]" or drive letter.
"\\(~[[:graph:]]*\\|[a-zA-Z]:\\)"
line-beg))
(goto-char (match-beginning 0)))))
(skip-chars-backward (car args)) (skip-chars-backward (car args))
(skip-chars-forward (nth 1 args) pt)) (skip-chars-forward (nth 1 args) pt))
(point)))) (point))))

View file

@ -105,7 +105,7 @@ left alone when opening a URL in an external browser."
(with-temp-buffer (with-temp-buffer
(insert string) (insert string)
(goto-char (point-min)) (goto-char (point-min))
(forward-char 10) (forward-char 3)
(ffap-string-at-point)))) (ffap-string-at-point))))
(ert-deftest ffap-test-with-spaces () (ert-deftest ffap-test-with-spaces ()
@ -113,7 +113,7 @@ left alone when opening a URL in an external browser."
(equal (equal
(ffap-test-string (ffap-test-string
t "c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt") t "c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt")
"/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt")) "c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt"))
(should (should
(equal (equal
(ffap-test-string (ffap-test-string
@ -122,23 +122,39 @@ left alone when opening a URL in an external browser."
(should (should
(equal (equal
(ffap-test-string (ffap-test-string
t "c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/") t "z:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/")
"/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/")) "z:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/"))
(should (should
(equal (equal
(ffap-test-string (ffap-test-string
t "c:\\Program Files\\Open Text Evaluation Media\\Open Text Exceed 14 x86\\Program Files\\Hummingbird\\") t "c:\\Program Files\\Open Text Evaluation Media\\Open Text Exceed 14 x86\\Program Files\\Hummingbird\\")
"\\Program Files\\Open Text Evaluation Media\\Open Text Exceed 14 x86\\Program Files\\Hummingbird\\")) "c:\\Program Files\\Open Text Evaluation Media\\Open Text Exceed 14 x86\\Program Files\\Hummingbird\\"))
(should (should
(equal (equal
(ffap-test-string (ffap-test-string
t "c:\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt") t "d:\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt")
"\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt")) "d:\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt"))
(should (should
(equal (equal
(ffap-test-string (ffap-test-string
t "C:\\temp\\program.log on Windows or /var/log/program.log on Unix.") t "C:\\temp\\program.log on Windows or /var/log/program.log on Unix.")
"\\temp\\program.log"))) "C:\\temp\\program.log"))
(should
(equal
(ffap-test-string t "~/tmp/")
"~/tmp/"))
(should
(equal
(ffap-test-string nil "~/tmp/")
"~/tmp/"))
(should
(equal
(ffap-test-string t "~abc123_áè/foo")
"~abc123_áè/foo"))
(should
(equal
(ffap-test-string t "c:/Program Files/my program.exe and here's more text")
"c:/Program Files/my program.exe")))
(ert-deftest ffap-test-no-newlines () (ert-deftest ffap-test-no-newlines ()
(should-not (should-not