From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#28246: display line number width != length of line number at eob Date: Sat, 26 Aug 2017 14:57:56 -0700 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1503784763 385 195.159.176.226 (26 Aug 2017 21:59:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 26 Aug 2017 21:59:23 +0000 (UTC) To: 28246@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 26 23:59:16 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1dlj6f-0007YF-S3 for geb-bug-gnu-emacs@m.gmane.org; Sat, 26 Aug 2017 23:59:06 +0200 Original-Received: from localhost ([::1]:58785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlj6l-0004wd-4h for geb-bug-gnu-emacs@m.gmane.org; Sat, 26 Aug 2017 17:59:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33894) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlj6f-0004wT-91 for bug-gnu-emacs@gnu.org; Sat, 26 Aug 2017 17:59:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlj6c-0004Oh-6A for bug-gnu-emacs@gnu.org; Sat, 26 Aug 2017 17:59:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48193) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dlj6c-0004OS-2h for bug-gnu-emacs@gnu.org; Sat, 26 Aug 2017 17:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dlj6b-00068z-QC for bug-gnu-emacs@gnu.org; Sat, 26 Aug 2017 17:59:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 26 Aug 2017 21:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 28246 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: Emacs Bug Reports Original-Received: via spool by submit@debbugs.gnu.org id=B.150378470923575 (code B ref -1); Sat, 26 Aug 2017 21:59:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Aug 2017 21:58:29 +0000 Original-Received: from localhost ([127.0.0.1]:56874 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlj64-00068B-LE for submit@debbugs.gnu.org; Sat, 26 Aug 2017 17:58:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42896) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlj62-00067x-9W for submit@debbugs.gnu.org; Sat, 26 Aug 2017 17:58:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlj5w-0004EX-0f for submit@debbugs.gnu.org; Sat, 26 Aug 2017 17:58:21 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:60400) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlj5v-0004ER-U9 for submit@debbugs.gnu.org; Sat, 26 Aug 2017 17:58:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlj5u-0004w7-Ht for bug-gnu-emacs@gnu.org; Sat, 26 Aug 2017 17:58:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlj5r-0004Du-Ea for bug-gnu-emacs@gnu.org; Sat, 26 Aug 2017 17:58:18 -0400 Original-Received: from gateway32.websitewelcome.com ([192.185.145.18]:31622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlj5r-00047g-7D for bug-gnu-emacs@gnu.org; Sat, 26 Aug 2017 17:58:15 -0400 Original-Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 5D984A0012 for ; Sat, 26 Aug 2017 16:57:58 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id lj4eduNWCdHTnlj4edGrz6; Sat, 26 Aug 2017 16:57:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:To:From:Message-ID:Date: Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=TErSTjF+1GllGhijI0xgATP+6N/I37AnXodigFaFAuo=; b=JnGz3CB+0a9AijwA8mUM4QW8ah ed/aaGvcDbxdzbRPHUo0ejOIjWd42GTjTf+axFWy4rfsykJ2VQ9qUOEjef57yHTPkj43MrdELnGAv tZmJ5Finah4tHnGbw10WJ410UaA0MDsPDqr7nO3yQD68Txhsb7UdRGhYQ1ZfdDTOGZhKlSTxzBCXu 3IcT55ia6Im7ASfYgsdu3kjgHRUQq668vwnMu819uWi7BvDF4zv23K5vWMbNP/NlXeasWPggPk2V9 /1mqlgkRpthfGIucEVSdOMNbgw8i4PgD5o8zzjkozB49Yy56/KE7j+C7KJxOrldj7TcPzGK/xp5OO CaC/w3xQ==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:52909 helo=server.private) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.87) (envelope-from ) id 1dlj5Z-002MfX-IC for bug-gnu-emacs@gnu.org; Sat, 26 Aug 2017 16:57:57 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Exim-ID: 1dlj5Z-002MfX-IC X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.private) [45.48.239.195]:52909 X-Source-Auth: lawlist X-Email-Count: 1 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:136239 Archived-At: I would like to configure native line numbers to dynamically adjust the width (smaller/larger) so that it is equal to the length of the last line in the buffer. Examples: * Buffer has 1 to 9 lines, the width should be 1 (irrespective of where point is). * Buffer has 10 to 99 lines, the width should 2 (irrespective of where point is). * Buffer has 100 to 999 lines, the width should be 3 (irrespective of where point is). Emacs is erroneously increasing the line number width before there are sufficient lines in the buffer to merit such an increase in width. Emacs fails to decrease the line number width when lines are removed from the buffer that merit a decrease in the width. The erroneous behavior can be demonstrated by evaluating the following code in a *scratch* buffer, and holding down the return key, and by holding down the backspace key. The desired behavior can be achieved with the Lisp code below AND by adding the following lines of code to maybe_produce_line_number just above the comment /* Compute the required width if needed. */ /* example modification to achieve desired behavior */ if (NATNUMP (Vdisplay_line_numbers_width) && !EQ (Vdisplay_line_numbers, Qrelative) && !EQ (Vdisplay_line_numbers, Qvisual)) it->lnum_width = XFASTINT (Vdisplay_line_numbers_width); I was unable to achieve the desired behavior by customizing Lisp variables such as display-line-numbers-grow-only and/or display-line-numbers-width-start. Here is the Lisp code that I am using: (require 'display-line-numbers) (setq display-line-numbers-grow-only nil) (setq display-line-numbers-width-start nil) (defvar display-line-numbers--update-width-var t "When non-nil, update the line number width.") (defun display-line-numbers--update-width-fn () "Update the line number width based upon the last line in the buffer. This function should be attached to the `post-command-hook'" (let ((display-width (line-number-display-width)) (desired-width (save-excursion (goto-char (point-max)) (length (format-mode-line "%l"))))) (setq display-line-numbers-width desired-width) (message "display-width (%s) | target-width (%s)" display-width desired-width))) (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 (cond (display-line-numbers-mode (cond ((null display-line-numbers--update-width-var) (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))) (display-line-numbers--update-width-var (add-hook 'post-command-hook #'display-line-numbers--update-width-fn nil 'local))) (setq display-line-numbers display-line-numbers-type)) (t (remove-hook 'pre-command-hook #'display-line-numbers-update-width 'local) (remove-hook 'post-command-hook #'display-line-numbers--update-width-fn 'local) (setq display-line-numbers nil)))) (display-line-numbers-mode t)