• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    Emacs Lisp
  • Created almost 8 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Window numbers for Emacs - Navigate windows and frames using numbers

Window numbers for Emacs !

https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg https://melpa.org/packages/winum-badge.svg https://stable.melpa.org/packages/winum-badge.svg

Contents

Introduction

Window numbers for Emacs: Navigate your windows and frames using numbers !

This package is an extended and actively maintained version of the window-numbering package by Nikolaj Schumacher, with some ideas and code taken from 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.

Changelog

Sep. 11 2019

  • Added customize variable winum-ignored-buffers-regexp to ignored buffers based on regexps.

Nov. 15 2018

  • Added customize variable winum-format, a format string to configure how the window number appears in the mode-line

Initial release: what’s changed since window-numbering

This package brings a lot of additions to the old window-numbering:

  • Number sets across multiple frames, giving a smoother experience of multi-screen Emacs
  • 3 possible scopes: frame-local, visible frames or all frames
  • get-window-by-number public function, needed in Spacemacs and for future developments.
  • Unlimited window numbers
  • select-window-by-number can now be used interactively to select a window using prefix arg or read-from-minibuffer, allowing the selection of an unlimited number.
  • Ignore buffers by name
  • ;;;###autoload all functions that should have public visibility
  • Improved customize integration
  • Removed window-numbering-before-assign-hook, which just duplicated window-numbering-assign-func in a more complicated fashion
  • New default key bindings under the C-x w prefix, to be compliant with Emacs key bindings conventions and native Emacs key bindings
  • winum-set-keymap-prefix helper function to change the prefix more easily
  • More detailed README.org
  • Improved docstrings
  • Simplified implementation for better readability

Installation

Using Melpa

The recommended way of installing winum is from the Melpa package repository:

M-x package-install RET winum RET

You will find instructions to setup Melpa here if you don’t have it setup yet.

Once the package is installed, you need to load and activate winum-mode in your Emacs configuration:

