diff options
| author | Eli Zaretskii | 2025-06-08 11:21:05 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2025-06-08 11:21:05 +0300 |
| commit | ff8c0648fb4dd67bfad44167e70f25a12b1149bd (patch) | |
| tree | 54b97b54f5154e9c6e938d5dd7be4219311a233d | |
| parent | b7560fb63dce3a1c7cc7048ebcfca7c694e566d2 (diff) | |
| download | emacs-ff8c0648fb4dd67bfad44167e70f25a12b1149bd.tar.gz emacs-ff8c0648fb4dd67bfad44167e70f25a12b1149bd.zip | |
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.
| -rw-r--r-- | lisp/ffap.el | 16 | ||||
| -rw-r--r-- | test/lisp/ffap-tests.el | 32 |
2 files changed, 35 insertions, 13 deletions
diff --git a/lisp/ffap.el b/lisp/ffap.el index f892bb81e40..1c9f0294601 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el | |||
| @@ -1140,7 +1140,7 @@ The arguments CHARS, BEG and END are handled as described in | |||
| 1140 | "Last string returned by the function `ffap-string-at-point'.") | 1140 | "Last string returned by the function `ffap-string-at-point'.") |
| 1141 | 1141 | ||
| 1142 | (defcustom ffap-file-name-with-spaces nil | 1142 | (defcustom ffap-file-name-with-spaces nil |
| 1143 | "If non-nil, enable looking for paths with spaces in `ffap-string-at-point'. | 1143 | "If non-nil, allow file names with spaces in `ffap-string-at-point'. |
| 1144 | Enabling this variable may lead to `find-file-at-point' guessing | 1144 | Enabling this variable may lead to `find-file-at-point' guessing |
| 1145 | wrong more often when trying to find a file name intermingled | 1145 | wrong more often when trying to find a file name intermingled |
| 1146 | with normal text, but can be useful when working on systems that | 1146 | 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)'." | |||
| 1286 | (if (and ffap-file-name-with-spaces | 1286 | (if (and ffap-file-name-with-spaces |
| 1287 | (memq mode '(nil file))) | 1287 | (memq mode '(nil file))) |
| 1288 | (when (setq dir-separator (ffap-dir-separator-near-point)) | 1288 | (when (setq dir-separator (ffap-dir-separator-near-point)) |
| 1289 | (while (re-search-backward | 1289 | (let ((dirsep-re (regexp-quote dir-separator)) |
| 1290 | (regexp-quote dir-separator) | 1290 | (line-beg (line-beginning-position))) |
| 1291 | (line-beginning-position) t) | 1291 | (while (re-search-backward dirsep-re line-beg t) |
| 1292 | (goto-char (match-beginning 0)))) | 1292 | (goto-char (match-beginning 0))) |
| 1293 | (if (and (looking-at dirsep-re) | ||
| 1294 | (looking-back | ||
| 1295 | ;; Either "~[USER]" or drive letter. | ||
| 1296 | "\\(~[[:graph:]]*\\|[a-zA-Z]:\\)" | ||
| 1297 | line-beg)) | ||
| 1298 | (goto-char (match-beginning 0))))) | ||
| 1293 | (skip-chars-backward (car args)) | 1299 | (skip-chars-backward (car args)) |
| 1294 | (skip-chars-forward (nth 1 args) pt)) | 1300 | (skip-chars-forward (nth 1 args) pt)) |
| 1295 | (point)))) | 1301 | (point)))) |
diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el index 3c6e1e8e18e..ea5e745bfaf 100644 --- a/test/lisp/ffap-tests.el +++ b/test/lisp/ffap-tests.el | |||
| @@ -105,7 +105,7 @@ left alone when opening a URL in an external browser." | |||
| 105 | (with-temp-buffer | 105 | (with-temp-buffer |
| 106 | (insert string) | 106 | (insert string) |
| 107 | (goto-char (point-min)) | 107 | (goto-char (point-min)) |
| 108 | (forward-char 10) | 108 | (forward-char 3) |
| 109 | (ffap-string-at-point)))) | 109 | (ffap-string-at-point)))) |
| 110 | 110 | ||
| 111 | (ert-deftest ffap-test-with-spaces () | 111 | (ert-deftest ffap-test-with-spaces () |
| @@ -113,7 +113,7 @@ left alone when opening a URL in an external browser." | |||
| 113 | (equal | 113 | (equal |
| 114 | (ffap-test-string | 114 | (ffap-test-string |
| 115 | t "c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt") | 115 | t "c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt") |
| 116 | "/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt")) | 116 | "c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program here.txt")) |
| 117 | (should | 117 | (should |
| 118 | (equal | 118 | (equal |
| 119 | (ffap-test-string | 119 | (ffap-test-string |
| @@ -122,23 +122,39 @@ left alone when opening a URL in an external browser." | |||
| 122 | (should | 122 | (should |
| 123 | (equal | 123 | (equal |
| 124 | (ffap-test-string | 124 | (ffap-test-string |
| 125 | t "c:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/") | 125 | t "z:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/") |
| 126 | "/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/")) | 126 | "z:/Program Files/Open Text Evaluation Media/Open Text Exceed 14 x86/Program Files/Hummingbird/")) |
| 127 | (should | 127 | (should |
| 128 | (equal | 128 | (equal |
| 129 | (ffap-test-string | 129 | (ffap-test-string |
| 130 | t "c:\\Program Files\\Open Text Evaluation Media\\Open Text Exceed 14 x86\\Program Files\\Hummingbird\\") | 130 | t "c:\\Program Files\\Open Text Evaluation Media\\Open Text Exceed 14 x86\\Program Files\\Hummingbird\\") |
| 131 | "\\Program Files\\Open Text Evaluation Media\\Open Text Exceed 14 x86\\Program Files\\Hummingbird\\")) | 131 | "c:\\Program Files\\Open Text Evaluation Media\\Open Text Exceed 14 x86\\Program Files\\Hummingbird\\")) |
| 132 | (should | 132 | (should |
| 133 | (equal | 133 | (equal |
| 134 | (ffap-test-string | 134 | (ffap-test-string |
| 135 | t "c:\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt") | 135 | t "d:\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt") |
| 136 | "\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt")) | 136 | "d:\\Program Files\\Freescale\\CW for MPC55xx and MPC56xx 2.10\\PowerPC_EABI_Tools\\Command_Line_Tools\\CLT_Usage_Notes.txt")) |
| 137 | (should | 137 | (should |
| 138 | (equal | 138 | (equal |
| 139 | (ffap-test-string | 139 | (ffap-test-string |
| 140 | t "C:\\temp\\program.log on Windows or /var/log/program.log on Unix.") | 140 | t "C:\\temp\\program.log on Windows or /var/log/program.log on Unix.") |
| 141 | "\\temp\\program.log"))) | 141 | "C:\\temp\\program.log")) |
| 142 | (should | ||
| 143 | (equal | ||
| 144 | (ffap-test-string t "~/tmp/") | ||
| 145 | "~/tmp/")) | ||
| 146 | (should | ||
| 147 | (equal | ||
| 148 | (ffap-test-string nil "~/tmp/") | ||
| 149 | "~/tmp/")) | ||
| 150 | (should | ||
| 151 | (equal | ||
| 152 | (ffap-test-string t "~abc123_áè/foo") | ||
| 153 | "~abc123_áè/foo")) | ||
| 154 | (should | ||
| 155 | (equal | ||
| 156 | (ffap-test-string t "c:/Program Files/my program.exe and here's more text") | ||
| 157 | "c:/Program Files/my program.exe"))) | ||
| 142 | 158 | ||
| 143 | (ert-deftest ffap-test-no-newlines () | 159 | (ert-deftest ffap-test-no-newlines () |
| 144 | (should-not | 160 | (should-not |