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: Mon, 28 Aug 2017 11:50:40 -0700 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1503946818 19965 195.159.176.226 (28 Aug 2017 19:00:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 28 Aug 2017 19:00:18 +0000 (UTC) Cc: 28246@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 28 21:00:09 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 1dmPGa-0004n5-Sq for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Aug 2017 21:00:09 +0200 Original-Received: from localhost ([::1]:41123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmPGh-0000OV-Rz for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 Aug 2017 15:00:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dmPGb-0000La-Hc for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2017 15:00:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dmPGV-0006yD-E1 for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2017 15:00:09 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50994) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dmPGV-0006xb-AN for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2017 15:00:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dmPGV-0007ev-0e for bug-gnu-emacs@gnu.org; Mon, 28 Aug 2017 15:00:03 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Aug 2017 19:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28246 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 28246-submit@debbugs.gnu.org id=B28246.150394676229351 (code B ref 28246); Mon, 28 Aug 2017 19:00:02 +0000 Original-Received: (at 28246) by debbugs.gnu.org; 28 Aug 2017 18:59:22 +0000 Original-Received: from localhost ([127.0.0.1]:59675 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmPFq-0007dL-13 for submit@debbugs.gnu.org; Mon, 28 Aug 2017 14:59:22 -0400 Original-Received: from gateway34.websitewelcome.com ([192.185.148.204]:22080) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dmPFp-0007dD-0P for 28246@debbugs.gnu.org; Mon, 28 Aug 2017 14:59:21 -0400 Original-Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway34.websitewelcome.com (Postfix) with ESMTP id CF70D5341DB for <28246@debbugs.gnu.org>; Mon, 28 Aug 2017 13:50:41 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id mP6Td9zCb7GnJmP6Tdojyh; Mon, 28 Aug 2017 13:49:41 -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:Cc:To:From:Message-ID:Date: Sender:Reply-To: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=uOrXNWq1Ahw4LFTedD620nIw+06VOaK9S1CPbXf7XFs=; b=V1mpbOCjojWkULnZnHaIiuhrdE dFJ9EKt7n1SQ/GKPMW3cTSVEnPRmnbIqNWqYxgeuHrl+0CiwdVoL0pK+ks9N8xeui2FyBWOtilNyz Gbu6uIoY9C0QShw9YDCKuL2z4BStR6jmx3BUprXAcSeWxg+Yx8MgVd39AezmMTf0XTKjAoEAq7+WO m7NDFNNPNxWZCFoYsUErAM/q/rAgEkldgsRr6vGRvb3u8WH3Qx95oQUIAgQwfSRkGyeKQZir0DQsQ bBwa+zN8gK5tUYU7tNZ2mlxSPQNq27Q54eopbOEhXcr/q2BXWAZMo3anSxxdjJkVof49dwExaVVmJ +UTywOuA==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:51538 helo=server.private) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.87) (envelope-from ) id 1dmP7R-002DAg-2C; Mon, 28 Aug 2017 13:50:41 -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 - debbugs.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: 1dmP7R-002DAg-2C 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]:51538 X-Source-Auth: lawlist X-Email-Count: 2 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes 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:136305 Archived-At: Thank you, Eli, for having taken the time to explain the fundamentals of how Emacs calculates the width for display of native line numbers. I have been using the point-max approach (each command loop) in my own setup since I first started using Emacs a few years ago (with a variation of linum.el for just the visible window), and I became accustomed to seeing the width decrease/increase accordingly. I instantly noticed the difference with native line numbers, and my OCDC went into action looking for a fix. :) I created a Qprecision symbol to be used with Vdisplay_line_numbers_width, and I can turn the precision width feature on/off. The revised snippet is listed below in the event that anyone is interested in this thread in the future. Thank you again for all your help and explanations. At your convenience, please feel free to close out bug #28246. Keith /* @lawlist modification -- precision width for line numbers. */ struct window *w = decode_live_window (selected_window); Lisp_Object buf = w->contents; CHECK_BUFFER (buf); struct buffer *b = XBUFFER (buf); if (!it->lnum_width && EQ (Vdisplay_line_numbers_width, Qprecision) && !EQ (Vdisplay_line_numbers, Qrelative) && !EQ (Vdisplay_line_numbers, Qvisual) && !MINI_WINDOW_P (XWINDOW (selected_window)) && BUF_BEG (b) <= ZV && ZV <= BUF_Z (b)) { /* Length of an Integer: https://stackoverflow.com/a/3068420/2112489 The log10, abs, and floor functions are provided by math.h */ it->lnum_width = floor (log10 (abs (internal_line_number_at_position (w, ZV)))) + 1; eassert (it->lnum_width > 0); } /* Compute the required width if needed. */ else if (!it->lnum_width) { if (NATNUMP (Vdisplay_line_numbers_width)) it->lnum_width = XFASTINT (Vdisplay_line_numbers_width); /* Max line number to be displayed cannot be more than the one corresponding to the last row of the desired matrix. */ ptrdiff_t max_lnum; if (NILP (Vdisplay_line_numbers_current_absolute) && (EQ (Vdisplay_line_numbers, Qrelative) || EQ (Vdisplay_line_numbers, Qvisual))) /* We subtract one more because the current line is always zero in this mode. */ max_lnum = it->w->desired_matrix->nrows - 2; else if (EQ (Vdisplay_line_numbers, Qvisual)) max_lnum = it->pt_lnum + it->w->desired_matrix->nrows - 1; else max_lnum = this_line + it->w->desired_matrix->nrows - 1 - it->vpos; max_lnum = max (1, max_lnum); it->lnum_width = max (it->lnum_width, log10 (max_lnum) + 1); eassert (it->lnum_width > 0); }