From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Christophe Junke Newsgroups: gmane.emacs.bugs Subject: bug#31707: [PATCH 1/1] ido: add ido-fallback special variable Date: Mon, 4 Jun 2018 10:39:43 +0200 Message-ID: <20180604083943.13769-1-junke.christophe@gmail.com> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1528102753 9428 195.159.176.226 (4 Jun 2018 08:59:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 4 Jun 2018 08:59:13 +0000 (UTC) Cc: Christophe Junke To: 31707@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 04 10:59:09 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPlKW-0002NF-S5 for geb-bug-gnu-emacs@m.gmane.org; Mon, 04 Jun 2018 10:59:09 +0200 Original-Received: from localhost ([::1]:38407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPlMe-0003ZU-1C for geb-bug-gnu-emacs@m.gmane.org; Mon, 04 Jun 2018 05:01:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPlMQ-0003Yy-VJ for bug-gnu-emacs@gnu.org; Mon, 04 Jun 2018 05:01:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPlMM-0000Fo-M4 for bug-gnu-emacs@gnu.org; Mon, 04 Jun 2018 05:01:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52952) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPlMM-0000FN-IA for bug-gnu-emacs@gnu.org; Mon, 04 Jun 2018 05:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fPlMM-000862-7G for bug-gnu-emacs@gnu.org; Mon, 04 Jun 2018 05:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Christophe Junke Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 04 Jun 2018 09:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 31707 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.152810285031090 (code B ref -1); Mon, 04 Jun 2018 09:01:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Jun 2018 09:00:50 +0000 Original-Received: from localhost ([127.0.0.1]:60849 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPlMA-00085L-0L for submit@debbugs.gnu.org; Mon, 04 Jun 2018 05:00:50 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38327) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fPl24-0007Vs-5p for submit@debbugs.gnu.org; Mon, 04 Jun 2018 04:40:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPl1x-0004UL-UK for submit@debbugs.gnu.org; Mon, 04 Jun 2018 04:39:59 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:48854) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fPl1x-0004UF-Qf for submit@debbugs.gnu.org; Mon, 04 Jun 2018 04:39:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPl1w-0004tF-GO for bug-gnu-emacs@gnu.org; Mon, 04 Jun 2018 04:39:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPl1r-0004SX-Eg for bug-gnu-emacs@gnu.org; Mon, 04 Jun 2018 04:39:56 -0400 Original-Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:39350) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPl1r-0004SJ-7G for bug-gnu-emacs@gnu.org; Mon, 04 Jun 2018 04:39:51 -0400 Original-Received: by mail-wm0-x235.google.com with SMTP id p11-v6so12657231wmc.4 for ; Mon, 04 Jun 2018 01:39:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=1hBUhHlCS+vpYK1UCJWzVw2h0NdXhaCk+Bj/JC1l+Qg=; b=Fz5U1j+6vJDQtPpGj//2Dsvg/1mvLaB9EXSXz7GO995cXa11z9Si6cQlQ610aPwsH4 r3/Z9KVBeFJyb8ZjAeo1kM3vulp/sMse/uIxm18BRPnvb9vEqzAxgsfuT7Ci6rsbxE0c XAimoYDxqANp9MLGoCcLzfoQVzsJZz9EegnytISbOYNpf0u/7hNRWP4rcNBxt+VPycdk 67mKFQTVIY2k/HrnwG/jxAeNin+YOMYjI7eEnRSVuumvKIqEj27rUHPUoqpHnp/ElN0+ SriR/3BwrktybMm1vX6taHw9ee34HzQtuMruYG9DfiojVre2LF2ioeRFr4rA5zKDtrpC s/6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1hBUhHlCS+vpYK1UCJWzVw2h0NdXhaCk+Bj/JC1l+Qg=; b=FzVY9rjY86Qfpe6zqpWFmNiuHJHThQsNmuwK+LC1U2T6hUNz9YvwB4874v0UiJHxuI xV3sMoT74Rqsb/StHHJvX+jK97y0vOhJ+XK1/54HFhS2mKEbnH25DeaNgjQDajSO7MWO VeMqogJV3AOky9LL0PlPXwGPxNJ8GRRGtSgXZnbdW7w8qXi8ZSz74cC0jZJTE00CAVsF HooebUpCFuVKINBvDmvvvAzCuSKRivPtYRED0Y1Y07RBPiIdBMaV1yg8s145bZmTFRuE SlO6a87E4xw3xezpcDwuUaeOXTJ8akwB6bbV2ZxV0e1VrFJmNHYhe1tJ6zqzzTYrH+c8 x+6A== X-Gm-Message-State: APt69E0xh2YclHomgyxCR0zvAM3W3RLrAZna2mBWOg4SaAreAGUQ6cFi W14s4bhwYtM/pxUEqPA3amFXgcQX X-Google-Smtp-Source: ADUXVKIEKFYbpN9U6kVEszyXMlxLacVbhy45aUArr9CoCaSIkQdv7U6bIICXFO58OGUytS581+VNLQ== X-Received: by 2002:a1c:aa0c:: with SMTP id t12-v6mr8989948wme.56.1528101589725; Mon, 04 Jun 2018 01:39:49 -0700 (PDT) Original-Received: from PAD2018L060.Parrot.Biz (smtp.parrot.biz. [62.23.167.188]) by smtp.gmail.com with ESMTPSA id 44-v6sm102909926wrv.47.2018.06.04.01.39.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 01:39:48 -0700 (PDT) X-Mailer: git-send-email 2.14.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Mailman-Approved-At: Mon, 04 Jun 2018 05:00:49 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:146941 Archived-At: 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