(require 'winum)

(winum-mode)

Manual installation

  • Clone the repo:
cd /path/to/install/folder
git clone https://github.com/deb0ch/emacs-winum
  • Add the following to your Emacs configuration:
(add-to-list 'load-path "/path/to/install/folder/emacs-winum/")

(require 'winum)

(winum-mode)

How to use

Key bindingDescription
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-10

    By default, C-x w 0 is bound to select-window-0-or-10. 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 prefer.

  • select-window-by-number

    If you happen to have more than 10 windows, you can use the select-window-by-number function, bound by default to C-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.

Configuration

Keybindings

The default prefix for key bindings 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 function winum-set-keymap-prefix:

(winum-set-keymap-prefix (kbd "C-c"))

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. 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:

(setq winum-keymap
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd "C-`") 'winum-select-window-by-number)
      (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))

(require 'winum)

(winum-mode)

Note that it is important to set winum-keymap before the require.

You can also use the more conventional define-key on winum-keymap:

(define-key winum-keymap (kbd "C-x y o l o") 'winum-select-window-by-number)

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

Several options are available through Emacs’ Customize interface under convenience > winum:

  • winum-scope

    Frames affected by a number set. Choices are ‘frame-local ‘visible or ‘global.

    Default: ‘global

  • winum-reverse-frame-list

    If t, order frames by reverse order of creation. Has effect only when winum-scope is not ‘frame-local.

    Default: nil

  • winum-auto-assign-0-to-minibuffer

    If non-nil, winum-mode assigns 0 to the minibuffer if active.

    Default: t

  • winum-assign-functions

    List of functions called for each window by `winum-mode’.

    These functions allow for deterministic assignment of numbers to windows. Each function is called for every window. A function should return the number to be assigned to a window or nil. The first function to output a number for a given window will determine this window’s number (if more than 1 function assigns a number a warning will be logged in the messages buffer).

    If the list is empty or if every function returns nil for a given window winum will proceed to automatic number assignment.

    Since this list is meant to allow custom window assignment for mutiple packages at once it should never be directly set, only added to and removed from.

    These functions, along with winum-auto-assign-0-to-minibuffer, are the only way to have 0 assigned to a window.

    Example: always assign Calculator the number 9 and NeoTree the number 0:

    (defun winum-assign-9-to-calculator-8-to-flycheck-errors ()
      (cond
       ((equal (buffer-name) "*Calculator*") 9)
       ((equal (buffer-name) "*Flycheck errors*") 8)))
    
    (defun winum-assign-0-to-neotree ()
      (when (string-match-p (buffer-name) ".*\\*NeoTree\\*.*") 10))
    
    (add-to-list 'winum-assign-functions #'winum-assign-9-to-calculator-8-to-flycheck-errors)
    (add-to-list 'winum-assign-functions #'winum-assign-0-to-neotree)
        

    Default: nil

  • winum-auto-setup-mode-line

    When nil, winum-mode will 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: t

  • winum-format

    Format string defining how the window number looks like in the mode-line. This string is passed to the format function along with the result of winum-get-number-string.

    Default: =” %s “=

  • winum-mode-line-position

    The position in the mode-line winum-mode displays the number.

    Default: 1

  • winum-ignored-buffers

    List of buffers to ignore when assigning numbers.

    Default: ‘(” which-key”)

  • winum-ignored-buffers-regexp

    List of regexps for buffer names. Matching buffers will be ignored when assigning numbers. See Emacs’ documentation on regexps for syntax.

    Default: ‘()

  • face: winum-face

    Face 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.

(setq winum-keymap
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd "C-`") 'winum-select-window-by-number)
      (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))

(require 'winum)

(defun winum-assign-9-to-calculator-8-to-flycheck-errors ()
  (cond
   ((equal (buffer-name) "*Calculator*") 9)
   ((equal (buffer-name) "*Flycheck errors*") 8)))

(defun winum-assign-0-to-neotree ()
  (when (string-match-p (buffer-name) ".*\\*NeoTree\\*.*") 10))

(add-to-list 'winum-assign-functions #'winum-assign-9-to-calculator-8-to-flycheck-errors)
(add-to-list 'winum-assign-functions #'winum-assign-0-to-neotree)

(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-format                      " %s "
      winum-mode-line-position          1
      winum-ignored-buffers             '(" *which-key*")
      winum-ignored-buffers-regexp      '(" \\*Treemacs-.*"))

(winum-mode)

Future developments

  • send buffer to numbered window

    Send current window’s buffer to window N. With prefix argument focus will follow.

  • swap buffer with numbered window

    Same as previous, but will swap buffers instead of just sending them.

  • Evilify

    Adapt the package to the famous `evil-mode` and use a leader key.

  • Override native other-window (C-x o) to use window numbers
  • Autocomplete read-from-minibuffer
  • Things that you have thought of and I haven’t 😸

More Repositories

1

PE-Injector

A small, useless, self-replicating virus that injects itself into a windows executable binary. Upon execution, it will infect all the other executables in the same directory, which, in turn, will display a message box and infect all other executables in their directory when executed.
Assembly
13
star
2

toorkit

A simple useless rootkit for the linux kernel. It is a kernel module which hooks up the open() syscall (or potentially any syscall) to replace it with a custom function.
C
12
star
3

strace

strace is a recode of the standard Linux program strace. It traces the execution of other programs to print their syscalls and their arguments. You can run the program as a command-line argument or attach to an already existing process using its PID.
C
7
star
4

R-Type

A remake of the famous game R-Type. It is coded using the Entity-Component-System pattern, can be played up to 4 players through network and is cross-platform Linux/Windows.
C
5
star
5

dxlServo

DxlServo is a C++ object/library made for simplifying the use of Dynamixel AX-12a servomotors in C++ projects.
C++
4
star
6

.spacemacs.d

My personnal spacemacs configuration
Emacs Lisp
3
star
7

yolofs

A simple useless pseudo-filesystem, coded for discovering the challenges of interfacing a filesystem with Linux VFS. It adds an "encryption" feature (a simple rotation of n, n given as an argument to mount).
C
3
star
8

ftrace

ftrace is a program tracer. It traces the execution of a program to draw a call graph of each and every function call using Dotty, either internal functions, static or shared libraries, or syscalls.
Makefile
3
star
9

steps

A simple helper tool for scripting tutorials / install processes
Shell
2
star
10

yolok

Yolok is a simple useless kernel, coded for discovering the many challenges of creating a kernel on a x86 architecture.
C
2
star
11

SubtitlesTimeMachine

A simple tool for shifting the times of a .srt file. Useful when the speech and the subtitles do not match in a movie.
Go
1
star
12

bullets-api

The backend part of a personal project of a life organiser, starting as a tiny Todo list app.
JavaScript
1
star
13

bullets

A personal project of a life organiser, starting as a tiny Todo list app.
JavaScript
1
star
14

myOCR

A simple Optical Character Recognition program, using a KNN classifier.
Java
1
star
15

YoloKernelModule

A simple useless Loadable Kernel Module for Linux, creating a dummy misc device in /dev containing a string modifiable with ioctl().
C
1
star
16

cop21project_embedded

C++
1
star
17

Nibbler

A snake-like game for Linux. Eat fruits, grow your snake, max your score but don't crash into a wall !
C++
1
star
18

animatedBaballe

Dummy project for playing around with react Native, Animated, Fastlane and other shiny toys
JavaScript
1
star
19

ansible-role-spacemacs

An Ansible role for installing Spacemacs with Emacs built from source
1
star
20

CreepyFirmware

Creepyfirmware is the code running Creepi, a little creepy robotic arm with a webcam tracking people's faces.
C++
1
star
21

Algogen

Some tests and tryouts abouts genetic algorithms
Python
1
star
22

sokoboule

A little Mario Sokoban based on the tutorial on openclassrooms.com (formerly Le Site Du Zero). My first program ever <3
C
1
star
23

Bullets-Meteor

JavaScript
1
star