diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/cus-start.el | 8 | ||||
| -rw-r--r-- | lisp/display-line-numbers.el | 103 |
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'. | ||
| 43 | See `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. | ||
| 58 | When `display-line-numbers-mode' is turned on, | ||
| 59 | `display-line-numbers-width' is set to the minimum width necessary | ||
| 60 | to 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. | ||
| 74 | This uses `display-line-numbers' internally. | ||
| 75 | |||
| 76 | To change the type of line numbers displayed by default, | ||
| 77 | customize `display-line-numbers-type'. To change the type while | ||
| 78 | the 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 | ||