From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jonas Bernoulli Newsgroups: gmane.emacs.bugs Subject: bug#17000: setup ido keymaps only once Date: Mon, 22 Dec 2014 19:53:40 +0100 Message-ID: <87k31jcy8b.fsf@bernoul.li> References: <877g7zfbwr.fsf@bernoul.li> <87wqfyun64.fsf@bernoul.li> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1419274647 30444 80.91.229.3 (22 Dec 2014 18:57:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 22 Dec 2014 18:57:27 +0000 (UTC) Cc: 17000@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 22 19:57:20 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y38AP-0001TO-BG for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Dec 2014 19:57:17 +0100 Original-Received: from localhost ([::1]:41583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y38AO-0007NX-LT for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Dec 2014 13:57:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y38AG-0007NS-2K for bug-gnu-emacs@gnu.org; Mon, 22 Dec 2014 13:57:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y38AA-0005vU-No for bug-gnu-emacs@gnu.org; Mon, 22 Dec 2014 13:57:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y38AA-0005vN-Ib for bug-gnu-emacs@gnu.org; Mon, 22 Dec 2014 13:57:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Y38AA-0000yb-2O for bug-gnu-emacs@gnu.org; Mon, 22 Dec 2014 13:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jonas Bernoulli Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Dec 2014 18:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17000 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 17000-submit@debbugs.gnu.org id=B17000.14192745963718 (code B ref 17000); Mon, 22 Dec 2014 18:57:01 +0000 Original-Received: (at 17000) by debbugs.gnu.org; 22 Dec 2014 18:56:36 +0000 Original-Received: from localhost ([127.0.0.1]:55137 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y389j-0000xt-Fu for submit@debbugs.gnu.org; Mon, 22 Dec 2014 13:56:36 -0500 Original-Received: from mail.hostpark.net ([212.243.197.30]:51900) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y389f-0000xd-NR for 17000@debbugs.gnu.org; Mon, 22 Dec 2014 13:56:33 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id F36C416F24; Mon, 22 Dec 2014 19:56:28 +0100 (CET) X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Original-Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail0.hostpark.net [127.0.0.1]) (amavisd-new, port 10124) with ESMTP id omfvCTPEC1-v; Mon, 22 Dec 2014 19:56:28 +0100 (CET) Original-Received: from lem (80-218-85-1.dclient.hispeed.ch [80.218.85.1]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id A9D8B16F3A; Mon, 22 Dec 2014 19:56:28 +0100 (CET) In-reply-to: <87wqfyun64.fsf@bernoul.li> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:97680 Archived-At: --=-=-= Content-Type: text/plain > 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 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Define-ido-keymaps-when-the-variables-are-defined.patch >From a4111f92676c87a179f9ec21782c6939537a564b Mon Sep 17 00:00:00 2001 From: Jonas Bernoulli 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 + + * 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 * 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 --=-=-=--