aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorAlexander Gramiak2017-07-22 12:16:08 +0300
committerEli Zaretskii2017-07-22 12:16:08 +0300
commitebb78a7bfa3e6a87cfb53f1f2b17fc2f61add595 (patch)
tree4a5e32ce7751b92194e349c5fa76489fd1ce0b6a /lisp
parent6d7e34b692edd61ac2f0872db521bcec321453cf (diff)
downloademacs-ebb78a7bfa3e6a87cfb53f1f2b17fc2f61add595.tar.gz
emacs-ebb78a7bfa3e6a87cfb53f1f2b17fc2f61add595.zip
Add a minor mode interface for display-line-numbers
* lisp/cus-start.el: Use the new display-line-numbers group. * lisp/display-line-numbers.el: New file. * doc/emacs/custom.texi (Init Rebinding): Re-add entry that used to belong to linum-mode. * doc/emacs/modes.texi (Minor Modes): Summarize the mode. * etc/NEWS: Document display-line-numbers-mode and its customization variables, and mention that display-line-numbers-width is buffer-local. * src/xdisp.c (syms_of_xdisp) <display-line-numbers-width>: Fix a typo.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/cus-start.el8
-rw-r--r--lisp/display-line-numbers.el103
2 files changed, 107 insertions, 4 deletions
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index ed913e32688..c28b8a147fc 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -584,7 +584,7 @@ since it could result in memory overflow and make Emacs crash."
584 (const :tag "Grow only" :value grow-only)) 584 (const :tag "Grow only" :value grow-only))
585 "25.1") 585 "25.1")
586 (display-raw-bytes-as-hex display boolean "26.1") 586 (display-raw-bytes-as-hex display boolean "26.1")
587 (display-line-numbers display 587 (display-line-numbers display-line-numbers
588 (choice 588 (choice
589 (const :tag "Off (nil)" :value nil) 589 (const :tag "Off (nil)" :value nil)
590 (const :tag "Absolute line numbers" 590 (const :tag "Absolute line numbers"
@@ -594,7 +594,7 @@ since it could result in memory overflow and make Emacs crash."
594 (const :tag "Visually relative line numbers" 594 (const :tag "Visually relative line numbers"
595 :value visual)) 595 :value visual))
596 "26.1") 596 "26.1")
597 (display-line-numbers-width display 597 (display-line-numbers-width display-line-numbers
598 (choice 598 (choice
599 (const :tag "Dynamically computed" 599 (const :tag "Dynamically computed"
600 :value nil) 600 :value nil)
@@ -602,14 +602,14 @@ since it could result in memory overflow and make Emacs crash."
602 :value 2 602 :value 2
603 :format "%v")) 603 :format "%v"))
604 "26.1") 604 "26.1")
605 (display-line-numbers-current-absolute display 605 (display-line-numbers-current-absolute display-line-numbers
606 (choice 606 (choice
607 (const :tag "Display actual number of current line" 607 (const :tag "Display actual number of current line"
608 :value t) 608 :value t)
609 (const :tag "Display zero as number of current line" 609 (const :tag "Display zero as number of current line"
610 :value nil)) 610 :value nil))
611 "26.1") 611 "26.1")
612 (display-line-numbers-widen display 612 (display-line-numbers-widen display-line-numbers
613 (choice 613 (choice
614 (const :tag "Disregard narrowing when calculating line numbers" 614 (const :tag "Disregard narrowing when calculating line numbers"
615 :value t) 615 :value t)
diff --git a/lisp/display-line-numbers.el b/lisp/display-line-numbers.el
new file mode 100644
index 00000000000..95237250f93
--- /dev/null
+++ b/lisp/display-line-numbers.el
@@ -0,0 +1,103 @@
1;;; display-line-numbers.el --- interface for display-line-numbers -*- lexical-binding: t -*-
2
3;; Copyright (C) 2017 Free Software Foundation, Inc.
4
5;; Maintainer: emacs-devel@gnu.org
6;; Keywords: convenience
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;; Provides a minor mode interface for `display-line-numbers'.
26;;
27;; Toggle display of line numbers with M-x display-line-numbers-mode.
28;; To enable line numbering in all buffers, use M-x
29;; global-display-line-numbers-mode. To change the default type of
30;; line numbers displayed, customize display-line-numbers-type.
31
32;; NOTE: Customization variables for `display-line-numbers' itself are
33;; defined in cus-start.el.
34
35;;; Code:
36
37(defgroup display-line-numbers nil
38 "Display line numbers in the buffer."
39 :group 'display)
40
41(defcustom display-line-numbers-type t
42 "The default type of line numbers to use in `display-line-numbers-mode'.
43See `display-line-numbers' for value options."
44 :group 'display-line-numbers
45 :type '(choice (const :tag "Relative line numbers" relative)
46 (const :tag "Relative visual line numbers" visual)
47 (other :tag "Absolute line numbers" t))
48 :version "26.1")
49
50(defcustom display-line-numbers-grow-only nil
51 "If non-nil, do not shrink line number width."
52 :group 'display-line-numbers
53 :type 'boolean
54 :version "26.1")
55
56(defcustom display-line-numbers-width-start nil
57 "If non-nil, count number of lines to use for line number width.
58When `display-line-numbers-mode' is turned on,
59`display-line-numbers-width' is set to the minimum width necessary
60to display all line numbers in the buffer."
61 :group 'display-line-numbers
62 :type 'boolean
63 :version "26.1")
64
65(defun display-line-numbers-update-width ()
66 "Prevent the line number width from shrinking."
67 (let ((width (line-number-display-width)))
68 (when (> width (or display-line-numbers-width 1))
69 (setq display-line-numbers-width width))))
70
71;;;###autoload
72(define-minor-mode display-line-numbers-mode
73 "Toggle display of line numbers in the buffer.
74This uses `display-line-numbers' internally.
75
76To change the type of line numbers displayed by default,
77customize `display-line-numbers-type'. To change the type while
78the mode is on, set `display-line-numbers' directly."
79 :lighter nil
80 (if display-line-numbers-mode
81 (progn
82 (when display-line-numbers-width-start
83 (setq display-line-numbers-width
84 (length (number-to-string
85 (count-lines (point-min) (point-max))))))
86 (when display-line-numbers-grow-only
87 (add-hook 'pre-command-hook #'display-line-numbers-update-width nil t))
88 (setq display-line-numbers display-line-numbers-type))
89 (remove-hook 'pre-command-hook #'display-line-numbers-update-width t)
90 (setq display-line-numbers nil)))
91
92;;;###autoload
93(define-globalized-minor-mode global-display-line-numbers-mode
94 display-line-numbers-mode
95 (lambda ()
96 (unless (or (minibufferp)
97 ;; taken from linum.el
98 (and (daemonp) (null (frame-parameter nil 'client))))
99 (display-line-numbers-mode))))
100
101(provide 'display-line-numbers)
102
103;;; display-line-numbers.el ends here