diff options
| author | Christophe Junke | 2018-06-04 10:39:43 +0200 |
|---|---|---|
| committer | Noam Postavsky | 2018-06-25 20:05:53 -0400 |
| commit | 12c77f6918c4a60dbbae3f716a58300b4026e8da (patch) | |
| tree | 9351800b487caee3c4b369e5d42a0a328b7c5158 | |
| parent | 826e8d1f12b014617c8899936730a740a09fefb1 (diff) | |
| download | emacs-12c77f6918c4a60dbbae3f716a58300b4026e8da.tar.gz emacs-12c77f6918c4a60dbbae3f716a58300b4026e8da.zip | |
Add ido-fallback special variable (Bug#31707)
Before ido.el switch to lexical-binding, it was possible for other
packages to modify the 'fallback' variables declared inside
'ido-file-internal' and 'ido-buffer-internal'.
* lisp/ido.el (ido-fallback): New variable.
(ido-buffer-internal, ido-file-internal): Reset ido-fallback to nil
before prompting user. Use ido-fallback when ido-exit is 'fallback'.
(ido-fallback-command): Add optional FALLBACK-COMMAND argument.
Copyright-paperwork-exempt: yes
| -rw-r--r-- | lisp/ido.el | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lisp/ido.el b/lisp/ido.el index da0c9d463d1..761f02ea782 100644 --- a/lisp/ido.el +++ b/lisp/ido.el | |||
| @@ -1239,6 +1239,9 @@ Only used if `ido-use-virtual-buffers' is non-nil.") | |||
| 1239 | ;; Dynamically bound in ido-read-internal. | 1239 | ;; Dynamically bound in ido-read-internal. |
| 1240 | (defvar ido-completing-read) | 1240 | (defvar ido-completing-read) |
| 1241 | 1241 | ||
| 1242 | ;; If dynamically set when ido-exit is 'fallback, overrides fallback command. | ||
| 1243 | (defvar ido-fallback nil) | ||
| 1244 | |||
| 1242 | ;;; FUNCTIONS | 1245 | ;;; FUNCTIONS |
| 1243 | 1246 | ||
| 1244 | (defun ido-active (&optional merge) | 1247 | (defun ido-active (&optional merge) |
| @@ -2220,6 +2223,7 @@ If cursor is not at the end of the user input, move to end of input." | |||
| 2220 | (run-hook-with-args 'ido-before-fallback-functions | 2223 | (run-hook-with-args 'ido-before-fallback-functions |
| 2221 | (or fallback 'switch-to-buffer)) | 2224 | (or fallback 'switch-to-buffer)) |
| 2222 | (call-interactively (or fallback 'switch-to-buffer))) | 2225 | (call-interactively (or fallback 'switch-to-buffer))) |
| 2226 | (setq ido-fallback nil) | ||
| 2223 | (let* ((ido-context-switch-command switch-cmd) | 2227 | (let* ((ido-context-switch-command switch-cmd) |
| 2224 | (ido-current-directory nil) | 2228 | (ido-current-directory nil) |
| 2225 | (ido-directory-nonreadable nil) | 2229 | (ido-directory-nonreadable nil) |
| @@ -2245,7 +2249,7 @@ If cursor is not at the end of the user input, move to end of input." | |||
| 2245 | 2249 | ||
| 2246 | ((eq ido-exit 'fallback) | 2250 | ((eq ido-exit 'fallback) |
| 2247 | (let ((read-buffer-function nil)) | 2251 | (let ((read-buffer-function nil)) |
| 2248 | (setq this-command (or fallback 'switch-to-buffer)) | 2252 | (setq this-command (or ido-fallback fallback 'switch-to-buffer)) |
| 2249 | (run-hook-with-args 'ido-before-fallback-functions this-command) | 2253 | (run-hook-with-args 'ido-before-fallback-functions this-command) |
| 2250 | (call-interactively this-command))) | 2254 | (call-interactively this-command))) |
| 2251 | 2255 | ||
| @@ -2341,6 +2345,7 @@ If cursor is not at the end of the user input, move to end of input." | |||
| 2341 | ;; Internal function for ido-find-file and friends | 2345 | ;; Internal function for ido-find-file and friends |
| 2342 | (unless item | 2346 | (unless item |
| 2343 | (setq item 'file)) | 2347 | (setq item 'file)) |
| 2348 | (setq ido-fallback nil) | ||
| 2344 | (let ((ido-current-directory (ido-expand-directory default)) | 2349 | (let ((ido-current-directory (ido-expand-directory default)) |
| 2345 | (ido-context-switch-command switch-cmd) | 2350 | (ido-context-switch-command switch-cmd) |
| 2346 | ido-directory-nonreadable ido-directory-too-big | 2351 | ido-directory-nonreadable ido-directory-too-big |
| @@ -2412,7 +2417,7 @@ If cursor is not at the end of the user input, move to end of input." | |||
| 2412 | ;; we don't want to change directory of current buffer. | 2417 | ;; we don't want to change directory of current buffer. |
| 2413 | (let ((default-directory ido-current-directory) | 2418 | (let ((default-directory ido-current-directory) |
| 2414 | (read-file-name-function nil)) | 2419 | (read-file-name-function nil)) |
| 2415 | (setq this-command (or fallback 'find-file)) | 2420 | (setq this-command (or ido-fallback fallback 'find-file)) |
| 2416 | (run-hook-with-args 'ido-before-fallback-functions this-command) | 2421 | (run-hook-with-args 'ido-before-fallback-functions this-command) |
| 2417 | (call-interactively this-command))) | 2422 | (call-interactively this-command))) |
| 2418 | 2423 | ||
| @@ -2821,13 +2826,15 @@ If no buffer or file exactly matching the prompt exists, maybe create a new one. | |||
| 2821 | (setq ido-exit 'takeprompt) | 2826 | (setq ido-exit 'takeprompt) |
| 2822 | (exit-minibuffer)) | 2827 | (exit-minibuffer)) |
| 2823 | 2828 | ||
| 2824 | (defun ido-fallback-command () | 2829 | (defun ido-fallback-command (&optional fallback-command) |
| 2825 | "Fallback to non-Ido version of current command." | 2830 | "Fallback to non-Ido version of current command. |
| 2831 | The optional FALLBACK-COMMAND argument indicates which command to run." | ||
| 2826 | (interactive) | 2832 | (interactive) |
| 2827 | (let ((i (length ido-text))) | 2833 | (let ((i (length ido-text))) |
| 2828 | (while (> i 0) | 2834 | (while (> i 0) |
| 2829 | (push (aref ido-text (setq i (1- i))) unread-command-events))) | 2835 | (push (aref ido-text (setq i (1- i))) unread-command-events))) |
| 2830 | (setq ido-exit 'fallback) | 2836 | (setq ido-exit 'fallback) |
| 2837 | (setq ido-fallback fallback-command) | ||
| 2831 | (exit-minibuffer)) | 2838 | (exit-minibuffer)) |
| 2832 | 2839 | ||
| 2833 | (defun ido-enter-find-file () | 2840 | (defun ido-enter-find-file () |