unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#17000: setup ido keymaps only once
@ 2014-03-12 19:35 Jonas Bernoulli
  2014-03-12 23:36 ` Stefan Monnier
  2015-01-18 15:17 ` Oleh Krehel
  0 siblings, 2 replies; 11+ messages in thread
From: Jonas Bernoulli @ 2014-03-12 19:35 UTC (permalink / raw)
  To: 17000

Currently the ido keymaps are hard to modify because they are recreated
every time `ido-completing-read' is used.  This forces users to add a
function to `ido-minibuffer-setup' and do their `define-key's there.

I believe it is safe for the "base" ido keymaps to set the value when
the variable is defined, instead of delaying this until ido is actually
used, and then redoing that work whenever `ido-completing-read' is
called.

These are the keymaps which are currently set in `ido-init-completion-maps':
  ido-common-completion-map
  ido-file-completion-map
  ido-file-dir-completion-map
  ido-buffer-completion-map

`ido-completion-map' is different, it's a kind of "current-local-map".
Its value is set in `ido-setup-completion-map' by creating a new sparse
keymap, setting its parent to one of the above keymaps (depending on
what is currently being completed) and then possibly making some
adjustments depending on `ido-context-switch-command' and `viper-mode'.

`ido-setup-completion-map' is called every time `ido-read-internal' is
called, i.e. every time the user actually uses ido completion.  Therefor
`ido-completion-map' is set every time ido completion is used and so it
is safe to modify it using `ido-minibuffer-setup-hook' for just this one
call.

`ido-init-completion-maps' is *not* called every time ido completion is
used.  It is called only in `ido-common-initialization' which is called
only in `ido-mode' and `ido-completion-read', but not in
`ido-read-internal'.  The reason why `ido-completion-read' has to do the
common initialization is simple: it may be used by users and packages to
complete certain things without also using ido completion for everything
`ido-mode' itself supports.

Besides the initialization of the keymaps the "common initialization"
also includes adding functions to hooks.  I am arguing that the latter
should stay but that the keymaps shouldn't be recreated here and that it
is backward compatible to make that change.

While it is possible that some third-party code modifies one of the
`ido-*-completion-map's by using `ido-minibuffer-setup', that would be
a bug.  Instead the "final keymap", `ido-completion-map', should be
modified.  Even without the proposed change modifying one of the
`ido-*-completion-map's when using `ido-completing-read' with the
intention of having that only affect the current invocation would
actually affect later uses of ido completion because only
`ido-completing-read' re-runs `ido-init-completion-maps',
`ido-read-internal' does *not* do that.  Therefore changes to these
keymaps would remain in effect until the next time `ido-completing-read'
is used, uses of `ido-read-internal' that happen in between would use
the modified map.

  Best regards,
  Jonas

---

diff --git a/lisp/ido.el b/lisp/ido.el
index b16ab1f..b4a3b28 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -978,25 +978,96 @@ The fallback command is passed as an argument to the functions."
   :type 'hook
   :group 'ido)
 
-;;; Internal Variables
-
-;; Persistent variables
-
-(defvar ido-completion-map nil
-  "Currently active keymap for Ido commands.")
+;; Keymaps
 
-(defvar ido-common-completion-map nil
+(defvar ido-common-completion-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-a" 'ido-toggle-ignore)
+    (define-key map "\C-c" 'ido-toggle-case)
+    (define-key map "\C-e" 'ido-edit-input)
+    (define-key map "\t" 'ido-complete)
+    (define-key map " " 'ido-complete-space)
+    (define-key map "\C-j" 'ido-select-text)
+    (define-key map "\C-m" 'ido-exit-minibuffer)
+    (define-key map "\C-p" 'ido-toggle-prefix)
+    (define-key map "\C-r" 'ido-prev-match)
+    (define-key map "\C-s" 'ido-next-match)
+    (define-key map [?\C-.] 'ido-next-match)
+    (define-key map [?\C-,] 'ido-prev-match)
+    (define-key map "\C-t" 'ido-toggle-regexp)
+    (define-key map "\C-z" 'ido-undo-merge-work-directory)
+    (define-key map [(control ?\s)] 'ido-restrict-to-matches)
+    (define-key map [(meta ?\s)] 'ido-take-first-match)
+    (define-key map [(control ?@)] 'ido-restrict-to-matches)
+    (define-key map [right] 'ido-next-match)
+    (define-key map [left] 'ido-prev-match)
+    (define-key map "?" 'ido-completion-help)
+    ;; Magic commands.
+    (define-key map "\C-b" 'ido-magic-backward-char)
+    (define-key map "\C-f" 'ido-magic-forward-char)
+    (define-key map "\C-d" 'ido-magic-delete-char)
+    (set-keymap-parent map minibuffer-local-map)
+    (setq ido-common-completion-map map))
   "Keymap for all Ido commands.")
 
-(defvar ido-file-completion-map nil
+(defvar ido-file-completion-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-k" 'ido-delete-file-at-head)
+    (define-key map "\C-o" 'ido-copy-current-word)
+    (define-key map "\C-w" 'ido-copy-current-file-name)
+    (define-key map [(meta ?l)] 'ido-toggle-literal)
+    (set-keymap-parent map ido-file-dir-completion-map)
+    (setq ido-file-completion-map map))
   "Keymap for Ido file commands.")
 
-(defvar ido-file-dir-completion-map nil
+(defvar ido-file-dir-completion-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-x\C-b" 'ido-enter-switch-buffer)
+    (define-key map "\C-x\C-f" 'ido-fallback-command)
+    (define-key map "\C-x\C-d" 'ido-enter-dired)
+    (define-key map [down] 'ido-next-match-dir)
+    (define-key map [up]   'ido-prev-match-dir)
+    (define-key map [(meta up)] 'ido-prev-work-directory)
+    (define-key map [(meta down)] 'ido-next-work-directory)
+    (define-key map [backspace] 'ido-delete-backward-updir)
+    (define-key map "\d"        'ido-delete-backward-updir)
+    (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS
+    (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir)  ; M-DEL
+
+    (define-key map [(control backspace)] 'ido-up-directory)
+    (define-key map "\C-l" 'ido-reread-directory)
+    (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir)
+    (define-key map [(meta ?b)] 'ido-push-dir)
+    (define-key map [(meta ?v)] 'ido-push-dir-first)
+    (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir)
+    (define-key map [(meta ?k)] 'ido-forget-work-directory)
+    (define-key map [(meta ?m)] 'ido-make-directory)
+    (define-key map [(meta ?n)] 'ido-next-work-directory)
+    (define-key map [(meta ?o)] 'ido-prev-work-file)
+    (define-key map [(meta control ?o)] 'ido-next-work-file)
+    (define-key map [(meta ?p)] 'ido-prev-work-directory)
+    (define-key map [(meta ?s)] 'ido-merge-work-directories)
+    (set-keymap-parent map ido-common-completion-map)
+    (setq ido-file-dir-completion-map map))
   "Keymap for Ido file and directory commands.")
 
-(defvar ido-buffer-completion-map nil
+(defvar ido-buffer-completion-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-x\C-f" 'ido-enter-find-file)
+    (define-key map "\C-x\C-b" 'ido-fallback-command)
+    (define-key map "\C-k" 'ido-kill-buffer-at-head)
+    (define-key map "\C-o" 'ido-toggle-virtual-buffers)
+    (set-keymap-parent map ido-common-completion-map)
+    (setq ido-buffer-completion-map map))
   "Keymap for Ido buffer commands.")
 
+;;; Internal Variables
+
+;; Persistent variables
+
+(defvar ido-completion-map nil
+  "Currently active keymap for Ido commands.")
+
 (defvar  ido-file-history nil
   "History of files selected using `ido-find-file'.")
 
