change key bindings to use ~C-x w~ prefix

This commit is contained in:
deb0ch 2016-12-15 01:12:51 +01:00
parent 75dcc93f14
commit 6da09ea7c3
2 changed files with 84 additions and 53 deletions

View file

@ -12,6 +12,7 @@
- [[#configuration-file-example][Configuration file example]] - [[#configuration-file-example][Configuration file example]]
* Introduction * Introduction
Window numbers for Emacs: Navigate your windows and frames using numbers ! Window numbers for Emacs: Navigate your windows and frames using numbers !
This package is an extended and actively maintained version of the This package is an extended and actively maintained version of the
@ -21,7 +22,9 @@ with some ideas and code taken from https://github.com/abo-abo/ace-window.
This version brings, among other things, support for number sets across multiple This version brings, among other things, support for number sets across multiple
frames, giving the user a smoother experience of multi-screen Emacs. frames, giving the user a smoother experience of multi-screen Emacs.
* Installation * Installation
- Clone the repo: - Clone the repo:
#+BEGIN_SRC shell #+BEGIN_SRC shell
@ -39,14 +42,18 @@ frames, giving the user a smoother experience of multi-screen Emacs.
(winum-mode) (winum-mode)
#+END_SRC #+END_SRC
* How to use * How to use
- =select-window-[0..9]=
Use ~M-1~ to ~M-9~ to navigate windows numbered 1 to 9. | Key binding | Description |
|-------------+---------------------------------------------------------------------------------------------|
| ~C-x w <n>~ | select window <n>, where <n> ranges from 0 to 9. A negative argument deletes the window. |
| ~C-x w `~ | select window by number. Number can be given as prefix arg or will be read from minibuffer. |
By default, ~M-0~ is bound to =select-window-0-or-10=, which behaves like - =select-window-0-or-10=
the other ones except that if 0 is not assigned it will act on the window 10
instead. By default, ~C-x w 0~ is bound to =select-window-0-or-10=c. If window 0 is not
assigned, it will act on the window 10 instead.
You can rebind this to the more straightforward =select-window-0= if you You can rebind this to the more straightforward =select-window-0= if you
prefer. prefer.
@ -54,47 +61,64 @@ frames, giving the user a smoother experience of multi-screen Emacs.
- =select-window-by-number= - =select-window-by-number=
If you happen to have more than 10 windows, you can use the If you happen to have more than 10 windows, you can use the
=select-window-by-number= function, bound by default to ~C-`~. =select-window-by-number= function, bound by default to ~C-x w `~.
This function allows several ways to input the window number: This function allows several ways to input the window number:
- Use a numbered prefix argument.\\ - Use a numbered prefix argument.\\
*Ex:* ~C-1 C-2 C`~ to select window 12. *Ex:* ~C-1 C-2 C-x w `~ to select window 12.
- Use a negative prefix argument to delete the window.\\ - Use a negative prefix argument to delete the window.\\
*Ex:* ~C-- C-1 C-2 C`~ to delete window 12. *Ex:* ~C-- C-1 C-2 C-x w `~ to delete window 12.
- Use the negative prefix argument to delete window 0.\\ - Use the negative prefix argument to delete window 0.\\
*Ex:* ~C-- C-`~ to delete window 0. *Ex:* ~C-- C-x w `~ to delete window 0.
- Use the default prefix argument to delete current window.\\ - Use the default prefix argument to delete current window.\\
*Ex:* ~C-u C-`~ to delete current window. *Ex:* ~C-u C-x w `~ to delete current window.
- If no prefix argument ig given, a number is read from minibuffer. A negative - If no prefix argument ig given, a number is read from minibuffer. A negative
input will delete the window instead of selecting it. input will delete the window instead of selecting it.
*NB:* On Spacemacs you can specify the prefix argument using ~SPC u~.
*Ex:* ~SPC u - 1 2 C-`~ to delete window 12.
* Configuration * Configuration
** Keybindings ** Keybindings
To define your own bindings and override the default ones, override
=winum-keymap= before activating the mode: By default, all key bindings are prefixed with a value stored in
=winum-keymap-prefix=, by default ~C-x w~. See [[Customize options][Customize options]].
The default prefix is ~C-x w~ for compatibility with common Emacs bindings. If
you prefer no to use a prefix and have shorter key bindings, you can also
override =winum-keymap= before activating =winum-mode=:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(require 'winum) (require 'winum)
(setq winum-keymap (let ((map (make-sparse-keymap))) (setq winum-keymap
(define-key map "\M-m 0" 'select-window-0) (let ((map (make-sparse-keymap)))
; ... (define-key map (kbd "C-`") 'winum-select-window-by-number)
(define-key map "\M-m 9" 'select-window-9) (define-key map (kbd "M-0") 'winum-select-window-0-or-10)
map)) (define-key map (kbd "M-1") 'winum-select-window-1)
(define-key map (kbd "M-2") 'winum-select-window-2)
(define-key map (kbd "M-3") 'winum-select-window-3)
(define-key map (kbd "M-4") 'winum-select-window-4)
(define-key map (kbd "M-5") 'winum-select-window-5)
(define-key map (kbd "M-6") 'winum-select-window-6)
(define-key map (kbd "M-7") 'winum-select-window-7)
(define-key map (kbd "M-8") 'winum-select-window-8)
map))
(winum-mode) (winum-mode)
#+END_SRC #+END_SRC
This way your bindings will not error when the mode is turned off.
** Customize options ** Customize options
Several options are available through Emacs' Customize interface under Several options are available through Emacs' Customize interface under
=convenience= > =winum=: =convenience= > =winum=:
- =winum-keymap-prefix=
Prefix key sequence for keybindings.
Default: (kbd "C-x w")
- =winum-scope= - =winum-scope=
Frames affected by a number set. Choices are ='frame-local= ='visible= or Frames affected by a number set. Choices are ='frame-local= ='visible= or
@ -184,25 +208,25 @@ available winum options.
(set-face-property 'winum-face :weight 'bold) (set-face-property 'winum-face :weight 'bold)
(setq window-numbering-scope 'global (setq window-numbering-scope 'global
winum-reverse-frame-list nil winum-reverse-frame-list nil
winum-auto-assign-0-to-minibuffer t winum-auto-assign-0-to-minibuffer t
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 (let ((map (make-sparse-keymap))) winum-keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "C-`") 'select-window-by-number) (define-key map (kbd "C-`") 'select-window-by-number)
(define-key map (kbd "M-0") 'select-window-0-or-10) (define-key map (kbd "M-0") 'select-window-0-or-10)
(define-key map (kbd "M-1") 'select-window-1) (define-key map (kbd "M-1") 'select-window-1)
(define-key map (kbd "M-2") 'select-window-2) (define-key map (kbd "M-2") 'select-window-2)
(define-key map (kbd "M-3") 'select-window-3) (define-key map (kbd "M-3") 'select-window-3)
(define-key map (kbd "M-4") 'select-window-4) (define-key map (kbd "M-4") 'select-window-4)
(define-key map (kbd "M-5") 'select-window-5) (define-key map (kbd "M-5") 'select-window-5)
(define-key map (kbd "M-6") 'select-window-6) (define-key map (kbd "M-6") 'select-window-6)
(define-key map (kbd "M-7") 'select-window-7) (define-key map (kbd "M-7") 'select-window-7)
(define-key map (kbd "M-8") 'select-window-8) (define-key map (kbd "M-8") 'select-window-8)
(define-key map (kbd "M-9") 'select-window-9) (define-key map (kbd "M-9") 'select-window-9)
map)) map))
(winum-mode) (winum-mode)
#+END_SRC #+END_SRC

View file

@ -94,21 +94,28 @@ numbers in the mode-line.")
"Face used for the number in the mode-line." "Face used for the number in the mode-line."
:group 'winum) :group 'winum)
(defcustom winum-keymap-prefix (kbd "C-x w")
"Prefix key sequence for keybindings."
:group 'winum
:type 'string)
(defvar winum-keymap (defvar winum-keymap
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(define-key map (kbd "C-`") 'winum-select-window-by-number) (let ((prefix-map (make-sparse-keymap)))
(define-key map (kbd "M-0") 'winum-select-window-0-or-10) (define-key prefix-map (kbd "`") 'winum-select-window-by-number)
(define-key map (kbd "M-1") 'winum-select-window-1) (define-key prefix-map (kbd "0") 'winum-select-window-0-or-10)
(define-key map (kbd "M-2") 'winum-select-window-2) (define-key prefix-map (kbd "1") 'winum-select-window-1)
(define-key map (kbd "M-3") 'winum-select-window-3) (define-key prefix-map (kbd "2") 'winum-select-window-2)
(define-key map (kbd "M-4") 'winum-select-window-4) (define-key prefix-map (kbd "3") 'winum-select-window-3)
(define-key map (kbd "M-5") 'winum-select-window-5) (define-key prefix-map (kbd "4") 'winum-select-window-4)
(define-key map (kbd "M-6") 'winum-select-window-6) (define-key prefix-map (kbd "5") 'winum-select-window-5)
(define-key map (kbd "M-7") 'winum-select-window-7) (define-key prefix-map (kbd "6") 'winum-select-window-6)
(define-key map (kbd "M-8") 'winum-select-window-8) (define-key prefix-map (kbd "7") 'winum-select-window-7)
(define-key map (kbd "M-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 used in by `winum-mode'.") (define-key map winum-keymap-prefix prefix-map))
map)
"Keymap used for `winum-mode'.")
;;;###autoload ;;;###autoload
(define-minor-mode winum-mode (define-minor-mode winum-mode