From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alex Newsgroups: gmane.emacs.devel Subject: Re: Native line numbers landed on master Date: Tue, 11 Jul 2017 14:44:13 -0600 Message-ID: <87pod67lgi.fsf@lylat> References: <83k23jl5ra.fsf@gnu.org> <87r2xqo8p7.fsf@lylat> <83lgnxk7v6.fsf@gnu.org> <87shi5jk2w.fsf@lylat> <83lgnwi3k3.fsf@gnu.org> <87a84crq31.fsf@lylat> <834lujj9d5.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1499805967 4134 195.159.176.226 (11 Jul 2017 20:46:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Jul 2017 20:46:07 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 11 22:46:01 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dV22a-0000HD-B8 for ged-emacs-devel@m.gmane.org; Tue, 11 Jul 2017 22:45:52 +0200 Original-Received: from localhost ([::1]:48884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dV22f-0001vO-Rb for ged-emacs-devel@m.gmane.org; Tue, 11 Jul 2017 16:45:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dV22X-0001v7-F3 for emacs-devel@gnu.org; Tue, 11 Jul 2017 16:45:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dV22S-0007Kx-Hg for emacs-devel@gnu.org; Tue, 11 Jul 2017 16:45:49 -0400 Original-Received: from mail-io0-f194.google.com ([209.85.223.194]:35261) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dV22S-0007AS-8a; Tue, 11 Jul 2017 16:45:44 -0400 Original-Received: by mail-io0-f194.google.com with SMTP id 84so342720iop.2; Tue, 11 Jul 2017 13:45:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=Kn7UviqLo8el4UbRzsoIK/culQpGqXzMlRcfFRaJzlo=; b=FKCpoIYmnf0fKnN3Uhv6NCOzzr2T3MxzlgYeuPZAYTPUtnFHuH5ycQVcw++pWkaOTT mG5m3SRPCRyJhdKRHrvAlF1A15K3WRIXQRtga47yT5z0HeTkHHVZcHRqanym3NkNPRpV 1jbsu2ezleXaIGW43+N3y4cAvyX7YiLgoxRNeisJ7ndjNiN/egnYHWgL4Xa/Q2EBDUt4 VF/zjQQm76Duok+bq3l5xLzha6R5AEJ1N7UtWd0ZqJWroZEHu0o1PQaBjbIrIXyWBnDb 7nS9caqUT6qWhonDi665+WgSd4QW9Wp859Z+dPmWT7i7f2mqkEI7b6xxjNLXTsOwqP1N 0TPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=Kn7UviqLo8el4UbRzsoIK/culQpGqXzMlRcfFRaJzlo=; b=JJn97xhG4cLBFb7fp0SEcgZXFNQw6p1xg8PhMLIy+s5atILEzTFQYpBG9pp8Zu3iMe BNTofXOvIHnXdnUJx0c7eFG3s9/mo74nb/0xl3wRT1DIwoCp0ZxUw1r1IZrBqqU3ekd/ z2rs3VJRqyn7sS7AJzabM1tzT0FBgBGHnqJN5bGM0B0V2lVuX1scISIrE6P8hTJNavCM 0o9bcsHjengY6TJP9Er178iMp0c3fzWmYBmfpkfBmZkCb7V3NG2QroY3oY8GIsSXbiPV C11my0P5yiDGN90WJW6+tpejIMi04KsuSfF038SSAXlM49n9TXC57KG8JAYBDUdYLzRO ECZA== X-Gm-Message-State: AIVw111cupM1yUmsZ/ZK88uT1HLoCYUtbMywn0Lv3riSN6W0qaSvUrC4 nhvEBpDNrXl6ZuVU X-Received: by 10.107.154.12 with SMTP id c12mr2027847ioe.228.1499805860268; Tue, 11 Jul 2017 13:44:20 -0700 (PDT) Original-Received: from lylat (S010664777d9cebe3.ss.shawcable.net. [70.64.85.59]) by smtp.gmail.com with ESMTPSA id q133sm504408ioe.58.2017.07.11.13.44.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jul 2017 13:44:18 -0700 (PDT) In-Reply-To: <834lujj9d5.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 11 Jul 2017 18:12:22 +0300") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.223.194 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:216502 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Alex >> 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-minor-mode-interface-for-display-line-numbers.patch Content-Description: v2 >From d0e76628503adc7fd6a4a41c61954f305d6f2ac5 Mon Sep 17 00:00:00 2001 From: Alexander Gramiak 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 ++++++++++++++++++++++++++++++++++++++++++++ lisp/menu-bar.el | 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 . + +;;; 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 diff --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 --=-=-= Content-Type: text/plain Footnotes: [1] https://emacs.stackexchange.com/a/32860 --=-=-=--