@@ -1503,7 +1574,6 @@ Removes badly formatted data and ignored directories."
   (ido-save-history))
 
 (defun ido-common-initialization ()
-  (ido-init-completion-maps)
   (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup)
   (add-hook 'choose-completion-string-functions 'ido-choose-completion-string))
 
@@ -1597,90 +1667,22 @@ This function also adds a hook to the minibuffer."
 
 
 ;;; IDO KEYMAP
-(defun ido-init-completion-maps ()
-  "Set up the completion keymaps used by Ido."
-
-  ;; Common map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-a" 'ido-toggle-ignore)
-    (define-key map "\C-c" 'ido-toggle-case)
-    (define-key map "\C-e" 'ido-edit-input)
-    (define-key map "\t" 'ido-complete)
-    (define-key map " " 'ido-complete-space)
-    (define-key map "\C-j" 'ido-select-text)
-    (define-key map "\C-m" 'ido-exit-minibuffer)
-    (define-key map "\C-p" 'ido-toggle-prefix)
-    (define-key map "\C-r" 'ido-prev-match)
-    (define-key map "\C-s" 'ido-next-match)
-    (define-key map [?\C-.] 'ido-next-match)
-    (define-key map [?\C-,] 'ido-prev-match)
-    (define-key map "\C-t" 'ido-toggle-regexp)
-    (define-key map "\C-z" 'ido-undo-merge-work-directory)
-    (define-key map [(control ?\s)] 'ido-restrict-to-matches)
-    (define-key map [(meta ?\s)] 'ido-take-first-match)
-    (define-key map [(control ?@)] 'ido-restrict-to-matches)
-    (define-key map [right] 'ido-next-match)
-    (define-key map [left] 'ido-prev-match)
-    (define-key map "?" 'ido-completion-help)
-    ;; Magic commands.
-    (define-key map "\C-b" 'ido-magic-backward-char)
-    (define-key map "\C-f" 'ido-magic-forward-char)
-    (define-key map "\C-d" 'ido-magic-delete-char)
-    (set-keymap-parent map minibuffer-local-map)
-    (setq ido-common-completion-map map))
-
-  ;; File and directory map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-x\C-b" 'ido-enter-switch-buffer)
-    (define-key map "\C-x\C-f" 'ido-fallback-command)
-    (define-key map "\C-x\C-d" 'ido-enter-dired)
-    (define-key map [down] 'ido-next-match-dir)
-    (define-key map [up]   'ido-prev-match-dir)
-    (define-key map [(meta up)] 'ido-prev-work-directory)
-    (define-key map [(meta down)] 'ido-next-work-directory)
-    (define-key map [backspace] 'ido-delete-backward-updir)
-    (define-key map "\d"        'ido-delete-backward-updir)
-    (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS
-    (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir)  ; M-DEL
-
-    (define-key map [(control backspace)] 'ido-up-directory)
-    (define-key map "\C-l" 'ido-reread-directory)
-    (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir)
-    (define-key map [(meta ?b)] 'ido-push-dir)
-    (define-key map [(meta ?v)] 'ido-push-dir-first)
-    (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir)
-    (define-key map [(meta ?k)] 'ido-forget-work-directory)
-    (define-key map [(meta ?m)] 'ido-make-directory)
-    (define-key map [(meta ?n)] 'ido-next-work-directory)
-    (define-key map [(meta ?o)] 'ido-prev-work-file)
-    (define-key map [(meta control ?o)] 'ido-next-work-file)
-    (define-key map [(meta ?p)] 'ido-prev-work-directory)
-    (define-key map [(meta ?s)] 'ido-merge-work-directories)
-    (set-keymap-parent map ido-common-completion-map)
-    (setq ido-file-dir-completion-map map))
 
-  ;; File only map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-k" 'ido-delete-file-at-head)
-    (define-key map "\C-o" 'ido-copy-current-word)
-    (define-key map "\C-w" 'ido-copy-current-file-name)
-    (define-key map [(meta ?l)] 'ido-toggle-literal)
-    (set-keymap-parent map ido-file-dir-completion-map)
-    (setq ido-file-completion-map map))
+(defun ido-setup-completion-map ()
+  "Set up the keymap for Ido.
 
-  ;; Buffer map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-x\C-f" 'ido-enter-find-file)
-    (define-key map "\C-x\C-b" 'ido-fallback-command)
-    (define-key map "\C-k" 'ido-kill-buffer-at-head)
-    (define-key map "\C-o" 'ido-toggle-virtual-buffers)
-    (set-keymap-parent map ido-common-completion-map)
-    (setq ido-buffer-completion-map map)))
+Create a keymap and depending on what is being completed set its
+parent to one of:
 
+  `ido-common-completion-map'
+  `ido-file-dir-completion-map'
+  `ido-file-completion-map'
+  `ido-buffer-completion-map'
 
-(defun ido-setup-completion-map ()
-  "Set up the keymap for Ido."
+If option `ido-context-switch-command' is non-nil or `viper-mode'
+is enabled some keybindings are changed in the keymap.
 
+Finally `ido-completion-map' is bound to the keymap."
   ;; generated every time so that it can inherit new functions.
   (let ((map (make-sparse-keymap))
 	(viper-p (if (boundp 'viper-mode) viper-mode)))





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

* bug#17000: setup ido keymaps only once
  2014-03-12 19:35 bug#17000: setup ido keymaps only once Jonas Bernoulli
@ 2014-03-12 23:36 ` Stefan Monnier
  2014-03-13 15:35   ` Jonas Bernoulli
  2014-12-23  2:07   ` Leo Liu
  2015-01-18 15:17 ` Oleh Krehel
  1 sibling, 2 replies; 11+ messages in thread
From: Stefan Monnier @ 2014-03-12 23:36 UTC (permalink / raw)
  To: Jonas Bernoulli; +Cc: 17000

> Currently the ido keymaps are hard to modify because they are recreated
> every time `ido-completing-read' is used.

Indeed, this is wrong.

> I believe it is safe for the "base" ido keymaps to set the value when
> the variable is defined, instead of delaying this until ido is actually
> used, and then redoing that work whenever `ido-completing-read' is
> called.

Agreed.

> -(defvar ido-common-completion-map nil
> +(defvar ido-common-completion-map
> +  (let ((map (make-sparse-keymap)))
[...]
> +    (set-keymap-parent map minibuffer-local-map)
> +    (setq ido-common-completion-map map))

This last line should just be "map)".  Same for the other maps.

Looks good.  Please apply after the trunk re-opens.


        Stefan "Beware: I don't use IDO and don't know its code"





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

* bug#17000: setup ido keymaps only once
  2014-03-12 23:36 ` Stefan Monnier
@ 2014-03-13 15:35   ` Jonas Bernoulli
  2014-12-08 23:39     ` Lars Magne Ingebrigtsen
  2014-12-22 18:53     ` Jonas Bernoulli
  2014-12-23  2:07   ` Leo Liu
  1 sibling, 2 replies; 11+ messages in thread
From: Jonas Bernoulli @ 2014-03-13 15:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 17000

> This last line should just be "map)".  Same for the other maps.
> Looks good.  Please apply after the trunk re-opens.

Once the trunk re-opens I will submit a new patch with this fixed
and which includes the necessary changelog entry.

>         Stefan "Beware: I don't use IDO and don't know its code"

  Jonas "Who was bothered by this so much he didn't use IDO until now" :-)





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

* bug#17000: setup ido keymaps only once
  2014-03-13 15:35   ` Jonas Bernoulli
@ 2014-12-08 23:39     ` Lars Magne Ingebrigtsen
  2014-12-10  9:15       ` Jonas Bernoulli
  2014-12-22 18:53     ` Jonas Bernoulli
  1 sibling, 1 reply; 11+ messages in thread
From: Lars Magne Ingebrigtsen @ 2014-12-08 23:39 UTC (permalink / raw)
  To: Jonas Bernoulli; +Cc: 17000

Jonas Bernoulli <jonas@bernoul.li> writes:

>> This last line should just be "map)".  Same for the other maps.
>> Looks good.  Please apply after the trunk re-opens.
>
> Once the trunk re-opens I will submit a new patch with this fixed
> and which includes the necessary changelog entry.
>
>>         Stefan "Beware: I don't use IDO and don't know its code"
>
>   Jonas "Who was bothered by this so much he didn't use IDO until now" :-)

The trunk is open now if you have an updated version of this patch...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#17000: setup ido keymaps only once
  2014-12-08 23:39     ` Lars Magne Ingebrigtsen
@ 2014-12-10  9:15       ` Jonas Bernoulli
  0 siblings, 0 replies; 11+ messages in thread
From: Jonas Bernoulli @ 2014-12-10  9:15 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: 17000


Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> Jonas Bernoulli <jonas@bernoul.li> writes:
>
>>> This last line should just be "map)".  Same for the other maps.
>>> Looks good.  Please apply after the trunk re-opens.
>>
>> Once the trunk re-opens I will submit a new patch with this fixed
>> and which includes the necessary changelog entry.
>>
>>>         Stefan "Beware: I don't use IDO and don't know its code"
>>
>>   Jonas "Who was bothered by this so much he didn't use IDO until now" :-)
>
> The trunk is open now if you have an updated version of this patch...

Yes I know, thanks.  This is fairly high up on my todo list.
I'll test a bit and then post a new version.





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

* bug#17000: setup ido keymaps only once
  2014-03-13 15:35   ` Jonas Bernoulli
  2014-12-08 23:39     ` Lars Magne Ingebrigtsen
@ 2014-12-22 18:53     ` Jonas Bernoulli
  1 sibling, 0 replies; 11+ messages in thread
From: Jonas Bernoulli @ 2014-12-22 18:53 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 17000

[-- Attachment #1: Type: text/plain, Size: 327 bytes --]

> Once the trunk re-opens I will submit a new patch with this fixed
> and which includes the necessary changelog entry.

Here we go.  I hope I got the metadata mostly right.

I have used this, along with various third-party ido extensions,
for a while now (with 24.4 though) and without any problems.

  Best regards,
  Jonas


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Define-ido-keymaps-when-the-variables-are-defined.patch --]
[-- Type: text/x-diff, Size: 13836 bytes --]

From a4111f92676c87a179f9ec21782c6939537a564b Mon Sep 17 00:00:00 2001
From: Jonas Bernoulli <jonas@bernoul.li>
Date: Mon, 22 Dec 2014 19:45:46 +0100
Subject: [PATCH] Define ido keymaps when the variables are defined.

Instead of redefining the ido keymaps using `ido-init-completxion-maps'
every time `ido-completing-read' is used, set them up once in the
respective `defvar' forms.  The actual keymap used during completion
is still a keymap which has one of the ido keymaps as parent, so it is
possible to modify bindings without that affecting future invocations.

Fixes: debbugs:17000

* lisp/ido: define keymaps once
(ido-common-completion-map, ido-file-dir-completion-map)
(ido-file-completion-map, ido-buffer-completion-map): Setup key bindings
when variable is defined.
(ido-completion-map): Move definition.
(ido-init-completion-maps): Noop.
(ido-common-initialization): Don't call it.
(ido-setup-completion-map): Improve doc-string, cleanup.
---
 lisp/ChangeLog |  11 +++
 lisp/ido.el    | 222 +++++++++++++++++++++++++++++----------------------------
 2 files changed, 123 insertions(+), 110 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d8bb1c8..32884eb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
+2014-12-22  Jonas Bernoulli  <jonas@bernoul.li>
+
+	* lisp/ido: define keymaps once (bug#17000)
+	(ido-common-completion-map, ido-file-dir-completion-map)
+	(ido-file-completion-map, ido-buffer-completion-map): Setup key bindings
+	when variable is defined.
+	(ido-completion-map): Move definition.
+	(ido-init-completion-maps): Noop.
+	(ido-common-initialization): Don't call it.
+	(ido-setup-completion-map): Improve doc-string, cleanup.
+
 2014-12-22  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* completion.el: Use post-self-insert-hook (bug#19400).
diff --git a/lisp/ido.el b/lisp/ido.el
index 5f7637c..c8f0338 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -324,7 +324,8 @@
 (defvar recentf-list)
 
 ;;; User Variables
-;;
+;;;; Options
+
 ;; These are some things you might want to change.
 
 (defun ido-fractionp (n)
@@ -978,25 +979,92 @@ (defcustom ido-before-fallback-functions '()
   :type 'hook
   :group 'ido)
 
-;;; Internal Variables
-
-;; Persistent variables
-
-(defvar ido-completion-map nil
-  "Currently active keymap for Ido commands.")
+;;;; Keymaps
 
-(defvar ido-common-completion-map nil
+(defvar ido-common-completion-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map minibuffer-local-map)
+    (define-key map "\C-a" 'ido-toggle-ignore)
+    (define-key map "\C-c" 'ido-toggle-case)
+    (define-key map "\C-e" 'ido-edit-input)
+    (define-key map "\t" 'ido-complete)
+    (define-key map " " 'ido-complete-space)
+    (define-key map "\C-j" 'ido-select-text)
+    (define-key map "\C-m" 'ido-exit-minibuffer)
+    (define-key map "\C-p" 'ido-toggle-prefix)
+    (define-key map "\C-r" 'ido-prev-match)
+    (define-key map "\C-s" 'ido-next-match)
+    (define-key map [?\C-.] 'ido-next-match)
+    (define-key map [?\C-,] 'ido-prev-match)
+    (define-key map "\C-t" 'ido-toggle-regexp)
+    (define-key map "\C-z" 'ido-undo-merge-work-directory)
+    (define-key map [(control ?\s)] 'ido-restrict-to-matches)
+    (define-key map [(meta ?\s)] 'ido-take-first-match)
+    (define-key map [(control ?@)] 'ido-restrict-to-matches)
+    (define-key map [right] 'ido-next-match)
+    (define-key map [left] 'ido-prev-match)
+    (define-key map "?" 'ido-completion-help)
+    (define-key map "\C-b" 'ido-magic-backward-char)
+    (define-key map "\C-f" 'ido-magic-forward-char)
+    (define-key map "\C-d" 'ido-magic-delete-char)
+    map)
   "Keymap for all Ido commands.")
 
-(defvar ido-file-completion-map nil
-  "Keymap for Ido file commands.")
-
-(defvar ido-file-dir-completion-map nil
+(defvar ido-file-dir-completion-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map ido-common-completion-map)
+    (define-key map "\C-x\C-b" 'ido-enter-switch-buffer)
+    (define-key map "\C-x\C-f" 'ido-fallback-command)
+    (define-key map "\C-x\C-d" 'ido-enter-dired)
+    (define-key map [down] 'ido-next-match-dir)
+    (define-key map [up]   'ido-prev-match-dir)
+    (define-key map [(meta up)] 'ido-prev-work-directory)
+    (define-key map [(meta down)] 'ido-next-work-directory)
+    (define-key map [backspace] 'ido-delete-backward-updir)
+    (define-key map "\d"        'ido-delete-backward-updir)
+    (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS
+    (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir)  ; M-DEL
+    (define-key map [(control backspace)] 'ido-up-directory)
+    (define-key map "\C-l" 'ido-reread-directory)
+    (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir)
+    (define-key map [(meta ?b)] 'ido-push-dir)
+    (define-key map [(meta ?v)] 'ido-push-dir-first)
+    (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir)
+    (define-key map [(meta ?k)] 'ido-forget-work-directory)
+    (define-key map [(meta ?m)] 'ido-make-directory)
+    (define-key map [(meta ?n)] 'ido-next-work-directory)
+    (define-key map [(meta ?o)] 'ido-prev-work-file)
+    (define-key map [(meta control ?o)] 'ido-next-work-file)
+    (define-key map [(meta ?p)] 'ido-prev-work-directory)
+    (define-key map [(meta ?s)] 'ido-merge-work-directories)
+    map)
   "Keymap for Ido file and directory commands.")
 
-(defvar ido-buffer-completion-map nil
+(defvar ido-file-completion-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map ido-file-dir-completion-map)
+    (define-key map "\C-k" 'ido-delete-file-at-head)
+    (define-key map "\C-o" 'ido-copy-current-word)
+    (define-key map "\C-w" 'ido-copy-current-file-name)
+    (define-key map [(meta ?l)] 'ido-toggle-literal)
+    map)
+  "Keymap for Ido file commands.")
+
+(defvar ido-buffer-completion-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map ido-common-completion-map)
+    (define-key map "\C-x\C-f" 'ido-enter-find-file)
+    (define-key map "\C-x\C-b" 'ido-fallback-command)
+    (define-key map "\C-k" 'ido-kill-buffer-at-head)
+    (define-key map [?\C-\S-b] 'ido-bury-buffer-at-head)
+    (define-key map "\C-o" 'ido-toggle-virtual-buffers)
+    map)
   "Keymap for Ido buffer commands.")
 
+;;; Internal Variables
+
+;;;; Persistent variables
+
 (defvar  ido-file-history nil
   "History of files selected using `ido-find-file'.")
 
@@ -1027,7 +1095,10 @@ (defvar ido-ignore-item-temp-list nil
 Intended to be let-bound by functions which call Ido repeatedly.
 Should never be set permanently.")
 
-;; Temporary storage
+;;;; Temporary storage
+
+(defvar ido-completion-map nil
+  "Currently active keymap for Ido commands.")
 
 (defvar ido-eoinput 1
   "Point where minibuffer input ends and completion info begins.
@@ -1086,13 +1157,14 @@ (defvar ido-virtual-buffers nil
 This is a copy of `recentf-list', pared down and with faces applied.
 Only used if `ido-use-virtual-buffers' is non-nil.")
 
-;;; Variables with dynamic bindings.
-;;; Declared here to keep the byte compiler quiet.
+;;;; Variables with dynamic bindings.
+
+;; These are declared here to keep the byte compiler quiet.
 
 ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list).
 (defvar ido-cur-item)
 
-;;; Stores the current default item
+;; Stores the current default item
 (defvar ido-default-item)
 
 ;; Stores the current list of items that will be searched through.
@@ -1502,7 +1574,6 @@ (defun ido-kill-emacs-hook ()
   (ido-save-history))
 
 (defun ido-common-initialization ()
-  (ido-init-completion-maps)
   (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup)
   (add-hook 'choose-completion-string-functions 'ido-choose-completion-string))
 
@@ -1596,120 +1667,51 @@ (defun ido-mode (&optional arg)
 
 
 ;;; IDO KEYMAP
-(defun ido-init-completion-maps ()
-  "Set up the completion keymaps used by Ido."
-
-  ;; Common map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-a" 'ido-toggle-ignore)
-    (define-key map "\C-c" 'ido-toggle-case)
-    (define-key map "\C-e" 'ido-edit-input)
-    (define-key map "\t" 'ido-complete)
-    (define-key map " " 'ido-complete-space)
-    (define-key map "\C-j" 'ido-select-text)
-    (define-key map "\C-m" 'ido-exit-minibuffer)
-    (define-key map "\C-p" 'ido-toggle-prefix)
-    (define-key map "\C-r" 'ido-prev-match)
-    (define-key map "\C-s" 'ido-next-match)
-    (define-key map [?\C-.] 'ido-next-match)
-    (define-key map [?\C-,] 'ido-prev-match)
-    (define-key map "\C-t" 'ido-toggle-regexp)
-    (define-key map "\C-z" 'ido-undo-merge-work-directory)
-    (define-key map [(control ?\s)] 'ido-restrict-to-matches)
-    (define-key map [(meta ?\s)] 'ido-take-first-match)
-    (define-key map [(control ?@)] 'ido-restrict-to-matches)
-    (define-key map [right] 'ido-next-match)
-    (define-key map [left] 'ido-prev-match)
-    (define-key map "?" 'ido-completion-help)
-    ;; Magic commands.
-    (define-key map "\C-b" 'ido-magic-backward-char)
-    (define-key map "\C-f" 'ido-magic-forward-char)
-    (define-key map "\C-d" 'ido-magic-delete-char)
-    (set-keymap-parent map minibuffer-local-map)
-    (setq ido-common-completion-map map))
 
-  ;; File and directory map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-x\C-b" 'ido-enter-switch-buffer)
-    (define-key map "\C-x\C-f" 'ido-fallback-command)
-    (define-key map "\C-x\C-d" 'ido-enter-dired)
-    (define-key map [down] 'ido-next-match-dir)
-    (define-key map [up]   'ido-prev-match-dir)
-    (define-key map [(meta up)] 'ido-prev-work-directory)
-    (define-key map [(meta down)] 'ido-next-work-directory)
-    (define-key map [backspace] 'ido-delete-backward-updir)
-    (define-key map "\d"        'ido-delete-backward-updir)
-    (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS
-    (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir)  ; M-DEL
+(defalias 'ido-init-completion-maps 'ignore "")
+(make-obsolete 'ido-init-completion-maps "it does nothing." "25.1")
 
-    (define-key map [(control backspace)] 'ido-up-directory)
-    (define-key map "\C-l" 'ido-reread-directory)
-    (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir)
-    (define-key map [(meta ?b)] 'ido-push-dir)
-    (define-key map [(meta ?v)] 'ido-push-dir-first)
-    (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir)
-    (define-key map [(meta ?k)] 'ido-forget-work-directory)
-    (define-key map [(meta ?m)] 'ido-make-directory)
-    (define-key map [(meta ?n)] 'ido-next-work-directory)
-    (define-key map [(meta ?o)] 'ido-prev-work-file)
-    (define-key map [(meta control ?o)] 'ido-next-work-file)
-    (define-key map [(meta ?p)] 'ido-prev-work-directory)
-    (define-key map [(meta ?s)] 'ido-merge-work-directories)
-    (set-keymap-parent map ido-common-completion-map)
-    (setq ido-file-dir-completion-map map))
-
-  ;; File only map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-k" 'ido-delete-file-at-head)
-    (define-key map "\C-o" 'ido-copy-current-word)
-    (define-key map "\C-w" 'ido-copy-current-file-name)
-    (define-key map [(meta ?l)] 'ido-toggle-literal)
-    (set-keymap-parent map ido-file-dir-completion-map)
-    (setq ido-file-completion-map map))
+(defun ido-setup-completion-map ()
+  "Set up the completion keymap used by Ido.
 
-  ;; Buffer map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-x\C-f" 'ido-enter-find-file)
-    (define-key map "\C-x\C-b" 'ido-fallback-command)
-    (define-key map "\C-k" 'ido-kill-buffer-at-head)
-    (define-key map [?\C-\S-b] 'ido-bury-buffer-at-head)
-    (define-key map "\C-o" 'ido-toggle-virtual-buffers)
-    (set-keymap-parent map ido-common-completion-map)
-    (setq ido-buffer-completion-map map)))
+Create a keymap, bind `ido-completion-map' to it, and depending
+on what is being completed (`ido-cur-item') set its parent keymap
+to one of:
 
+  `ido-common-completion-map'
+  `ido-file-dir-completion-map'
+  `ido-file-completion-map'
+  `ido-buffer-completion-map'
 
-(defun ido-setup-completion-map ()
-  "Set up the keymap for Ido."
-
+If option `ido-context-switch-command' is non-nil or `viper-mode'
+is enabled then some keybindings are changed in the keymap."
   ;; generated every time so that it can inherit new functions.
   (let ((map (make-sparse-keymap))
 	(viper-p (if (boundp 'viper-mode) viper-mode)))
-
     (when viper-p
       (define-key map [remap viper-intercept-ESC-key] 'ignore))
-
-    (cond
-     ((memq ido-cur-item '(file dir))
+    (pcase ido-cur-item
+     ((or `file `dir)
       (when ido-context-switch-command
 	(define-key map "\C-x\C-b" ido-context-switch-command)
 	(define-key map "\C-x\C-d" 'ignore))
       (when viper-p
-	(define-key map [remap viper-backward-char] 'ido-delete-backward-updir)
-	(define-key map [remap viper-del-backward-char-in-insert] 'ido-delete-backward-updir)
-	(define-key map [remap viper-delete-backward-word] 'ido-delete-backward-word-updir))
+	(define-key map [remap viper-backward-char]
+	  'ido-delete-backward-updir)
+	(define-key map [remap viper-del-backward-char-in-insert]
+	  'ido-delete-backward-updir)
+	(define-key map [remap viper-delete-backward-word]
+	  'ido-delete-backward-word-updir))
       (set-keymap-parent map
 			 (if (eq ido-cur-item 'file)
 			     ido-file-completion-map
 			   ido-file-dir-completion-map)))
-
-     ((eq ido-cur-item 'buffer)
+     (`buffer
       (when ido-context-switch-command
 	(define-key map "\C-x\C-f" ido-context-switch-command))
       (set-keymap-parent map ido-buffer-completion-map))
-
-     (t
+     (_
       (set-keymap-parent map ido-common-completion-map)))
-
     (setq ido-completion-map map)))
 
 (defun ido-final-slash (dir &optional fix-it)
-- 
2.1.3


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

* bug#17000: setup ido keymaps only once
  2014-03-12 23:36 ` Stefan Monnier
  2014-03-13 15:35   ` Jonas Bernoulli
@ 2014-12-23  2:07   ` Leo Liu
  2014-12-24 17:11     ` Dmitry Gutov
  1 sibling, 1 reply; 11+ messages in thread
From: Leo Liu @ 2014-12-23  2:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Jonas Bernoulli, 17000

On 2014-03-13 07:36 +0800, Stefan Monnier wrote:
> Indeed, this is wrong.

Ido's author is not an idiot and AFAIK he is responsive to questions on
ido. So maybe ask him first for why it was designed that way ;)

Leo





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

* bug#17000: setup ido keymaps only once
  2014-12-23  2:07   ` Leo Liu
@ 2014-12-24 17:11     ` Dmitry Gutov
  2014-12-25 22:44       ` Kim Storm
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry Gutov @ 2014-12-24 17:11 UTC (permalink / raw)
  To: Leo Liu, Stefan Monnier; +Cc: Jonas Bernoulli, 17000, Kim F. Storm

On 12/23/2014 04:07 AM, Leo Liu wrote:

> Ido's author is not an idiot and AFAIK he is responsive to questions on
> ido. So maybe ask him first for why it was designed that way ;)

Kim, any particular reason it was written this way?





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

* bug#17000: setup ido keymaps only once
  2014-12-24 17:11     ` Dmitry Gutov
@ 2014-12-25 22:44       ` Kim Storm
  0 siblings, 0 replies; 11+ messages in thread
From: Kim Storm @ 2014-12-25 22:44 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Jonas Bernoulli, 17000@debbugs.gnu.org, Leo Liu

[-- Attachment #1: Type: text/plain, Size: 665 bytes --]

As far as I remember, that part of ido has grown out of code inherited from iswitchb, so I probably just didn't see a need to change something that worked ok for ido.

Iswitchb had this comment in the keymap setup function:
;; generated every time so that it can inherit new functions.
The new patches seems fine to me.

Regards Kim 

> Den 24/12/2014 kl. 18.11 skrev Dmitry Gutov <dgutov@yandex.ru>:
> 
>> On 12/23/2014 04:07 AM, Leo Liu wrote:
>> 
>> Ido's author is not an idiot and AFAIK he is responsive to questions on
>> ido. So maybe ask him first for why it was designed that way ;)
> 
> Kim, any particular reason it was written this way?

[-- Attachment #2: Type: text/html, Size: 1282 bytes --]

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

* bug#17000: setup ido keymaps only once
  2014-03-12 19:35 bug#17000: setup ido keymaps only once Jonas Bernoulli
  2014-03-12 23:36 ` Stefan Monnier
@ 2015-01-18 15:17 ` Oleh Krehel
  2015-01-19 11:58   ` Dmitry Gutov
  1 sibling, 1 reply; 11+ messages in thread
From: Oleh Krehel @ 2015-01-18 15:17 UTC (permalink / raw)
  To: 17000

Hello,

I have been using Jonas' patch for a week now.
It's working fine.

regards,
Oleh





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

* bug#17000: setup ido keymaps only once
  2015-01-18 15:17 ` Oleh Krehel
@ 2015-01-19 11:58   ` Dmitry Gutov
  0 siblings, 0 replies; 11+ messages in thread
From: Dmitry Gutov @ 2015-01-19 11:58 UTC (permalink / raw)
  To: Oleh Krehel, 17000-done, Jonas Bernoulli

Version: 25.1

On 01/18/2015 05:17 PM, Oleh Krehel wrote:

> I have been using Jonas' patch for a week now.
> It's working fine.

Thanks for checking, installed.

Thanks, Jonas!





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

end of thread, other threads:[~2015-01-19 11:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-12 19:35 bug#17000: setup ido keymaps only once Jonas Bernoulli
2014-03-12 23:36 ` Stefan Monnier
2014-03-13 15:35   ` Jonas Bernoulli
2014-12-08 23:39     ` Lars Magne Ingebrigtsen
2014-12-10  9:15       ` Jonas Bernoulli
2014-12-22 18:53     ` Jonas Bernoulli
2014-12-23  2:07   ` Leo Liu
2014-12-24 17:11     ` Dmitry Gutov
2014-12-25 22:44       ` Kim Storm
2015-01-18 15:17 ` Oleh Krehel
2015-01-19 11:58   ` Dmitry Gutov

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).