replace variable winum-keymap-prefix with function winum-set-keymap-prefix
Fixes #1. Setting the key bindings prefix using a variable just couldn't work given how Emacs handles key bindings for minor modes and that the available keymap API doesn't handle keymaps.
This commit is contained in:
parent
1be3fdfa0a
commit
6ccde2026b
47
README.org
47
README.org
|
@ -95,16 +95,23 @@ Emacs configuration:
|
||||||
|
|
||||||
* Configuration
|
* Configuration
|
||||||
** Keybindings
|
** Keybindings
|
||||||
By default, all key bindings are prefixed with a value stored in
|
The default prefix for key bindings is ~C-x w~ for compatibility with native
|
||||||
=winum-keymap-prefix=, by default ~C-x w~. See [[#customize-options][Customize options]].
|
Emacs bindings.
|
||||||
|
|
||||||
The default prefix is ~C-x w~ for compatibility with native Emacs bindings.
|
If you don't like ~C-x w~, you can set a prefix of your choosing using the
|
||||||
However, it gives long key bindings and can be incomfortable to use.
|
function =winum-set-keymap-prefix=:
|
||||||
|
|
||||||
For instance, you could replace the native prefix with ~C-c~ or ~M-m~.
|
#+BEGIN_SRC elisp
|
||||||
|
(winum-set-keymap-prefix (kbd "C-c"))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
If you prefer no to use a prefix to have even shorter bindings, you can also
|
This function overrides the value of =winum-keymap=, so you should call it
|
||||||
directly override =winum-keymap=:
|
before customization of =winum-keymap= and/or after customization of
|
||||||
|
=winum-base-map=. Its argument must be a key sequence, like the ones returned by
|
||||||
|
=kbd=.
|
||||||
|
|
||||||
|
If you prefer no to use a prefix and have even shorter bindings, you can also
|
||||||
|
override =winum-keymap= in the minor mode bindings table:
|
||||||
|
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(require 'winum)
|
(require 'winum)
|
||||||
|
@ -127,13 +134,16 @@ directly override =winum-keymap=:
|
||||||
(winum-mode)
|
(winum-mode)
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
This is a little bit hacky but is less code than using =define-key=, and will
|
You can also use the more conventional =define-key= on =winum-keymap=:
|
||||||
also shadow the old bindings.
|
|
||||||
|
|
||||||
*NB:* Both ~`~ and ~²~ are mapped to =winum-select-window-by-number= to handle
|
#+BEGIN_SRC emacs-lisp
|
||||||
both =qwerty= and =azerty= keyboard layouts.
|
(define-key winum-keymap (kbd "C-x y o l o") 'winum-select-window-by-number)
|
||||||
If you are using a different kind of layout, the recommended place to map
|
#+END_SRC
|
||||||
it is the key beside ~1~.
|
|
||||||
|
*NB:* Both ~`~ and ~²~ are mapped to =winum-select-window-by-number= by default
|
||||||
|
to handle both =qwerty= and =azerty= keyboard layouts. If you are using a
|
||||||
|
different kind of layout, the recommended place to map it is the key
|
||||||
|
beside ~1~.
|
||||||
|
|
||||||
** Customize options
|
** Customize options
|
||||||
Several options are available through Emacs' Customize interface under
|
Several options are available through Emacs' Customize interface under
|
||||||
|
@ -205,12 +215,6 @@ Several options are available through Emacs' Customize interface under
|
||||||
|
|
||||||
Default: '(" *which-key*")
|
Default: '(" *which-key*")
|
||||||
|
|
||||||
- =winum-keymap-prefix=
|
|
||||||
|
|
||||||
Prefix key sequence for keybindings.
|
|
||||||
|
|
||||||
Default: =(kbd "C-x w")=
|
|
||||||
|
|
||||||
- face: =winum-face=
|
- face: =winum-face=
|
||||||
|
|
||||||
Face used for the number in the mode-line.
|
Face used for the number in the mode-line.
|
||||||
|
@ -220,8 +224,6 @@ Here is an example that you could put in your =.emacs=, which includes all
|
||||||
available winum options.
|
available winum options.
|
||||||
|
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(add-to-list 'load-path "/path/to/install/folder/winum.el/")
|
|
||||||
|
|
||||||
(require 'winum)
|
(require 'winum)
|
||||||
|
|
||||||
(setcdr (assoc 'winum-mode minor-mode-map-alist)
|
(setcdr (assoc 'winum-mode minor-mode-map-alist)
|
||||||
|
@ -256,8 +258,7 @@ available winum options.
|
||||||
winum-assign-func 'my-winum-assign-func
|
winum-assign-func 'my-winum-assign-func
|
||||||
winum-auto-setup-mode-line t
|
winum-auto-setup-mode-line t
|
||||||
winum-mode-line-position 1
|
winum-mode-line-position 1
|
||||||
winum-ignored-buffers '(" *which-key*")
|
winum-ignored-buffers '(" *which-key*"))
|
||||||
winum-keymap-prefix nil)
|
|
||||||
|
|
||||||
(winum-mode)
|
(winum-mode)
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
58
winum.el
58
winum.el
|
@ -111,33 +111,30 @@ numbers in the mode-line.")
|
||||||
:group 'winum
|
:group 'winum
|
||||||
:type '(repeat string))
|
:type '(repeat string))
|
||||||
|
|
||||||
(defcustom winum-keymap-prefix (kbd "C-x w")
|
|
||||||
"Prefix key sequence for keybindings."
|
|
||||||
:group 'winum
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defface winum-face '()
|
(defface winum-face '()
|
||||||
"Face used for the number in the mode-line."
|
"Face used for the number in the mode-line."
|
||||||
:group 'winum)
|
:group 'winum)
|
||||||
|
|
||||||
(defvar winum-keymap
|
(defvar winum-base-map
|
||||||
(when winum-keymap-prefix
|
(let ((map (make-sparse-keymap)))
|
||||||
(let ((map (make-sparse-keymap)))
|
(define-key map (kbd "`") 'winum-select-window-by-number)
|
||||||
(let ((prefix-map (make-sparse-keymap)))
|
(define-key map (kbd "²") 'winum-select-window-by-number)
|
||||||
(define-key prefix-map (kbd "`") 'winum-select-window-by-number)
|
(define-key map (kbd "0") 'winum-select-window-0-or-10)
|
||||||
(define-key prefix-map (kbd "²") 'winum-select-window-by-number)
|
(define-key map (kbd "1") 'winum-select-window-1)
|
||||||
(define-key prefix-map (kbd "0") 'winum-select-window-0-or-10)
|
(define-key map (kbd "2") 'winum-select-window-2)
|
||||||
(define-key prefix-map (kbd "1") 'winum-select-window-1)
|
(define-key map (kbd "3") 'winum-select-window-3)
|
||||||
(define-key prefix-map (kbd "2") 'winum-select-window-2)
|
(define-key map (kbd "4") 'winum-select-window-4)
|
||||||
(define-key prefix-map (kbd "3") 'winum-select-window-3)
|
(define-key map (kbd "5") 'winum-select-window-5)
|
||||||
(define-key prefix-map (kbd "4") 'winum-select-window-4)
|
(define-key map (kbd "6") 'winum-select-window-6)
|
||||||
(define-key prefix-map (kbd "5") 'winum-select-window-5)
|
(define-key map (kbd "7") 'winum-select-window-7)
|
||||||
(define-key prefix-map (kbd "6") 'winum-select-window-6)
|
(define-key map (kbd "8") 'winum-select-window-8)
|
||||||
(define-key prefix-map (kbd "7") 'winum-select-window-7)
|
(define-key map (kbd "9") 'winum-select-window-9)
|
||||||
(define-key prefix-map (kbd "8") 'winum-select-window-8)
|
map)
|
||||||
(define-key prefix-map (kbd "9") 'winum-select-window-9)
|
"Keymap to be used under the prefix provided by `winum-keymap-prefix'.")
|
||||||
(define-key map winum-keymap-prefix prefix-map))
|
|
||||||
map))
|
(defvar winum-keymap (let ((map (make-sparse-keymap)))
|
||||||
|
(define-key map (kbd "C-x w") winum-base-map)
|
||||||
|
map)
|
||||||
"Keymap used for `winum-mode'.")
|
"Keymap used for `winum-mode'.")
|
||||||
|
|
||||||
;; Internal variables ----------------------------------------------------------
|
;; Internal variables ----------------------------------------------------------
|
||||||
|
@ -281,7 +278,7 @@ There are several ways to provide the number:
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(let* ((n (cond
|
(let* ((n (cond
|
||||||
((integerp arg) arg)
|
((integerp arg) arg)
|
||||||
((eq arg '-) 0) ; negative-argument
|
((eq arg '-) 0) ; the negative argument
|
||||||
(arg (winum-get-number))
|
(arg (winum-get-number))
|
||||||
((called-interactively-p 'any)
|
((called-interactively-p 'any)
|
||||||
(let ((user-input-str (read-from-minibuffer "Window: ")))
|
(let ((user-input-str (read-from-minibuffer "Window: ")))
|
||||||
|
@ -301,6 +298,19 @@ There are several ways to provide the number:
|
||||||
|
|
||||||
;; Public API ------------------------------------------------------------------
|
;; Public API ------------------------------------------------------------------
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun winum-set-keymap-prefix (prefix)
|
||||||
|
"Set key bindings prefix for `winum-keymap' based on `winum-base-map'.
|
||||||
|
This function overrides the value of `winum-keymap', so you
|
||||||
|
should call it before customization of `winum-keymap' and/or
|
||||||
|
after customization of `winum-base-map'.
|
||||||
|
PREFIX must be a key sequence, like the ones returned by `kbd'."
|
||||||
|
(setq winum-keymap (when prefix (let ((map (make-sparse-keymap)))
|
||||||
|
(define-key map prefix winum-base-map)
|
||||||
|
map)))
|
||||||
|
(setcdr (assoc 'winum-mode minor-mode-map-alist)
|
||||||
|
winum-keymap))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun winum-get-window-by-number (n)
|
(defun winum-get-window-by-number (n)
|
||||||
"Return window numbered N if exists, nil otherwise."
|
"Return window numbered N if exists, nil otherwise."
|
||||||
|
|
Loading…
Reference in a new issue