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: Sun, 09 Jul 2017 16:56:23 -0600 Message-ID: <87shi5jk2w.fsf@lylat> References: <83k23jl5ra.fsf@gnu.org> <87r2xqo8p7.fsf@lylat> <83lgnxk7v6.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1499641106 25224 195.159.176.226 (9 Jul 2017 22:58:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 9 Jul 2017 22:58:26 +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 Mon Jul 10 00:58:20 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 1dUL9f-0006E1-Mv for ged-emacs-devel@m.gmane.org; Mon, 10 Jul 2017 00:58:19 +0200 Original-Received: from localhost ([::1]:37762 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUL9l-0003uE-7Q for ged-emacs-devel@m.gmane.org; Sun, 09 Jul 2017 18:58:25 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUL90-0003u7-Cu for emacs-devel@gnu.org; Sun, 09 Jul 2017 18:57:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUL8x-0004VW-7c for emacs-devel@gnu.org; Sun, 09 Jul 2017 18:57:38 -0400 Original-Received: from mail-it0-f66.google.com ([209.85.214.66]:35838) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dUL8w-0004Uo-Ti; Sun, 09 Jul 2017 18:57:35 -0400 Original-Received: by mail-it0-f66.google.com with SMTP id v193so10762326itc.2; Sun, 09 Jul 2017 15:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version; bh=+X+PRTHD2SXuA+IpYJf9X8wc2aHQkwBTWtXFLTfnplg=; b=PsCUgEtAMQxr0WJStLGBCJ5vQYCtA8HHtkG9vpfGSp14EB8zcDdcVYPnI5Zwi5c0Zb 1Gfol3FnY1MgekwHav6w0RWcZgj1eqcT6dfJlB2ZuJERfKf/CefJWl//IOzmjJGM72pY 5CNKbz2r0bWf2Pmqy9Q3TF9K5e0qA9PpTrV8bhndlNJIRrmAp5J3+sh1IFQ3bipeZpbS jOwwFldi7L2J7X1Whk3yZCcL4w5NSn80hN/YjFtQR/ork0j72HQBCOZb5g/6fracsVUH KhmzAoiIyYaWSDlmyRrRcHRvSJ2N2H65kj+pbZCoRs5XmGCn5mDnopUU/Lizn1RrNQ6l QJXA== 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:in-reply-to:references :user-agent:date:message-id:mime-version; bh=+X+PRTHD2SXuA+IpYJf9X8wc2aHQkwBTWtXFLTfnplg=; b=dQviQE0/VUhOrFYptl+Lkag5XX+c0x+hEliawfyH27fVRA83EZB6/s14VCyoVGdvrL tMcFtZqee9D+iokbhpXUZx6PfnoYHGjESAV02K6H0nvPzlCUegBXTijD480bCaKtzM9p hrB955i5siaclvTFQyYA5VDknmf9mXYgzgDWQ1GyUfOkSRyDQDLbT68UvSTrymZHO5mq mreby1R5+FBRFt5x5d5XvuWgRWarkkPRfsNtVq6fcRF4xbpT3C221ETB4a+RVO+WmTtv 7ugbh0c+ZTwELizUPk6bHrvNKtSHsFRcnHbO38s+OMZhNipNeSxDSu11jzmUzLN8QKJU Ty3g== X-Gm-Message-State: AIVw113F+sl3kAfPDDD3m1e6e8tuY98UkLutsGnk9G58yGiNurbdXsoZ RY4fr+h+bIXS+TBh X-Received: by 10.36.39.137 with SMTP id g131mr7390214ita.89.1499640991903; Sun, 09 Jul 2017 15:56:31 -0700 (PDT) Original-Received: from lylat (S010664777d9cebe3.ss.shawcable.net. [70.64.85.59]) by smtp.gmail.com with ESMTPSA id b24sm2533318itd.21.2017.07.09.15.56.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jul 2017 15:56:30 -0700 (PDT) In-Reply-To: <83lgnxk7v6.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 09 Jul 2017 17:22:37 +0300") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.214.66 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:216380 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Alex >> Cc: emacs-devel@gnu.org >> Date: Sat, 08 Jul 2017 16:38:44 -0600 >> >> Why did you choose the name line-number-display-width over, e.g., >> display-line-number-width? It seems every other related variable has a >> prefix of display-. > > Not every other one: the faces start with line-number. > > Is the name that bad? It sounded right at the time, but if others > think it might confuse, we could rename it. I think it's a little confusing, but it's not a huge deal. >> P.S. I was thinking about how a minor mode for this should be >> implemented. I attached a proof of concept, which includes a couple >> extra variables to achieve line number width behaviour similar to >> linum/nlinum. What do you think? > > Looks okay, although I'd drop the # part in the below: > > (add-hook 'pre-command-hook #'display-line-numbers-update-width nil t)) Is there a reason to drop it? I heard that the byte compiler uses #' to check for existence of the function (and warns if it's not found), so it seems like a nice default in these situations. I've attached a patch below. I changed the menu bar to toggle the global mode since the other toggles in the Show/Hide menu are also toggled globally. Does it look alright for inclusion? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-minor-mode-interface-for-display-line-numbers.patch Content-Description: minor mode >From 283ac10f3601362c0b200f0b610047bec75d0a59 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/display-line-numbers.el | 99 ++++++++++++++++++++++++++++++++++++++++++++ lisp/menu-bar.el | 14 ++----- 2 files changed, 102 insertions(+), 11 deletions(-) create mode 100644 lisp/display-line-numbers.el diff --git a/lisp/display-line-numbers.el b/lisp/display-line-numbers.el new file mode 100644 index 0000000000..ebc3494f73 --- /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. + +;;; Code: + +(defgroup display-line-numbers nil + "Display line numbers in the buffer." + :group 'display) + +(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 "Regular line numbers" t)) + :version "26.1") + +(defcustom display-line-number-inhibit-shrink 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, set initial line number width based on buffer contents. +`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." + (setq display-line-number-width + (max (or display-line-number-width 1) + (line-number-display-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-number-inhibit-shrink + (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.11.0 --=-=-=--