Allow :map in bind-keys to accept multiple maps
Fixes https://github.com/jwiegley/use-package/issues/129
This commit is contained in:
parent
2abf565af2
commit
eb6b81dfec
1 changed files with 62 additions and 54 deletions
|
@ -1,77 +1,77 @@
|
||||||
;;; bind-key.el --- A simple way to manage personal keybindings
|
;;; bind-key.el --- a simple way to manage personal keybindings
|
||||||
|
|
||||||
;; Copyright (C) 2012 John Wiegley
|
;; copyright (c) 2012 john wiegley
|
||||||
|
|
||||||
;; Author: John Wiegley <jwiegley@gmail.com>
|
;; author: john wiegley <jwiegley@gmail.com>
|
||||||
;; Created: 16 Jun 2012
|
;; created: 16 jun 2012
|
||||||
;; Version: 1.0
|
;; version: 1.0
|
||||||
;; Keywords: keys keybinding config dotemacs
|
;; keywords: keys keybinding config dotemacs
|
||||||
;; URL: https://github.com/jwiegley/use-package
|
;; url: https://github.com/jwiegley/use-package
|
||||||
|
|
||||||
;; This program is free software; you can redistribute it and/or
|
;; this program is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU General Public License as
|
;; modify it under the terms of the gnu general public license as
|
||||||
;; published by the Free Software Foundation; either version 2, or (at
|
;; published by the free software foundation; either version 2, or (at
|
||||||
;; your option) any later version.
|
;; your option) any later version.
|
||||||
|
|
||||||
;; This program is distributed in the hope that it will be useful, but
|
;; this program is distributed in the hope that it will be useful, but
|
||||||
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
;; without any warranty; without even the implied warranty of
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
;; merchantability or fitness for a particular purpose. see the gnu
|
||||||
;; General Public License for more details.
|
;; general public license for more details.
|
||||||
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
;; you should have received a copy of the gnu general public license
|
||||||
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
;; along with gnu emacs; see the file copying. if not, write to the
|
||||||
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
;; free software foundation, inc., 59 temple place - suite 330,
|
||||||
;; Boston, MA 02111-1307, USA.
|
;; boston, ma 02111-1307, usa.
|
||||||
|
|
||||||
;;; Commentary:
|
;;; commentary:
|
||||||
|
|
||||||
;; If you have lots of keybindings set in your .emacs file, it can be hard to
|
;; if you have lots of keybindings set in your .emacs file, it can be hard to
|
||||||
;; know which ones you haven't set yet, and which may now be overriding some
|
;; know which ones you haven't set yet, and which may now be overriding some
|
||||||
;; new default in a new Emacs version. This module aims to solve that
|
;; new default in a new emacs version. this module aims to solve that
|
||||||
;; problem.
|
;; problem.
|
||||||
;;
|
;;
|
||||||
;; Bind keys as follows in your .emacs:
|
;; bind keys as follows in your .emacs:
|
||||||
;;
|
;;
|
||||||
;; (require 'bind-key)
|
;; (require 'bind-key)
|
||||||
;;
|
;;
|
||||||
;; (bind-key "C-c x" 'my-ctrl-c-x-command)
|
;; (bind-key "c-c x" 'my-ctrl-c-x-command)
|
||||||
;;
|
;;
|
||||||
;; If you want the keybinding to override all minor modes that may also bind
|
;; if you want the keybinding to override all minor modes that may also bind
|
||||||
;; the same key, use the `bind-key*' form:
|
;; the same key, use the `bind-key*' form:
|
||||||
;;
|
;;
|
||||||
;; (bind-key* "<C-return>" 'other-window)
|
;; (bind-key* "<c-return>" 'other-window)
|
||||||
;;
|
;;
|
||||||
;; If you want to rebind a key only in a particular keymap, use:
|
;; if you want to rebind a key only in a particular keymap, use:
|
||||||
;;
|
;;
|
||||||
;; (bind-key "C-c x" 'my-ctrl-c-x-command some-other-mode-map)
|
;; (bind-key "c-c x" 'my-ctrl-c-x-command some-other-mode-map)
|
||||||
;;
|
;;
|
||||||
;; To unbind a key within a keymap (for example, to stop your favorite major
|
;; to unbind a key within a keymap (for example, to stop your favorite major
|
||||||
;; mode from changing a binding that you don't want to override everywhere),
|
;; mode from changing a binding that you don't want to override everywhere),
|
||||||
;; use `unbind-key':
|
;; use `unbind-key':
|
||||||
;;
|
;;
|
||||||
;; (unbind-key "C-c x" some-other-mode-map)
|
;; (unbind-key "c-c x" some-other-mode-map)
|
||||||
;;
|
;;
|
||||||
;; To bind multiple keys at once, or set up a prefix map, a
|
;; to bind multiple keys at once, or set up a prefix map, a `bind-keys' macro
|
||||||
;; `bind-keys' macro is provided. It accepts keyword arguments, see
|
;; is provided. it accepts keyword arguments, see its documentation for
|
||||||
;; its documentation for detailed description.
|
;; detailed description.
|
||||||
;;
|
;;
|
||||||
;; To add keys into a specific map, use :map argument
|
;; to add keys into a specific map, use :map argument
|
||||||
;;
|
;;
|
||||||
;; (bind-keys :map dired-mode-map
|
;; (bind-keys :map dired-mode-map
|
||||||
;; ("o" . dired-omit-mode)
|
;; ("o" . dired-omit-mode)
|
||||||
;; ("a" . some-custom-dired-function))
|
;; ("a" . some-custom-dired-function))
|
||||||
;;
|
;;
|
||||||
;; To set up a prefix map, use :prefix-map and :prefix
|
;; to set up a prefix map, use `:prefix-map' and `:prefix' arguments (both are
|
||||||
;; arguments (both are required)
|
;; required)
|
||||||
;;
|
;;
|
||||||
;; (bind-keys :prefix-map my-customize-prefix-map
|
;; (bind-keys :prefix-map my-customize-prefix-map
|
||||||
;; :prefix "C-c c"
|
;; :prefix "C-c c"
|
||||||
;; ("f" . customize-face)
|
;; ("f" . customize-face)
|
||||||
;; ("v" . customize-variable))
|
;; ("v" . customize-variable))
|
||||||
;;
|
;;
|
||||||
;; You can combine all the keywords together.
|
;; You can combine all the keywords together. Additionally,
|
||||||
;; Additionally, :prefix-docstring can be specified to set
|
;; `:prefix-docstring' can be specified to set documentation of created
|
||||||
;; documentation of created :prefix-map variable.
|
;; `:prefix-map' variable.
|
||||||
;;
|
;;
|
||||||
;; To bind multiple keys in a `bind-key*' way (to be sure that your bindings
|
;; To bind multiple keys in a `bind-key*' way (to be sure that your bindings
|
||||||
;; will not be overridden by other modes), you may use `bind-keys*' macro:
|
;; will not be overridden by other modes), you may use `bind-keys*' macro:
|
||||||
|
@ -182,16 +182,17 @@ Accepts keyword arguments:
|
||||||
|
|
||||||
The rest of the arguments are conses of keybinding string and a
|
The rest of the arguments are conses of keybinding string and a
|
||||||
function symbol (unquoted)."
|
function symbol (unquoted)."
|
||||||
(let ((map (plist-get args :map))
|
(let* ((map (plist-get args :map))
|
||||||
(doc (plist-get args :prefix-docstring))
|
(maps (if (listp map) map (list map)))
|
||||||
(prefix-map (plist-get args :prefix-map))
|
(doc (plist-get args :prefix-docstring))
|
||||||
(prefix (plist-get args :prefix))
|
(prefix-map (plist-get args :prefix-map))
|
||||||
(menu-name (plist-get args :menu-name))
|
(prefix (plist-get args :prefix))
|
||||||
(key-bindings (progn
|
(menu-name (plist-get args :menu-name))
|
||||||
(while (keywordp (car args))
|
(key-bindings (progn
|
||||||
(pop args)
|
(while (keywordp (car args))
|
||||||
(pop args))
|
(pop args)
|
||||||
args)))
|
(pop args))
|
||||||
|
args)))
|
||||||
(when (or (and prefix-map
|
(when (or (and prefix-map
|
||||||
(not prefix))
|
(not prefix))
|
||||||
(and prefix
|
(and prefix
|
||||||
|
@ -205,12 +206,19 @@ function symbol (unquoted)."
|
||||||
,@(when doc `((put ',prefix-map 'variable-documentation ,doc)))
|
,@(when doc `((put ',prefix-map 'variable-documentation ,doc)))
|
||||||
,@(if menu-name
|
,@(if menu-name
|
||||||
`((define-prefix-command ',prefix-map nil ,menu-name))
|
`((define-prefix-command ',prefix-map nil ,menu-name))
|
||||||
`((define-prefix-command ',prefix-map)))
|
`((define-prefix-command ',prefix-map)))
|
||||||
(bind-key ,prefix ',prefix-map ,map)))
|
,@(mapcar
|
||||||
,@(mapcar (lambda (form)
|
#'(lambda (m)
|
||||||
`(bind-key ,(car form) ',(cdr form)
|
`(bind-key ,prefix ',prefix-map ,m)) maps)))
|
||||||
,(or prefix-map map)))
|
,@(apply
|
||||||
key-bindings))))
|
#'nconc
|
||||||
|
(mapcar (lambda (form)
|
||||||
|
(if prefix-map
|
||||||
|
`((bind-key ,(car form) ',(cdr form) ,prefix-map))
|
||||||
|
(mapcar
|
||||||
|
#'(lambda (m)
|
||||||
|
`(bind-key ,(car form) ',(cdr form) ,m)) maps)))
|
||||||
|
key-bindings)))))
|
||||||
|
|
||||||
(defmacro bind-keys* (&rest args)
|
(defmacro bind-keys* (&rest args)
|
||||||
`(bind-keys :map override-global-map
|
`(bind-keys :map override-global-map
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue