unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#31707: [PATCH 1/1] ido: add ido-fallback special variable
@ 2018-06-04  8:39 Christophe Junke
  2018-06-09  7:00 ` Eli Zaretskii
  0 siblings, 1 reply; 17+ messages in thread
From: Christophe Junke @ 2018-06-04  8:39 UTC (permalink / raw)
  To: 31707; +Cc: Christophe Junke

The Ido module has been compiled with "lexical-binding: t" for some
time now. Previously, when the bindings were dynamic, it was possible
for other packages to modify the "fallback" variables declared inside
"ido-file-internal" and "ido-buffer-internal".

In particular, that was the case in magit-extras.el, which runs
magit-status on current path when exiting Ido. This feature is now
broken since "fallback" is lexical. For reference, the current code
for "ido-enter-magit-status" does the following:

    (with-no-warnings ; FIXME these are internal variables
      (setq ido-exit 'fallback fallback 'magit-status))
    (exit-minibuffer)

I think it would be cleaner to have it do:

    (ido-fallback-command 'magit-status)

The current patch:

- Introduces an ido-fallback special variable, which, when set,
  overrides the local, lexical, "fallback" variable; it does so only
  when ido-exit is set to 'fallback.

- Adds an optional parameter to "ido-fallback-command" that is used to
  specify which fallback command to run on exit.

* lisp/ido.el (ido-fallback): add new variable,
(ido-buffer-internal): reset ido-fallback to nil before prompting user,
(ido-buffer-internal): use ido-fallback when ido-exit is 'fallback,
(ido-file-internal): reset ido-fallback to nil before prompting user,
(ido-file-internal): use ido-fallback when ido-exit is 'fallback,
(ido-fallback-command): add optional argument fallback-command
---
 lisp/ido.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lisp/ido.el b/lisp/ido.el
index 705e7dd630..00d0f4f446 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -1242,6 +1242,9 @@ Only used if `ido-use-virtual-buffers' is non-nil.")
 ;; Dynamically bound in ido-read-internal.
 (defvar ido-completing-read)
 
+;; If dynamically set when ido-exit is 'fallback, overrides fallback command.
+(defvar ido-fallback nil)
+
 ;;; FUNCTIONS
 
 (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."
 	(run-hook-with-args 'ido-before-fallback-functions
 			    (or fallback 'switch-to-buffer))
 	(call-interactively (or fallback 'switch-to-buffer)))
+    (setq ido-fallback nil)
     (let* ((ido-context-switch-command switch-cmd)
 	   (ido-current-directory nil)
 	   (ido-directory-nonreadable nil)
@@ -2245,7 +2249,7 @@ If cursor is not at the end of the user input, move to end of input."
 
        ((eq ido-exit 'fallback)
 	(let ((read-buffer-function nil))
-	  (setq this-command (or fallback 'switch-to-buffer))
+	  (setq this-command (or ido-fallback fallback 'switch-to-buffer))
 	  (run-hook-with-args 'ido-before-fallback-functions this-command)
 	  (call-interactively this-command)))
 
@@ -2341,6 +2345,7 @@ If cursor is not at the end of the user input, move to end of input."
   ;; Internal function for ido-find-file and friends
   (unless item
     (setq item 'file))
+  (setq ido-fallback nil)
   (let ((ido-current-directory (ido-expand-directory default))
 	(ido-context-switch-command switch-cmd)
 	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."
 	;; we don't want to change directory of current buffer.
 	(let ((default-directory ido-current-directory)
 	      (read-file-name-function nil))
-	  (setq this-command (or fallback 'find-file))
+	  (setq this-command (or ido-fallback fallback 'find-file))
 	  (run-hook-with-args 'ido-before-fallback-functions this-command)
 	  (call-interactively this-command)))
 
@@ -2821,13 +2826,15 @@ If no buffer or file exactly matching the prompt exists, maybe create a new one.
   (setq ido-exit 'takeprompt)
   (exit-minibuffer))
 
-(defun ido-fallback-command ()
-  "Fallback to non-Ido version of current command."
+(defun ido-fallback-command (&optional fallback-command)
+  "Fallback to non-Ido version of current command.
+The optional fallback-command argument indicates which command to run."
   (interactive)
   (let ((i (length ido-text)))
     (while (> i 0)
       (push (aref ido-text (setq i (1- i))) unread-command-events)))
   (setq ido-exit 'fallback)
+  (setq ido-fallback fallback-command)
   (exit-minibuffer))
 
 (defun ido-enter-find-file ()
-- 
2.14.1






^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-06-26  0:40 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-04  8:39 bug#31707: [PATCH 1/1] ido: add ido-fallback special variable Christophe Junke
2018-06-09  7:00 ` Eli Zaretskii
2018-06-11  8:23   ` bug#31783: [PATCH v2] ido.el: define a special ido-fallback variable Christophe Junke
2018-06-11 12:19     ` Noam Postavsky
2018-06-11 12:54       ` Christophe Junke
2018-06-11 15:28       ` Eli Zaretskii
     [not found]         ` <CAFDFyRiHzxOB7Q6uV1hPYmuC3KfiqJRCmk=nrQ5wTPWUue_W4Q@mail.gmail.com>
2018-06-11 16:55           ` Eli Zaretskii
2018-06-22  0:34             ` Noam Postavsky
2018-06-22  6:34               ` Eli Zaretskii
2018-06-22  8:24                 ` Christophe Junke
2018-06-22  9:02                   ` Eli Zaretskii
2018-06-22 11:32                 ` Noam Postavsky
2018-06-22 12:45                   ` Eli Zaretskii
2018-06-24  1:52                     ` bug#31707: [PATCH 1/1] ido: add ido-fallback special variable Noam Postavsky
2018-06-24 14:54                       ` Eli Zaretskii
2018-06-26  0:40                         ` Noam Postavsky
2018-06-11 18:52           ` bug#31783: [PATCH v2] ido.el: define a special ido-fallback variable Christophe Junke

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).