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 display of line numbers, improved Date: Mon, 26 Jun 2017 13:36:40 -0600 Message-ID: <871sq65ynr.fsf@lylat> References: <83tw35thxw.fsf@gnu.org> <87efu7lsj0.fsf@lylat> <83r2y7sc9q.fsf@gnu.org> <87a84vl8gm.fsf@lylat> <83podqsst5.fsf@gnu.org> <83efu6spyk.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1498505820 26740 195.159.176.226 (26 Jun 2017 19:37:00 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 26 Jun 2017 19:37:00 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: Stefan Monnier , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 26 21:36:52 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 1dPZoa-0006aT-Ef for ged-emacs-devel@m.gmane.org; Mon, 26 Jun 2017 21:36:52 +0200 Original-Received: from localhost ([::1]:48228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPZof-0007uS-Hn for ged-emacs-devel@m.gmane.org; Mon, 26 Jun 2017 15:36:57 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPZoY-0007uL-VJ for emacs-devel@gnu.org; Mon, 26 Jun 2017 15:36:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPZoV-0007AD-Ou for emacs-devel@gnu.org; Mon, 26 Jun 2017 15:36:51 -0400 Original-Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]:36029) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPZoV-0007A5-JN; Mon, 26 Jun 2017 15:36:47 -0400 Original-Received: by mail-it0-x241.google.com with SMTP id 185so988243itv.3; Mon, 26 Jun 2017 12:36:47 -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=VgxSo7FfOM/MaIF+aYmZ89s7CiAYqNaWjFdnxPKAj5A=; b=OzzTEeQckWclZZwKLu7js/y9uH9JbOGNRnyTWQr7fq8goWj2m955whwZD5Y7GNxdsb 4tFWoUge4WA7NCx3NQEKZ2ZGwx/Bt4JJXqfIeh64tCT1YuoAWJuF/UtNwnNZ6t85lZYU vAQ+OGXOwiNrdiba9dUSjxFLBYfgeGUPM7OuNs4PkrzO1Ab1sw+EctiTpu6JDAjswUnO O9cwkBcrObH4oWeSXTKym+g02ab9chCGljQLdZ4VYMDwkir8nTDrs5AHlIFgFRLOAx4v l9UKExxofWtA2OKbznkJI81effPaBqoaDgdN8n8Txj/6P3BmrT+6V7Xa21UJ3QpgTsQs PvpA== 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=VgxSo7FfOM/MaIF+aYmZ89s7CiAYqNaWjFdnxPKAj5A=; b=TgyWOqA0Ko8bHu77FyfSwK17fuSt6YfSROdVHtsSwvOYoa5K1yOL25kzrJNugN99hE KXacZGX0p4INdWxVkEjveBbqv/pouvbfNRrCDWp7+vJ+R3VSp5qf/psRXiW35KYD8Sbl 8lPFBD3quEkyAc1mbotW+vDVyuFsxclEjWL9kH48P1o/803ModnD9YIXuq69PzCQouo8 vSiB7JCOx5QTn0KhWU/irov7SD+7wQzFtW2AXiC3uTB6S/nJpBX6uVdrCnr139M03vXD xrrY3Vi2JHbt0+3JVs8GTYFUoRQ0cVqqXrk9wWrSFKkcuFo5MGquBdRtZ+N4OQR+wadg SGjg== X-Gm-Message-State: AKS2vOwEyF6yEoyFVE5f514OiwIJmyD2IgXhn9ZOAxyFtAEls20sh85m gzNsjIWrZpJZjJ7I X-Received: by 10.36.66.208 with SMTP id i199mr1689186itb.99.1498505806379; Mon, 26 Jun 2017 12:36:46 -0700 (PDT) Original-Received: from lylat (S010664777d9cebe3.ss.shawcable.net. [70.64.85.59]) by smtp.gmail.com with ESMTPSA id i73sm486351ioi.30.2017.06.26.12.36.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2017 12:36:44 -0700 (PDT) In-Reply-To: <83efu6spyk.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 26 Jun 2017 18:56:03 +0300") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::241 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:216010 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Stefan Monnier >> Date: Mon, 26 Jun 2017 11:28:23 -0400 >> >> I don't understand your comment: Alex is referring here to the approach >> used in nlinum, which I chose specifically to avoid having to scan the >> whole buffer. > > I alluded to this: > >> that can >> be worked around by setting 'display-line-number-width' to a >> sufficiently large number, but I would like it to be no larger than what >> it needs to be for the current text in the buffer. > > I provided 'display-line-number-width' to cater to the desire of not > shrinking the width too much, and it seemed to me that if someone's > ideal is not to change the width at all, as Alex said up-thread, > counting the lines at the beginning will do that for him. Counting at the beginning helps a lot, but it doesn't help for when the buffer grows over an editing session. >> Basically, start with a small value of display-line-number-width, and if >> during display we find that this value is too small to fit the largest >> displayed line-number, we increase it. > > I wanted to avoid using a buffer-local variable settable by the > display engine. (I cannot easily use display-line-number-width, > because that's a user-settable option; I need another variable.) What's the difference between the display engine setting a buffer-local variable and Lisp libraries doing so? I've included a diff that accomplishes what I want. Is there something fundamentally wrong it? PS: There's a bug with tab stops when display-line-number-width is a small positive number. Look at around L20814 in xdisp.c with a display-line-number-width being nil, 1, 2, and 3. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=line-numbers-grow-only.diff diff --git a/src/xdisp.c b/src/xdisp.c index aa75fcaf77..442b09b10b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -20810,8 +20810,21 @@ maybe_produce_line_number (struct it *it) /* Compute the required width if needed. */ if (!it->lnum_width) { - if (NATNUMP (Vdisplay_line_number_width)) - it->lnum_width = XFASTINT (Vdisplay_line_number_width); + if (display_line_numbers_grow_only && NATNUMP (Vdisplay_line_number_width)) + { + int min_lnum = XFASTINT (Vdisplay_line_number_width); + ptrdiff_t max_lnum; + + max_lnum = this_line + it->w->desired_matrix->nrows - 1 - it->vpos; + min_lnum = max (log10 (max_lnum) + 1, min_lnum); + + it->lnum_width = min_lnum; + Vdisplay_line_number_width = make_number (min_lnum); + } + else if (NATNUMP (Vdisplay_line_number_width)) + { + it->lnum_width = XFASTINT (Vdisplay_line_number_width); + } else { /* Max line number to be displayed cannot be more than @@ -32495,6 +32508,14 @@ even if the actual number needs less space. The default value of nil means compute the space dynamically. Any other value is treated as nil. */); Vdisplay_line_number_width = Qnil; + DEFSYM (Qdisplay_line_number_width, "display-line-number-width"); + Fmake_variable_buffer_local (Qdisplay_line_number_width); + + DEFVAR_BOOL ("display-line-numbers-grow-only", display_line_numbers_grow_only, + doc: /* Non-nil means only dynamically grow the +display, and never shrink. This variable is only taken into account +when `display-line-number-width' is a positive number.*/); + display_line_numbers_grow_only = false; DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay, doc: /* Non-nil means don't eval Lisp during redisplay. */); --=-=-=--