| .gitignore | ||
| README.org | ||
| winum.el | ||
Window numbers for Emacs !
Contents TOC
Introduction
Window numbers for Emacs: Navigate your windows and frames using numbers !
This package is an extended and actively maintained version of the https://github.com/nschum/window-numbering.el package by Nikolaj Schumacher, 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 frames, giving the user a smoother experience of multi-screen Emacs.
Installation
- Clone the repo:
cd /path/to/install/folder
git clone https://github.com/deb0ch/winum.el
- Add the following to your Emacs configuration:
(add-to-list 'load-path "/path/to/install/folder/winum.el/")
(require 'winum)
(winum-mode)
How to use
| 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. |
select-window-0-or-10By default,C-x w 0is 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 straightforwardselect-window-0if you prefer.-
select-window-by-numberIf you happen to have more than 10 windows, you can use the
select-window-by-numberfunction, bound by default toC-x w `.This function allows several ways to input the window number:
- Use a numbered prefix argument.
Ex:C-1 C-2 C-x w `to select window 12. - Use a negative prefix argument to delete the window.
Ex:C-- C-1 C-2 C-x w `to delete window 12. - Use the negative prefix argument to delete window 0.
Ex:C-- C-x w `to delete window 0. - Use the default prefix argument 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 input will delete the window instead of selecting it.
- Use a numbered prefix argument.
Configuration
Keybindings
By default, all key bindings are prefixed with a value stored in
winum-keymap-prefix, by default C-x w. See Customize options.
The default prefix is C-x w for compatibility with native Emacs bindings.
However, it gives long key bindings and can be incomfortable to use.
For instance, you can replace the native prefix with C-c or M-m.
If you prefer no to use a prefix to have even shorter bindings, you can also
directly override winum-keymap:
(require 'winum)
(setcdr (assoc 'winum-mode minor-mode-map-alist)
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-`") 'winum-select-window-by-number)
(define-key map (kbd "M-0") 'winum-select-window-0-or-10)
(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)
This is a little bit hacky but is less code than using define-key, and will
also shadow the old bindings.
NB: the ` key is convenient on qwerty keyboards, however if you are using
a different keyboard you should replace it with the key beside 1.
For instance, ² on an azerty keyboard.
Customize options
Several options are available through Emacs' Customize interface under
convenience > winum:
winum-scopeFrames affected by a number set. Choices are'frame-local'visibleor'global. Default:'globalwinum-reverse-frame-listIf t, order frames by reverse order of creation. Has effect only whenwinum-scopeis not'frame-local. Default:nilwinum-auto-assign-0-to-minibufferIf non-nil,winum-modeassigns 0 to the minibuffer if active. Default:twinum-assign-funcFunction called for each window bywinum-mode. This is called before automatic assignment begins. The function should return a number to have it assigned to the current-window,nilotherwise. Default:nilExample: always assign Calculator the number 9 and NeoTree the number 0:
(defun my-winum-assign-func ()
(cond
((equal (buffer-name) "*Calculator*")
9)
((string-match-p (buffer-name) ".*\\*NeoTree\\*.*")
0)
(t
nil)))
(setq winum-assign-func 'my-winum-assign-func)
winum-auto-setup-mode-lineWhen nil,winum-modewill not display window numbers in the mode-line. You might want this to be nil if you use a package that already manages window numbers in the mode-line. Default:twinum-mode-line-positionThe position in the mode-linewinum-modedisplays the number. Default: 1winum-ignored-buffersList of buffers to ignore when selecting window. Default: '(" which-key")winum-keymap-prefixPrefix key sequence for keybindings. Default: (kbd "C-x w")- face:
winum-faceFace used for the number in the mode-line.
Configuration file example
Here is an example that you could put in your .emacs, which includes all
available winum options.
(add-to-list 'load-path "/path/to/install/folder/winum.el/")
(require 'winum)
(setcdr (assoc 'winum-mode minor-mode-map-alist)
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-`") 'winum-select-window-by-number)
(define-key map (kbd "M-0") 'winum-select-window-0-or-10)
(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))
(defun my-winum-assign-func ()
(cond
((equal (buffer-name) "*Calculator*")
9)
((string-match-p (buffer-name) ".*\\*NeoTree\\*.*")
0)
(t
nil)))
(set-face-attribute 'winum-face nil :weight 'bold)
(setq window-numbering-scope 'global
winum-reverse-frame-list nil
winum-auto-assign-0-to-minibuffer t
winum-assign-func 'my-winum-assign-func
winum-auto-setup-mode-line t
winum-mode-line-position 1
winum-ignored-buffers '(" *which-key*")
winum-keymap-prefix nil)
(winum-mode)