diff options
| author | Jonas Bernoulli | 2015-01-19 13:54:14 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2015-01-19 13:54:14 +0200 |
| commit | db2ed6b798960f4067bbf2c7415f34b95b982818 (patch) | |
| tree | 21e8d653fa78e9c4164e608710d1ba38c79f510f | |
| parent | 2e8d209f258c9bb6a6626d4a101995965b040024 (diff) | |
| download | emacs-db2ed6b798960f4067bbf2c7415f34b95b982818.tar.gz emacs-db2ed6b798960f4067bbf2c7415f34b95b982818.zip | |
Set up ido keymaps only once
* lisp/ido (ido-common-completion-map)
(ido-file-dir-completion-map)
(ido-file-completion-map, ido-buffer-completion-map): Set up key
bindings when each 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.
Fixes: debbugs:17000
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/ido.el | 221 |
2 files changed, 122 insertions, 111 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 44d0cddc642..401f5a2ccee 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2015-01-19 Jonas Bernoulli <jonas@bernoul.li> | ||
| 2 | |||
| 3 | Define Ido keymaps once (bug#17000). | ||
| 4 | * lisp/ido (ido-common-completion-map) | ||
| 5 | (ido-file-dir-completion-map) | ||
| 6 | (ido-file-completion-map, ido-buffer-completion-map): Set up key | ||
| 7 | bindings when each variable is defined. | ||
| 8 | (ido-completion-map): Move definition. | ||
| 9 | (ido-init-completion-maps): Noop. | ||
| 10 | (ido-common-initialization): Don't call it. | ||
| 11 | (ido-setup-completion-map): Improve doc-string, cleanup. | ||
| 12 | |||
| 1 | 2015-01-19 Ivan Shmakov <ivan@siamics.net> | 13 | 2015-01-19 Ivan Shmakov <ivan@siamics.net> |
| 2 | 14 | ||
| 3 | * cus-dep.el (custom-make-dependencies): Ensure that | 15 | * cus-dep.el (custom-make-dependencies): Ensure that |
diff --git a/lisp/ido.el b/lisp/ido.el index 2321b57d08a..6a4f1978f24 100644 --- a/lisp/ido.el +++ b/lisp/ido.el | |||
| @@ -323,8 +323,8 @@ | |||
| 323 | 323 | ||
| 324 | (defvar recentf-list) | 324 | (defvar recentf-list) |
| 325 | 325 | ||
| 326 | ;;; User Variables | 326 | ;;;; Options |
| 327 | ;; | 327 | |
| 328 | ;; These are some things you might want to change. | 328 | ;; These are some things you might want to change. |
| 329 | 329 | ||
| 330 | (defun ido-fractionp (n) | 330 | (defun ido-fractionp (n) |
| @@ -978,25 +978,90 @@ The fallback command is passed as an argument to the functions." | |||
| 978 | :type 'hook | 978 | :type 'hook |
| 979 | :group 'ido) | 979 | :group 'ido) |
| 980 | 980 | ||
| 981 | ;;; Internal Variables | 981 | ;;;; Keymaps |
| 982 | |||
| 983 | ;; Persistent variables | ||
| 984 | |||
| 985 | (defvar ido-completion-map nil | ||
| 986 | "Currently active keymap for Ido commands.") | ||
| 987 | 982 | ||
| 988 | (defvar ido-common-completion-map nil | 983 | (defvar ido-common-completion-map |
| 984 | (let ((map (make-sparse-keymap))) | ||
| 985 | (set-keymap-parent map minibuffer-local-map) | ||
| 986 | (define-key map "\C-a" 'ido-toggle-ignore) | ||
| 987 | (define-key map "\C-c" 'ido-toggle-case) | ||
| 988 | (define-key map "\C-e" 'ido-edit-input) | ||
| 989 | (define-key map "\t" 'ido-complete) | ||
| 990 | (define-key map " " 'ido-complete-space) | ||
| 991 | (define-key map "\C-j" 'ido-select-text) | ||
| 992 | (define-key map "\C-m" 'ido-exit-minibuffer) | ||
| 993 | (define-key map "\C-p" 'ido-toggle-prefix) | ||
| 994 | (define-key map "\C-r" 'ido-prev-match) | ||
| 995 | (define-key map "\C-s" 'ido-next-match) | ||
| 996 | (define-key map [?\C-.] 'ido-next-match) | ||
| 997 | (define-key map [?\C-,] 'ido-prev-match) | ||
| 998 | (define-key map "\C-t" 'ido-toggle-regexp) | ||
| 999 | (define-key map "\C-z" 'ido-undo-merge-work-directory) | ||
| 1000 | (define-key map [(control ?\s)] 'ido-restrict-to-matches) | ||
| 1001 | (define-key map [(meta ?\s)] 'ido-take-first-match) | ||
| 1002 | (define-key map [(control ?@)] 'ido-restrict-to-matches) | ||
| 1003 | (define-key map [right] 'ido-next-match) | ||
| 1004 | (define-key map [left] 'ido-prev-match) | ||
| 1005 | (define-key map "?" 'ido-completion-help) | ||
| 1006 | (define-key map "\C-b" 'ido-magic-backward-char) | ||
| 1007 | (define-key map "\C-f" 'ido-magic-forward-char) | ||
| 1008 | (define-key map "\C-d" 'ido-magic-delete-char) | ||
| 1009 | map) | ||
| 989 | "Keymap for all Ido commands.") | 1010 | "Keymap for all Ido commands.") |
| 990 | 1011 | ||
| 991 | (defvar ido-file-completion-map nil | 1012 | (defvar ido-file-dir-completion-map |
| 992 | "Keymap for Ido file commands.") | 1013 | (let ((map (make-sparse-keymap))) |
| 993 | 1014 | (set-keymap-parent map ido-common-completion-map) | |
| 994 | (defvar ido-file-dir-completion-map nil | 1015 | (define-key map "\C-x\C-b" 'ido-enter-switch-buffer) |
| 1016 | (define-key map "\C-x\C-f" 'ido-fallback-command) | ||
| 1017 | (define-key map "\C-x\C-d" 'ido-enter-dired) | ||
| 1018 | (define-key map [down] 'ido-next-match-dir) | ||
| 1019 | (define-key map [up] 'ido-prev-match-dir) | ||
| 1020 | (define-key map [(meta up)] 'ido-prev-work-directory) | ||
| 1021 | (define-key map [(meta down)] 'ido-next-work-directory) | ||
| 1022 | (define-key map [backspace] 'ido-delete-backward-updir) | ||
| 1023 | (define-key map "\d" 'ido-delete-backward-updir) | ||
| 1024 | (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS | ||
| 1025 | (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir) ; M-DEL | ||
| 1026 | (define-key map [(control backspace)] 'ido-up-directory) | ||
| 1027 | (define-key map "\C-l" 'ido-reread-directory) | ||
| 1028 | (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir) | ||
| 1029 | (define-key map [(meta ?b)] 'ido-push-dir) | ||
| 1030 | (define-key map [(meta ?v)] 'ido-push-dir-first) | ||
| 1031 | (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir) | ||
| 1032 | (define-key map [(meta ?k)] 'ido-forget-work-directory) | ||
| 1033 | (define-key map [(meta ?m)] 'ido-make-directory) | ||
| 1034 | (define-key map [(meta ?n)] 'ido-next-work-directory) | ||
| 1035 | (define-key map [(meta ?o)] 'ido-prev-work-file) | ||
| 1036 | (define-key map [(meta control ?o)] 'ido-next-work-file) | ||
| 1037 | (define-key map [(meta ?p)] 'ido-prev-work-directory) | ||
| 1038 | (define-key map [(meta ?s)] 'ido-merge-work-directories) | ||
| 1039 | map) | ||
| 995 | "Keymap for Ido file and directory commands.") | 1040 | "Keymap for Ido file and directory commands.") |
| 996 | 1041 | ||
| 997 | (defvar ido-buffer-completion-map nil | 1042 | (defvar ido-file-completion-map |
| 1043 | (let ((map (make-sparse-keymap))) | ||
| 1044 | (set-keymap-parent map ido-file-dir-completion-map) | ||
| 1045 | (define-key map "\C-k" 'ido-delete-file-at-head) | ||
| 1046 | (define-key map "\C-o" 'ido-copy-current-word) | ||
| 1047 | (define-key map "\C-w" 'ido-copy-current-file-name) | ||
| 1048 | (define-key map [(meta ?l)] 'ido-toggle-literal) | ||
| 1049 | map) | ||
| 1050 | "Keymap for Ido file commands.") | ||
| 1051 | |||
| 1052 | (defvar ido-buffer-completion-map | ||
| 1053 | (let ((map (make-sparse-keymap))) | ||
| 1054 | (set-keymap-parent map ido-common-completion-map) | ||
| 1055 | (define-key map "\C-x\C-f" 'ido-enter-find-file) | ||
| 1056 | (define-key map "\C-x\C-b" 'ido-fallback-command) | ||
| 1057 | (define-key map "\C-k" 'ido-kill-buffer-at-head) | ||
| 1058 | (define-key map [?\C-\S-b] 'ido-bury-buffer-at-head) | ||
| 1059 | (define-key map "\C-o" 'ido-toggle-virtual-buffers) | ||
| 1060 | map) | ||
| 998 | "Keymap for Ido buffer commands.") | 1061 | "Keymap for Ido buffer commands.") |
| 999 | 1062 | ||
| 1063 | ;;;; Persistent variables | ||
| 1064 | |||
| 1000 | (defvar ido-file-history nil | 1065 | (defvar ido-file-history nil |
| 1001 | "History of files selected using `ido-find-file'.") | 1066 | "History of files selected using `ido-find-file'.") |
| 1002 | 1067 | ||
| @@ -1027,7 +1092,10 @@ Each element in the list is of the form (DIR (MTIME) FILE...).") | |||
| 1027 | Intended to be let-bound by functions which call Ido repeatedly. | 1092 | Intended to be let-bound by functions which call Ido repeatedly. |
| 1028 | Should never be set permanently.") | 1093 | Should never be set permanently.") |
| 1029 | 1094 | ||
| 1030 | ;; Temporary storage | 1095 | ;;;; Temporary storage |
| 1096 | |||
| 1097 | (defvar ido-completion-map nil | ||
| 1098 | "Currently active keymap for Ido commands.") | ||
| 1031 | 1099 | ||
| 1032 | (defvar ido-eoinput 1 | 1100 | (defvar ido-eoinput 1 |
| 1033 | "Point where minibuffer input ends and completion info begins. | 1101 | "Point where minibuffer input ends and completion info begins. |
| @@ -1086,13 +1154,14 @@ Value is an integer which is number of chars to right of prompt.") | |||
| 1086 | This is a copy of `recentf-list', pared down and with faces applied. | 1154 | This is a copy of `recentf-list', pared down and with faces applied. |
| 1087 | Only used if `ido-use-virtual-buffers' is non-nil.") | 1155 | Only used if `ido-use-virtual-buffers' is non-nil.") |
| 1088 | 1156 | ||
| 1089 | ;;; Variables with dynamic bindings. | 1157 | ;;;; Variables with dynamic bindings. |
| 1090 | ;;; Declared here to keep the byte compiler quiet. | 1158 | |
| 1159 | ;; These are declared here to keep the byte compiler quiet. | ||
| 1091 | 1160 | ||
| 1092 | ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list). | 1161 | ;; Stores the current ido item type ('file, 'dir, 'buffer, or 'list). |
| 1093 | (defvar ido-cur-item) | 1162 | (defvar ido-cur-item) |
| 1094 | 1163 | ||
| 1095 | ;;; Stores the current default item | 1164 | ;; Stores the current default item. |
| 1096 | (defvar ido-default-item) | 1165 | (defvar ido-default-item) |
| 1097 | 1166 | ||
| 1098 | ;; Stores the current list of items that will be searched through. | 1167 | ;; Stores the current list of items that will be searched through. |
| @@ -1502,7 +1571,6 @@ Removes badly formatted data and ignored directories." | |||
| 1502 | (ido-save-history)) | 1571 | (ido-save-history)) |
| 1503 | 1572 | ||
| 1504 | (defun ido-common-initialization () | 1573 | (defun ido-common-initialization () |
| 1505 | (ido-init-completion-maps) | ||
| 1506 | (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup) | 1574 | (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup) |
| 1507 | (add-hook 'choose-completion-string-functions 'ido-choose-completion-string)) | 1575 | (add-hook 'choose-completion-string-functions 'ido-choose-completion-string)) |
| 1508 | 1576 | ||
| @@ -1596,120 +1664,51 @@ This function also adds a hook to the minibuffer." | |||
| 1596 | 1664 | ||
| 1597 | 1665 | ||
| 1598 | ;;; IDO KEYMAP | 1666 | ;;; IDO KEYMAP |
| 1599 | (defun ido-init-completion-maps () | ||
| 1600 | "Set up the completion keymaps used by Ido." | ||
| 1601 | |||
| 1602 | ;; Common map | ||
| 1603 | (let ((map (make-sparse-keymap))) | ||
| 1604 | (define-key map "\C-a" 'ido-toggle-ignore) | ||
| 1605 | (define-key map "\C-c" 'ido-toggle-case) | ||
| 1606 | (define-key map "\C-e" 'ido-edit-input) | ||
| 1607 | (define-key map "\t" 'ido-complete) | ||
| 1608 | (define-key map " " 'ido-complete-space) | ||
| 1609 | (define-key map "\C-j" 'ido-select-text) | ||
| 1610 | (define-key map "\C-m" 'ido-exit-minibuffer) | ||
| 1611 | (define-key map "\C-p" 'ido-toggle-prefix) | ||
| 1612 | (define-key map "\C-r" 'ido-prev-match) | ||
| 1613 | (define-key map "\C-s" 'ido-next-match) | ||
| 1614 | (define-key map [?\C-.] 'ido-next-match) | ||
| 1615 | (define-key map [?\C-,] 'ido-prev-match) | ||
| 1616 | (define-key map "\C-t" 'ido-toggle-regexp) | ||
| 1617 | (define-key map "\C-z" 'ido-undo-merge-work-directory) | ||
| 1618 | (define-key map [(control ?\s)] 'ido-restrict-to-matches) | ||
| 1619 | (define-key map [(meta ?\s)] 'ido-take-first-match) | ||
| 1620 | (define-key map [(control ?@)] 'ido-restrict-to-matches) | ||
| 1621 | (define-key map [right] 'ido-next-match) | ||
| 1622 | (define-key map [left] 'ido-prev-match) | ||
| 1623 | (define-key map "?" 'ido-completion-help) | ||
| 1624 | ;; Magic commands. | ||
| 1625 | (define-key map "\C-b" 'ido-magic-backward-char) | ||
| 1626 | (define-key map "\C-f" 'ido-magic-forward-char) | ||
| 1627 | (define-key map "\C-d" 'ido-magic-delete-char) | ||
| 1628 | (set-keymap-parent map minibuffer-local-map) | ||
| 1629 | (setq ido-common-completion-map map)) | ||
| 1630 | |||
| 1631 | ;; File and directory map | ||
| 1632 | (let ((map (make-sparse-keymap))) | ||
| 1633 | (define-key map "\C-x\C-b" 'ido-enter-switch-buffer) | ||
| 1634 | (define-key map "\C-x\C-f" 'ido-fallback-command) | ||
| 1635 | (define-key map "\C-x\C-d" 'ido-enter-dired) | ||
| 1636 | (define-key map [down] 'ido-next-match-dir) | ||
| 1637 | (define-key map [up] 'ido-prev-match-dir) | ||
| 1638 | (define-key map [(meta up)] 'ido-prev-work-directory) | ||
| 1639 | (define-key map [(meta down)] 'ido-next-work-directory) | ||
| 1640 | (define-key map [backspace] 'ido-delete-backward-updir) | ||
| 1641 | (define-key map "\d" 'ido-delete-backward-updir) | ||
| 1642 | (define-key map [remap delete-backward-char] 'ido-delete-backward-updir) ; BS | ||
| 1643 | (define-key map [remap backward-kill-word] 'ido-delete-backward-word-updir) ; M-DEL | ||
| 1644 | 1667 | ||
| 1645 | (define-key map [(control backspace)] 'ido-up-directory) | 1668 | (defalias 'ido-init-completion-maps 'ignore "") |
| 1646 | (define-key map "\C-l" 'ido-reread-directory) | 1669 | (make-obsolete 'ido-init-completion-maps "it does nothing." "25.1") |
| 1647 | (define-key map [(meta ?d)] 'ido-wide-find-dir-or-delete-dir) | ||
| 1648 | (define-key map [(meta ?b)] 'ido-push-dir) | ||
| 1649 | (define-key map [(meta ?v)] 'ido-push-dir-first) | ||
| 1650 | (define-key map [(meta ?f)] 'ido-wide-find-file-or-pop-dir) | ||
| 1651 | (define-key map [(meta ?k)] 'ido-forget-work-directory) | ||
| 1652 | (define-key map [(meta ?m)] 'ido-make-directory) | ||
| 1653 | (define-key map [(meta ?n)] 'ido-next-work-directory) | ||
| 1654 | (define-key map [(meta ?o)] 'ido-prev-work-file) | ||
| 1655 | (define-key map [(meta control ?o)] 'ido-next-work-file) | ||
| 1656 | (define-key map [(meta ?p)] 'ido-prev-work-directory) | ||
| 1657 | (define-key map [(meta ?s)] 'ido-merge-work-directories) | ||
| 1658 | (set-keymap-parent map ido-common-completion-map) | ||
| 1659 | (setq ido-file-dir-completion-map map)) | ||
| 1660 | 1670 | ||
| 1661 | ;; File only map | 1671 | (defun ido-setup-completion-map () |
| 1662 | (let ((map (make-sparse-keymap))) | 1672 | "Set up the completion keymap used by Ido. |
| 1663 | (define-key map "\C-k" 'ido-delete-file-at-head) | ||
| 1664 | (define-key map "\C-o" 'ido-copy-current-word) | ||
| 1665 | (define-key map "\C-w" 'ido-copy-current-file-name) | ||
| 1666 | (define-key map [(meta ?l)] 'ido-toggle-literal) | ||
| 1667 | (set-keymap-parent map ido-file-dir-completion-map) | ||
| 1668 | (setq ido-file-completion-map map)) | ||
| 1669 | 1673 | ||
| 1670 | ;; Buffer map | 1674 | Create a keymap, bind `ido-completion-map' to it, and depending |
| 1671 | (let ((map (make-sparse-keymap))) | 1675 | on what is being completed (`ido-cur-item') set its parent keymap |
| 1672 | (define-key map "\C-x\C-f" 'ido-enter-find-file) | 1676 | to one of: |
| 1673 | (define-key map "\C-x\C-b" 'ido-fallback-command) | ||
| 1674 | (define-key map "\C-k" 'ido-kill-buffer-at-head) | ||
| 1675 | (define-key map [?\C-\S-b] 'ido-bury-buffer-at-head) | ||
| 1676 | (define-key map "\C-o" 'ido-toggle-virtual-buffers) | ||
| 1677 | (set-keymap-parent map ido-common-completion-map) | ||
| 1678 | (setq ido-buffer-completion-map map))) | ||
| 1679 | 1677 | ||
| 1678 | `ido-common-completion-map' | ||
| 1679 | `ido-file-dir-completion-map' | ||
| 1680 | `ido-file-completion-map' | ||
| 1681 | `ido-buffer-completion-map' | ||
| 1680 | 1682 | ||
| 1681 | (defun ido-setup-completion-map () | 1683 | If option `ido-context-switch-command' is non-nil or `viper-mode' |
| 1682 | "Set up the keymap for Ido." | 1684 | is enabled then some keybindings are changed in the keymap." |
| 1683 | |||
| 1684 | ;; generated every time so that it can inherit new functions. | 1685 | ;; generated every time so that it can inherit new functions. |
| 1685 | (let ((map (make-sparse-keymap)) | 1686 | (let ((map (make-sparse-keymap)) |
| 1686 | (viper-p (if (boundp 'viper-mode) viper-mode))) | 1687 | (viper-p (if (boundp 'viper-mode) viper-mode))) |
| 1687 | |||
| 1688 | (when viper-p | 1688 | (when viper-p |
| 1689 | (define-key map [remap viper-intercept-ESC-key] 'ignore)) | 1689 | (define-key map [remap viper-intercept-ESC-key] 'ignore)) |
| 1690 | 1690 | (pcase ido-cur-item | |
| 1691 | (cond | 1691 | ((or `file `dir) |
| 1692 | ((memq ido-cur-item '(file dir)) | ||
| 1693 | (when ido-context-switch-command | 1692 | (when ido-context-switch-command |
| 1694 | (define-key map "\C-x\C-b" ido-context-switch-command) | 1693 | (define-key map "\C-x\C-b" ido-context-switch-command) |
| 1695 | (define-key map "\C-x\C-d" 'ignore)) | 1694 | (define-key map "\C-x\C-d" 'ignore)) |
| 1696 | (when viper-p | 1695 | (when viper-p |
| 1697 | (define-key map [remap viper-backward-char] 'ido-delete-backward-updir) | 1696 | (define-key map [remap viper-backward-char] |
| 1698 | (define-key map [remap viper-del-backward-char-in-insert] 'ido-delete-backward-updir) | 1697 | 'ido-delete-backward-updir) |
| 1699 | (define-key map [remap viper-delete-backward-word] 'ido-delete-backward-word-updir)) | 1698 | (define-key map [remap viper-del-backward-char-in-insert] |
| 1699 | 'ido-delete-backward-updir) | ||
| 1700 | (define-key map [remap viper-delete-backward-word] | ||
| 1701 | 'ido-delete-backward-word-updir)) | ||
| 1700 | (set-keymap-parent map | 1702 | (set-keymap-parent map |
| 1701 | (if (eq ido-cur-item 'file) | 1703 | (if (eq ido-cur-item 'file) |
| 1702 | ido-file-completion-map | 1704 | ido-file-completion-map |
| 1703 | ido-file-dir-completion-map))) | 1705 | ido-file-dir-completion-map))) |
| 1704 | 1706 | (`buffer | |
| 1705 | ((eq ido-cur-item 'buffer) | ||
| 1706 | (when ido-context-switch-command | 1707 | (when ido-context-switch-command |
| 1707 | (define-key map "\C-x\C-f" ido-context-switch-command)) | 1708 | (define-key map "\C-x\C-f" ido-context-switch-command)) |
| 1708 | (set-keymap-parent map ido-buffer-completion-map)) | 1709 | (set-keymap-parent map ido-buffer-completion-map)) |
| 1709 | 1710 | (_ | |
| 1710 | (t | ||
| 1711 | (set-keymap-parent map ido-common-completion-map))) | 1711 | (set-keymap-parent map ido-common-completion-map))) |
| 1712 | |||
| 1713 | (setq ido-completion-map map))) | 1712 | (setq ido-completion-map map))) |
| 1714 | 1713 | ||
| 1715 | (defun ido-final-slash (dir &optional fix-it) | 1714 | (defun ido-final-slash (dir &optional fix-it) |