diff options
| author | Stefan Monnier | 2008-04-21 21:01:38 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2008-04-21 21:01:38 +0000 |
| commit | 984ddcbcef9ca63d62eeec38f8609b75723ff122 (patch) | |
| tree | 4597dd7a515f7820c1d4a0f9dd29fab826b231bb | |
| parent | ec50e665d22b1a632c7a00daf9f81249879148b4 (diff) | |
| download | emacs-984ddcbcef9ca63d62eeec38f8609b75723ff122.tar.gz emacs-984ddcbcef9ca63d62eeec38f8609b75723ff122.zip | |
(ffap-read-file-or-url): Do not abuse completing-read's
`predicate' argument to pass non-predicate data.
(ffap-read-url-internal, ffap-read-file-or-url-internal):
Use second arg as proper predicate.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/ffap.el | 45 |
2 files changed, 27 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5bfdcd1a1de..00cddb6f17d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2008-04-21 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2008-04-21 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * ffap.el (ffap-read-file-or-url): Do not abuse completing-read's | ||
| 4 | `predicate' argument to pass non-predicate data. | ||
| 5 | (ffap-read-url-internal, ffap-read-file-or-url-internal): | ||
| 6 | Use second arg as proper predicate. | ||
| 7 | |||
| 3 | * vc-bzr.el (vc-bzr-complete-with-prefix): Remove. | 8 | * vc-bzr.el (vc-bzr-complete-with-prefix): Remove. |
| 4 | (vc-bzr-revision-completion-table): Use completion-table-with-context | 9 | (vc-bzr-revision-completion-table): Use completion-table-with-context |
| 5 | instead. | 10 | instead. |
diff --git a/lisp/ffap.el b/lisp/ffap.el index d1dc36b3e9f..eaa7e3a3f1b 100644 --- a/lisp/ffap.el +++ b/lisp/ffap.el | |||
| @@ -922,7 +922,7 @@ If t, `ffap-tex-init' will initialize this when needed.") | |||
| 922 | (ffap-locate-file name t ffap-bib-path)) | 922 | (ffap-locate-file name t ffap-bib-path)) |
| 923 | 923 | ||
| 924 | (defun ffap-dired (name) | 924 | (defun ffap-dired (name) |
| 925 | (let ((pt (point)) dir try) | 925 | (let ((pt (point)) try) |
| 926 | (save-excursion | 926 | (save-excursion |
| 927 | (and (progn | 927 | (and (progn |
| 928 | (beginning-of-line) | 928 | (beginning-of-line) |
| @@ -1279,15 +1279,17 @@ which may actually result in an url rather than a filename." | |||
| 1279 | (push fnh-elem file-name-handler-alist) | 1279 | (push fnh-elem file-name-handler-alist) |
| 1280 | (unwind-protect | 1280 | (unwind-protect |
| 1281 | (setq guess | 1281 | (setq guess |
| 1282 | (completing-read | 1282 | (let ((default-directory (if dir (expand-file-name dir) |
| 1283 | prompt | 1283 | default-directory))) |
| 1284 | 'ffap-read-file-or-url-internal | 1284 | (completing-read |
| 1285 | dir | 1285 | prompt |
| 1286 | nil | 1286 | 'ffap-read-file-or-url-internal |
| 1287 | (if dir (cons guess (length dir)) guess) | 1287 | nil |
| 1288 | (list 'file-name-history) | 1288 | nil |
| 1289 | (and buffer-file-name | 1289 | (if dir (cons guess (length dir)) guess) |
| 1290 | (abbreviate-file-name buffer-file-name)))) | 1290 | (list 'file-name-history) |
| 1291 | (and buffer-file-name | ||
| 1292 | (abbreviate-file-name buffer-file-name))))) | ||
| 1291 | ;; Remove the special handler manually. We used to just let-bind | 1293 | ;; Remove the special handler manually. We used to just let-bind |
| 1292 | ;; file-name-handler-alist to preserve its value, but that caused | 1294 | ;; file-name-handler-alist to preserve its value, but that caused |
| 1293 | ;; other modifications to be lost (e.g. when Tramp gets loaded | 1295 | ;; other modifications to be lost (e.g. when Tramp gets loaded |
| @@ -1299,26 +1301,24 @@ which may actually result in an url rather than a filename." | |||
| 1299 | ;; Note: upcoming url.el package ought to handle this automatically. | 1301 | ;; Note: upcoming url.el package ought to handle this automatically. |
| 1300 | guess)) | 1302 | guess)) |
| 1301 | 1303 | ||
| 1302 | (defun ffap-read-url-internal (string dir action) | 1304 | (defun ffap-read-url-internal (string pred action) |
| 1303 | "Complete url's from history, treating given string as valid." | 1305 | "Complete url's from history, treating given string as valid." |
| 1304 | (let ((hist (ffap-soft-value "url-global-history-hash-table"))) | 1306 | (let ((hist (ffap-soft-value "url-global-history-hash-table"))) |
| 1305 | (cond | 1307 | (cond |
| 1306 | ((not action) | 1308 | ((not action) |
| 1307 | (or (try-completion string hist) string)) | 1309 | (or (try-completion string hist pred) string)) |
| 1308 | ((eq action t) | 1310 | ((eq action t) |
| 1309 | (or (all-completions string hist) (list string))) | 1311 | (or (all-completions string hist pred) (list string))) |
| 1310 | ;; action == lambda, documented where? Tests whether string is a | 1312 | ;; action == lambda, documented where? Tests whether string is a |
| 1311 | ;; valid "match". Let us always say yes. | 1313 | ;; valid "match". Let us always say yes. |
| 1312 | (t t)))) | 1314 | (t t)))) |
| 1313 | 1315 | ||
| 1314 | (defun ffap-read-file-or-url-internal (string dir action) | 1316 | (defun ffap-read-file-or-url-internal (string pred action) |
| 1315 | (unless dir | 1317 | (unless string ;Why would this ever happen? |
| 1316 | (setq dir default-directory)) | ||
| 1317 | (unless string | ||
| 1318 | (setq string default-directory)) | 1318 | (setq string default-directory)) |
| 1319 | (if (ffap-url-p string) | 1319 | (if (ffap-url-p string) |
| 1320 | (ffap-read-url-internal string dir action) | 1320 | (ffap-read-url-internal string pred action) |
| 1321 | (read-file-name-internal string dir action))) | 1321 | (read-file-name-internal string pred action))) |
| 1322 | 1322 | ||
| 1323 | ;; The rest of this page is just to work with package complete.el. | 1323 | ;; The rest of this page is just to work with package complete.el. |
| 1324 | ;; This code assumes that you load ffap.el after complete.el. | 1324 | ;; This code assumes that you load ffap.el after complete.el. |
| @@ -1523,7 +1523,7 @@ Function CONT is applied to the entry chosen by the user." | |||
| 1523 | (x-popup-menu | 1523 | (x-popup-menu |
| 1524 | t | 1524 | t |
| 1525 | (list "" (cons title | 1525 | (list "" (cons title |
| 1526 | (mapcar (function (lambda (i) (cons (car i) i))) | 1526 | (mapcar (lambda (i) (cons (car i) i)) |
| 1527 | alist)))))) | 1527 | alist)))))) |
| 1528 | ;; minibuffer with completion buffer: | 1528 | ;; minibuffer with completion buffer: |
| 1529 | (t | 1529 | (t |
| @@ -1537,8 +1537,7 @@ Function CONT is applied to the entry chosen by the user." | |||
| 1537 | nil))) | 1537 | nil))) |
| 1538 | (sit-for 0) ; redraw original screen | 1538 | (sit-for 0) ; redraw original screen |
| 1539 | ;; Convert string to its entry, or else the default: | 1539 | ;; Convert string to its entry, or else the default: |
| 1540 | (setq choice (or (assoc choice alist) (car alist)))) | 1540 | (setq choice (or (assoc choice alist) (car alist))))) |
| 1541 | ) | ||
| 1542 | (if choice | 1541 | (if choice |
| 1543 | (funcall cont choice) | 1542 | (funcall cont choice) |
| 1544 | (message "No choice made!") ; possible with menus | 1543 | (message "No choice made!") ; possible with menus |
| @@ -1569,7 +1568,7 @@ Applies `ffap-menu-text-plist' text properties at all matches." | |||
| 1569 | ffap-menu-text-plist) | 1568 | ffap-menu-text-plist) |
| 1570 | (message "Scanning...%2d%% <%s>" | 1569 | (message "Scanning...%2d%% <%s>" |
| 1571 | (/ (* 100 (- (point) (point-min))) range) item))) | 1570 | (/ (* 100 (- (point) (point-min))) range) item))) |
| 1572 | (or mod (set-buffer-modified-p nil)))) | 1571 | (or mod (restore-buffer-modified-p nil)))) |
| 1573 | (message "Scanning...done") | 1572 | (message "Scanning...done") |
| 1574 | ;; Remove duplicates. | 1573 | ;; Remove duplicates. |
| 1575 | (setq ffap-menu-alist ; sort by item | 1574 | (setq ffap-menu-alist ; sort by item |