This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+misc/nlinum/packages.el
jcaw d4cca74854 Add support for visual line numbers
Emacs 26 added built-in support for line numbers, relative line numbers, and
visual line numbers. Spacemacs supports only absolute and relative, but there is
no way to access the visual mode. It's hard to get around this, since Spacemacs
abstracts line numbers to a reasonably high degree.

Arguably, `visual` is much more useful than `relative` as a display type. Visual
line numbers are like relative line numbers, but only lines that are actually
showing are counted. This means:

  1. Hidden lines are not counted. If a large amount of text is folded, the line
     numbers won't jump from "10" to "546". This is particularly useful in
     buffers like `magit-status`, where a large amount of information is folded
     by default.

  2. Lines that are wrapped are counted as multiple lines, since they're being
     displayed as multiple lines in the editor. Each visual line will be
     numbered - unlike `relative`, where the entire thing is numbered... Once.

With standard relative line numbers, you can't actually navigate using the line
numbers in the sidebar as soon as folded or wrapped lines are introduced. Since
this is one of the main use cases for relative line numbers, this is a big
problem.

Visual mode fixes that problem. Every line that's being displayed is labelled.
Numbers always correspond to the actual number of lines you'd need to navigate
to reach that line.

This commit extends Spacemacs' line number interface to provide visual line
number support.
2019-06-23 19:16:44 +02:00

56 lines
2 KiB
EmacsLisp

;;; packages.el --- nlinum Layer packages File
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(if (version< emacs-version "26")
(progn
(defconst nlinum-packages
'(
(linum :excluded t)
(linum-relative :excluded t)
(display-line-numbers :excluded t)
nlinum
nlinum-relative
))
(defun nlinum/init-nlinum ()
(use-package nlinum
:init
(spacemacs|add-toggle line-numbers
:mode nlinum-mode
:documentation "Show the line numbers."
:evil-leader "tn")
:config
(progn
(if (or (eq dotspacemacs-line-numbers t)
(eq dotspacemacs-line-numbers 'relative)
(eq dotspacemacs-line-numbers 'visual))
(progn
(add-hook 'prog-mode-hook 'nlinum-mode)
(add-hook 'text-mode-hook 'nlinum-mode))
(add-hook 'after-change-major-mode-hook 'spacemacs/nlinum-maybe-on))
(setq nlinum-format "%4d"))))
(defun nlinum/init-nlinum-relative ()
(use-package nlinum-relative
:commands (nlinum-relative-toggle nlinum-relative-on)
:init
(progn
(setq nlinum-relative-current-symbol ""
nlinum-relative-redisplay-delay 0)
(when (or (spacemacs/visual-line-numbers-p)
(spacemacs/relative-line-numbers-p))
(nlinum-relative-setup-evil)
(add-hook 'nlinum-mode-hook 'nlinum-relative-on))
(spacemacs/set-leader-keys "tr" 'spacemacs/nlinum-relative-toggle)))))
(defconst nlinum-packages nil)
(spacemacs-buffer/warning (concat "nlinum layer is deprecated for Emacs 26.1 and above."
" You can safely remove it from your dotfile.")))