From: Alex <agrambot@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Native line numbers landed on master
Date: Tue, 11 Jul 2017 14:44:13 -0600 [thread overview]
Message-ID: <87pod67lgi.fsf@lylat> (raw)
In-Reply-To: <834lujj9d5.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 11 Jul 2017 18:12:22 +0300")
[-- Attachment #1: Type: text/plain, Size: 2813 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Alex <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org
>> Date: Mon, 10 Jul 2017 14:31:46 -0600
>>
>> I'm not sure if there's a convention for this (built-in feature with a
>> Lisp-level mode wrapper) situation, but it might be nice to separate the
>> variables that are directly linked to display-line-numbers and ones that
>> only are used in the minor mode wrapper.
>>
>> What about defining the defgroup in cus-edit.el, making both these
>> variables and the ones in cus-start belong to it?
>
> Sounds OK to me, thanks. I think we do want all the variables to
> appear in the same customization group, even if they are defined
> separately.
Well, it seems this cus-edit change doesn't fix it by itself. When
executing customize-group without display-line-numbers loaded, then the
lisp-level defcustoms aren't shown. It might be because there's a
missing entry in cus-load.el, but I don't know how to add a group to it.
linum, for instance, appears to automatically be added to it.
Would it be better to skip creating a new defgroup and have all
variables just be in the display group, or are you in favour of a new
group just for line numbers?
>> I don't know if the file should be pre/auto-loaded. Is there a reason to
>> do so considering linum.el isn't?
>
> linum.el _is_ autoloaded if you invoke linum-mode, no?
Right, I was referring to the defcustoms.
> The scenario I had in mind was a user doing this:
>
> M-x set-variable RET display-line-numbers RET t RET
>
> This is a legitimate way of activating the feature in a buffer. Do we
> want then the user to automatically have access to all the
> customizations and features in display-line-numbers.el?
As is stands, the contents of display-line-numbers.el only applies to
the minor modes and not display-line-numbers itself. So the user would
have to call one of the minor modes to use the features, and at that
point everything will be loaded.
I thought about autoloading the defcustoms, but it seems as if that's a
contentious decision[1].
> That was to fix a bug that I think shouldn't happen with the native
> implementation, because it doesn't count lines.
So even a single count-lines on the whole buffer is too much?
>> Does the problem affect display-line-numbers?
>
> I don't think so, but it should be easy to test. I'll take a look.
If so, then I'll leave it in.
>> P.S. I also noticed that the docstring for display-line-numbers doesn't
>> describe the 'relative value, or state that 'visual also uses relative
>> line numbers.
>
> Thanks, I fixed this.
Thanks, though it seems like your copyedit commit introduced a couple
typos. It also doesn't mention that any other non-nil value is treated
as t.
I've attached an updated patch. I didn't update the commit message yet.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v2 --]
[-- Type: text/x-diff, Size: 8465 bytes --]
From d0e76628503adc7fd6a4a41c61954f305d6f2ac5 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Sun, 9 Jul 2017 16:40:52 -0600
Subject: [PATCH] Add minor mode interface for display-line-numbers
* lisp/display-line-numbers.el: New file.
* lisp/menu-bar (menu-bar-showhide-menu): Use global minor mode.
(toggle-display-line-numbers): Remove.
---
lisp/cus-edit.el | 4 ++
lisp/cus-start.el | 8 ++--
lisp/display-line-numbers.el | 99 ++++++++++++++++++++++++++++++++++++++++++++
| 14 ++-----
4 files changed, 110 insertions(+), 15 deletions(-)
create mode 100644 lisp/display-line-numbers.el
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 6dbb45ec6b..6dde2faf92 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -380,6 +380,10 @@ display
"How characters are displayed in buffers."
:group 'environment)
+(defgroup display-line-numbers nil
+ "Display line numbers in the buffer."
+ :group 'display)
+
(defgroup execute nil
"Executing external commands."
:group 'processes)
diff --git a/lisp/cus-start.el b/lisp/cus-start.el
index e0290395ad..117b336a65 100644
--- a/lisp/cus-start.el
+++ b/lisp/cus-start.el
@@ -584,7 +584,7 @@ minibuffer-prompt-properties--setter
(const :tag "Grow only" :value grow-only))
"25.1")
(display-raw-bytes-as-hex display boolean "26.1")
- (display-line-numbers display
+ (display-line-numbers display-line-numbers
(choice
(const :tag "Off (nil)" :value nil)
(const :tag "Absolute line numbers"
@@ -594,7 +594,7 @@ minibuffer-prompt-properties--setter
(const :tag "Visually relative line numbers"
:value visual))
"26.1")
- (display-line-number-width display
+ (display-line-number-width display-line-numbers
(choice
(const :tag "Dynamically computed"
:value nil)
@@ -602,14 +602,14 @@ minibuffer-prompt-properties--setter
:value 2
:format "%v"))
"26.1")
- (display-line-numbers-current-absolute display
+ (display-line-numbers-current-absolute display-line-numbers
(choice
(const :tag "Display actual number of current line"
:value t)
(const :tag "Display zero as number of current line"
:value nil))
"26.1")
- (display-line-numbers-widen display
+ (display-line-numbers-widen display-line-numbers
(choice
(const :tag "Disregard narrowing when calculating line numbers"
:value t)
diff --git a/lisp/display-line-numbers.el b/lisp/display-line-numbers.el
new file mode 100644
index 0000000000..cca537a17b
--- /dev/null
+++ b/lisp/display-line-numbers.el
@@ -0,0 +1,99 @@
+;;; display-line-numbers.el --- interface for display-line-numbers -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Maintainer: emacs-devel@gnu.org
+;; Keywords: convenience
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Provides a minor mode interface for `display-line-numbers'.
+;;
+;; Toggle display of line numbers with M-x display-line-numbers-mode.
+;; To enable line numbering in all buffers, use M-x
+;; global-display-line-numbers-mode. To change the default type of
+;; line numbers displayed, customize display-line-number-type.
+
+;; NOTE: Customization variables for `display-line-numbers' itself are
+;; defined in cus-start.el.
+
+;;; Code:
+
+(defcustom display-line-number-type t
+ "Sets the type of line numbers to use in `display-line-number-mode'.
+See `display-line-numbers' for value options."
+ :group 'display-line-numbers
+ :type '(choice (const :tag "Relative line numbers" relative)
+ (const :tag "Relative visual line numbers" visual)
+ (other :tag "Absolute line numbers" t))
+ :version "26.1")
+
+(defcustom display-line-numbers-grow-only nil
+ "If non-nil, do not shrink line number width."
+ :group 'display-line-numbers
+ :type 'boolean
+ :version "26.1")
+
+(defcustom display-line-number-width-start nil
+ "If non-nil, count number of lines to use for line number width.
+When `display-line-number-mode' is turned on,
+`display-line-number-width' is set to the minimum width necessary
+to display all line numbers in the buffer."
+ :group 'display-line-numbers
+ :type 'boolean
+ :version "26.1")
+
+(defun display-line-numbers-update-width ()
+ "Prevent the line number width from shrinking."
+ (let ((width (line-number-display-width)))
+ (when (> width (or display-line-number-width 1))
+ (setq display-line-number-width width))))
+
+;;;###autoload
+(define-minor-mode display-line-numbers-mode
+ "Toggle display of line numbers in the buffer.
+This uses `display-line-numbers' internally.
+
+To change the type of line numbers displayed by default,
+customize `display-line-number-type'. To change the type while
+the mode is on, set `display-line-numbers' directly."
+ :lighter nil
+ (if display-line-numbers-mode
+ (progn
+ (when display-line-number-width-start
+ (setq display-line-number-width
+ (length (number-to-string
+ (count-lines (point-min) (point-max))))))
+ (when display-line-numbers-grow-only
+ (add-hook 'pre-command-hook #'display-line-numbers-update-width nil t))
+ (setq display-line-numbers display-line-number-type))
+ (remove-hook 'pre-command-hook #'display-line-numbers-update-width t)
+ (setq display-line-numbers nil)))
+
+;;;###autoload
+(define-globalized-minor-mode global-display-line-numbers-mode
+ display-line-numbers-mode
+ (lambda ()
+ (unless (or (minibufferp)
+ ;; taken from linum.el
+ (and (daemonp) (null (frame-parameter nil 'client))))
+ (display-line-numbers-mode))))
+
+(provide 'display-line-numbers)
+
+;;; display-line-numbers.el ends here
--git a/lisp/menu-bar.el b/lisp/menu-bar.el
index 3ca7d1b5b3..434dd9b91f 100644
--- a/lisp/menu-bar.el
+++ b/lisp/menu-bar.el
@@ -1101,23 +1101,15 @@ menu-bar-showhide-tool-bar-menu-customize-enable-bottom
:button (:radio . (eq tool-bar-mode nil))))
menu)))
-(defun toggle-display-line-numbers ()
- (interactive)
- (if display-line-numbers
- (setq display-line-numbers nil)
- (setq display-line-numbers t))
- (force-mode-line-update))
-
(defvar menu-bar-showhide-menu
(let ((menu (make-sparse-keymap "Show/Hide")))
(bindings--define-key menu [display-line-numbers]
`(menu-item "Line Numbers for All Lines"
- ,(lambda ()
- (interactive)
- (toggle-display-line-numbers))
+ global-display-line-numbers-mode
:help "Show the line number alongside each line"
- :button (:toggle . display-line-numbers)))
+ :button (:toggle . (bound-and-true-p
+ global-display-line-numbers-mode))))
(bindings--define-key menu [column-number-mode]
(menu-bar-make-mm-toggle column-number-mode
--
2.13.2
[-- Attachment #3: Type: text/plain, Size: 59 bytes --]
Footnotes:
[1] https://emacs.stackexchange.com/a/32860
next prev parent reply other threads:[~2017-07-11 20:44 UTC|newest]
Thread overview: 129+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-08 7:58 Native line numbers landed on master Eli Zaretskii
2017-07-08 8:41 ` martin rudalics
2017-07-08 10:23 ` Eli Zaretskii
2017-07-08 22:38 ` Alex
2017-07-09 14:22 ` Eli Zaretskii
2017-07-09 22:56 ` Alex
2017-07-10 17:50 ` Eli Zaretskii
2017-07-10 20:31 ` Alex
2017-07-11 15:12 ` Eli Zaretskii
2017-07-11 20:44 ` Alex [this message]
2017-07-12 14:40 ` Eli Zaretskii
2017-07-16 7:30 ` Alex
2017-07-16 14:10 ` Eli Zaretskii
2017-07-16 19:31 ` Alex
2017-07-17 15:00 ` Eli Zaretskii
2017-07-17 20:34 ` Alex
2017-07-22 9:18 ` Eli Zaretskii
2017-07-10 22:19 ` John Wiegley
2017-07-11 2:29 ` Eli Zaretskii
2017-07-11 15:27 ` Stefan Monnier
2017-07-11 16:04 ` Eli Zaretskii
2017-07-11 16:16 ` Stefan Monnier
2017-07-11 17:23 ` Eli Zaretskii
2017-07-11 17:48 ` Stefan Monnier
2017-07-11 18:04 ` Eli Zaretskii
2017-07-11 18:19 ` Stefan Monnier
2017-07-11 18:18 ` Sharp-quoting function symbols (Was: Native line numbers landed on master) Kaushal Modi
2017-09-30 18:36 ` Philipp Stephani
2017-12-30 21:09 ` Philipp Stephani
2017-07-10 16:51 ` Native line numbers landed on master Filipe Silva
2017-07-11 13:00 ` Robert Pluim
2017-07-11 13:37 ` Jean-Christophe Helary
2017-07-11 13:47 ` Robert Pluim
2017-07-11 14:19 ` Jean-Christophe Helary
2017-07-11 15:24 ` Eli Zaretskii
2017-07-11 15:29 ` Robert Pluim
2017-07-11 16:07 ` Eli Zaretskii
2017-07-11 16:12 ` Robert Pluim
2017-07-11 17:33 ` Eli Zaretskii
2017-07-12 3:23 ` Kaushal Modi
2017-07-12 7:11 ` martin rudalics
2017-07-12 14:27 ` Eli Zaretskii
2017-07-12 15:49 ` martin rudalics
2017-07-15 22:02 ` Yuri D'Elia
2017-07-16 2:34 ` Eli Zaretskii
2017-07-16 14:25 ` Eli Zaretskii
2017-07-17 9:44 ` Yuri D'Elia
2017-07-17 14:16 ` Eli Zaretskii
2019-06-10 2:46 ` Juanma Barranquero
2019-06-10 8:32 ` Yuri D'Elia
2019-06-10 12:38 ` Juanma Barranquero
2019-06-10 15:22 ` Eli Zaretskii
2019-06-10 15:32 ` Juanma Barranquero
2019-06-10 15:33 ` Yuri D'Elia
2019-06-10 15:54 ` Eli Zaretskii
2019-06-10 16:23 ` Yuri D'Elia
2019-06-10 17:41 ` Eli Zaretskii
2019-09-30 10:01 ` Juanma Barranquero
2019-09-30 10:21 ` Eli Zaretskii
2019-10-01 5:44 ` Juanma Barranquero
2019-10-01 7:05 ` Eli Zaretskii
2019-10-01 8:49 ` Juanma Barranquero
2019-10-01 8:55 ` Juanma Barranquero
2019-10-01 9:26 ` Eli Zaretskii
2019-10-01 9:25 ` Eli Zaretskii
2019-10-01 9:09 ` Yuri D'Elia
2019-10-01 9:21 ` Juanma Barranquero
2019-10-01 9:51 ` Yuri D'Elia
2019-10-01 10:23 ` Juanma Barranquero
2019-10-01 10:40 ` Yuri D'Elia
2019-10-01 10:39 ` Eli Zaretskii
2019-10-01 10:47 ` Lars Ingebrigtsen
2019-10-01 11:07 ` Eli Zaretskii
2019-10-01 11:11 ` Juanma Barranquero
2019-10-01 22:52 ` Ergus
2019-10-01 23:51 ` Juanma Barranquero
2019-10-02 3:41 ` Ergus
2019-10-02 9:40 ` Juanma Barranquero
2019-10-02 13:56 ` Ergus
2019-10-02 15:06 ` Eli Zaretskii
2019-10-03 4:11 ` Juanma Barranquero
2019-10-03 8:16 ` martin rudalics
2019-10-03 14:43 ` Juanma Barranquero
2019-10-03 9:10 ` Robert Pluim
2019-10-03 14:47 ` Juanma Barranquero
2019-10-03 15:18 ` Robert Pluim
2019-10-03 20:37 ` Stefan Kangas
2019-10-03 21:48 ` Juanma Barranquero
2019-10-03 22:37 ` Yuri D'Elia
2019-10-04 1:51 ` Juanma Barranquero
2019-10-04 7:45 ` Eli Zaretskii
2019-10-04 9:52 ` Yuri D'Elia
2019-10-04 10:24 ` Juanma Barranquero
2019-10-05 6:26 ` Juanma Barranquero
2019-10-07 0:14 ` Juanma Barranquero
2019-10-07 6:54 ` Robert Pluim
2019-10-07 7:39 ` Juanma Barranquero
2019-10-07 8:09 ` Robert Pluim
2019-10-07 8:39 ` Juanma Barranquero
2019-10-07 18:52 ` Juri Linkov
2019-10-08 0:57 ` Juanma Barranquero
2019-10-19 20:38 ` Juri Linkov
2019-10-07 16:30 ` Eli Zaretskii
2019-10-08 11:15 ` Robert Pluim
2019-10-08 12:23 ` Eli Zaretskii
2019-10-09 7:19 ` Robert Pluim
2019-10-09 8:16 ` Eli Zaretskii
2019-10-09 12:14 ` Robert Pluim
2019-10-09 12:23 ` Eli Zaretskii
2019-10-09 13:19 ` Robert Pluim
2019-10-09 10:51 ` Juanma Barranquero
2019-10-04 10:22 ` Ergus
2019-10-04 10:26 ` Juanma Barranquero
2019-10-03 12:28 ` Yuri Khan
2019-10-03 14:48 ` Juanma Barranquero
2019-10-03 17:56 ` Yuri D'Elia
2019-10-03 18:40 ` Eli Zaretskii
2019-10-03 19:01 ` Yuri D'Elia
2019-10-04 2:01 ` Juanma Barranquero
2019-10-04 5:01 ` Juanma Barranquero
2019-10-04 15:57 ` Johan Bockgård
2019-10-04 17:28 ` Juanma Barranquero
2019-10-04 19:24 ` Stefan Monnier
2019-10-04 20:12 ` Yuri D'Elia
2019-10-04 22:45 ` Juanma Barranquero
2019-10-06 14:04 ` Juanma Barranquero
2019-10-06 14:45 ` Juanma Barranquero
2019-10-06 18:02 ` Eli Zaretskii
2019-10-01 9:24 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pod67lgi.fsf@lylat \
--to=agrambot@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.