mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-05 22:20:24 -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:
parent
b7560fb63d
commit
ff8c0648fb
2 changed files with 35 additions and 13 deletions
16
lisp/ffap.el
16
lisp/ffap.el
|
|
@ -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'.")
|
||||
|
||||
(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
|
||||
wrong more often when trying to find a file name intermingled
|
||||
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
|
||||
(memq mode '(nil file)))
|
||||
(when (setq dir-separator (ffap-dir-separator-near-point))
|
||||
(while (re-search-backward
|
||||
(regexp-quote dir-separator)
|
||||
(line-beginning-position) t)
|
||||
(goto-char (match-beginning 0))))
|
||||
(let ((dirsep-re (regexp-quote dir-separator))
|
||||
(line-beg (line-beginning-position)))
|
||||
(while (re-search-backward dirsep-re line-beg t)
|
||||
(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-forward (nth 1 args) pt))
|
||||
(point))))
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ left alone when opening a URL in an external browser."
|
|||
(with-temp-buffer
|
||||
(insert string)
|
||||
(goto-char (point-min))
|
||||
(forward-char 10)
|
||||
(forward-char 3)
|
||||
(ffap-string-at-point))))
|
||||
|
||||
(ert-deftest ffap-test-with-spaces ()
|
||||
|
|
@ -113,7 +113,7 @@ left alone when opening a URL in an external browser."
|
|||
(equal
|
||||
(ffap-test-string
|
||||
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
|
||||
(equal
|
||||
(ffap-test-string
|
||||
|
|
@ -122,23 +122,39 @@ left alone when opening a URL in an external browser."
|
|||
(should
|
||||
(equal
|
||||
(ffap-test-string
|
||||
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/"))
|
||||
t "z:/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
|
||||
(equal
|
||||
(ffap-test-string
|
||||
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
|
||||
(equal
|
||||
(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")
|
||||
"\\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")
|
||||
"d:\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt"))
|
||||
(should
|
||||
(equal
|
||||
(ffap-test-string
|
||||
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 ()
|
||||
(should-not
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue