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, 16 Jul 2017 13:31:52 -0600 Message-ID: <871spgrxef.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> <87pod67lgi.fsf@lylat> <83fue1iur9.fsf@gnu.org> <87d190j0tz.fsf@lylat> <83h8yceal3.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1500233536 5585 195.159.176.226 (16 Jul 2017 19:32:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 16 Jul 2017 19:32:16 +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 Sun Jul 16 21:32:08 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 1dWpGw-0000uy-9j for ged-emacs-devel@m.gmane.org; Sun, 16 Jul 2017 21:32:06 +0200 Original-Received: from localhost ([::1]:46624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWpH1-0003ex-OZ for ged-emacs-devel@m.gmane.org; Sun, 16 Jul 2017 15:32:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWpGt-0003em-77 for emacs-devel@gnu.org; Sun, 16 Jul 2017 15:32:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWpGq-00067F-4w for emacs-devel@gnu.org; Sun, 16 Jul 2017 15:32:03 -0400 Original-Received: from mail-it0-x22a.google.com ([2607:f8b0:4001:c0b::22a]:34086) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dWpGp-00066z-Tv; Sun, 16 Jul 2017 15:32:00 -0400 Original-Received: by mail-it0-x22a.google.com with SMTP id v202so11543303itb.1; Sun, 16 Jul 2017 12:31:59 -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=cNoB7/LjqZ4YNZj0ThRJi8FVN7LUfnAMPH15WVAymIg=; b=ArWDKjHXZ+A8r0aXCqYO+hX1K9hXRIzxZ1z56xvZFikQ/z7j5nOptK5BHaJ5sHj02k UKRNrty+/fI1fb+J5bVbswt480/B9fQ6mpA3mtRtuLwcfFRpL3fPX2RvaWlm4R1R32gt 7fubKxqdRP+Wbo2FegLxZnIMpe3bb0cqQjq3iztPHev63jOKUqre+2UDGmOoSO6/MR+H jJ35X6QnSP6CjMZBx+ZtxoaIiJb+o3ioQU0lMjYXvzbjiugCaQ9w+3QoiRRxp2xg5RQh l0i+kDu98i53MZ6ii+YWQuLpHhPSZngfVY9wFgYXggf3KU6CPD6Cy8djVMHx1x2T/agD 7y1A== 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=cNoB7/LjqZ4YNZj0ThRJi8FVN7LUfnAMPH15WVAymIg=; b=bdIiBIv7pDkbN/DuhgN7u7XelMk7faUuj0sKSEXRjW5gfnfE7sj6iJjxDsKsXVnyho rWloKQa61pE5BniVOBmNBCPTITYNqasvJij8Kaf0alTfWuhDAimRrJTvCptyBNJl4UDF 4HkPzVKpUoQyJ1GeYH2ZI608Uh1B5JOPACQTfcY3qBjwpbuOWlaVds24NExxVydKnTEv zh3yY3nTm42lmQfD5TzheTCZR/QAcLhYeGumGQHjxTZJjBS9pNj4tVjL1EJw5mewtEFP W3cy7uOTmiS0K//EyDhHjDlLQs9WMdC1Xl2IFYRQNObkqj7MGhGMhEu25M81XjjuVFCe VJjA== X-Gm-Message-State: AIVw110ukEygKqwMZdfdI2sqX4ixADbNlovcPhfM+moBAs7uv3VFTnFX 1wiFrnLKQ5iGkvV6 X-Received: by 10.36.138.5 with SMTP id v5mr2496099itd.55.1500233518952; Sun, 16 Jul 2017 12:31:58 -0700 (PDT) Original-Received: from lylat (S010664777d9cebe3.ss.shawcable.net. [70.64.85.59]) by smtp.gmail.com with ESMTPSA id c195sm4587002ioe.42.2017.07.16.12.31.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 Jul 2017 12:31:57 -0700 (PDT) In-Reply-To: <83h8yceal3.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 16 Jul 2017 17:10:48 +0300") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::22a 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:216752 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Alex >> Cc: emacs-devel@gnu.org >> Date: Sun, 16 Jul 2017 01:30:16 -0600 >> >> It looks like I could just leave the defgroup definition in >> display-line-numbers.el and the variables in cus-start.el can still use >> it without display-line-numbers.el being preloaded. >> >> Which file would you rather have it in? > > All else being equal, I think having as much as possible in > display-line-numbers.el would be better, as it avoids scattering > related stuff across different files. I agree. Here's an updated patch that includes this as well as other improvements: --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-a-minor-mode-interface-for-display-line-numbers.patch >From d9149e30871377f90c0d5e08201b3405f3865d58 Mon Sep 17 00:00:00 2001 From: Alexander Gramiak Date: Sun, 16 Jul 2017 13:16:49 -0600 Subject: [PATCH] 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. --- lisp/cus-start.el | 8 ++-- lisp/display-line-numbers.el | 103 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 lisp/display-line-numbers.el diff --git a/lisp/cus-start.el b/lisp/cus-start.el index ed913e3268..c28b8a147f 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-numbers-width display + (display-line-numbers-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..95237250f9 --- /dev/null +++ b/lisp/display-line-numbers.el @@ -0,0 +1,103 @@ +;;; 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-numbers-type. + +;; NOTE: Customization variables for `display-line-numbers' itself are +;; defined in cus-start.el. + +;;; Code: + +(defgroup display-line-numbers nil + "Display line numbers in the buffer." + :group 'display) + +(defcustom display-line-numbers-type t + "The default type of line numbers to use in `display-line-numbers-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-numbers-width-start nil + "If non-nil, count number of lines to use for line number width. +When `display-line-numbers-mode' is turned on, +`display-line-numbers-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-numbers-width 1)) + (setq display-line-numbers-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-numbers-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-numbers-width-start + (setq display-line-numbers-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-numbers-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 -- 2.13.2 --=-=-=--