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, final testing Date: Sun, 02 Jul 2017 23:06:29 -0600 Message-ID: <874luuyuqy.fsf@lylat> References: <83y3s9pm2a.fsf@gnu.org> <87vandz7lw.fsf@lylat> <83wp7tpcav.fsf@gnu.org> <87r2y1z45o.fsf@lylat> <83vandp7wz.fsf@gnu.org> <87mv8pyy7f.fsf@lylat> <83shigpoxq.fsf@gnu.org> <87mv8nkh31.fsf@lylat> <83bmp3pnmb.fsf@gnu.org> <87eftzju5g.fsf@lylat> <837ezqq3gd.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1499058456 15924 195.159.176.226 (3 Jul 2017 05:07:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 3 Jul 2017 05:07:36 +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 03 07:07:32 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 1dRta6-0003j3-VY for ged-emacs-devel@m.gmane.org; Mon, 03 Jul 2017 07:07:31 +0200 Original-Received: from localhost ([::1]:60365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRta8-0007tN-Tv for ged-emacs-devel@m.gmane.org; Mon, 03 Jul 2017 01:07:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRtZW-0007tH-9G for emacs-devel@gnu.org; Mon, 03 Jul 2017 01:06:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRtZT-00064d-4O for emacs-devel@gnu.org; Mon, 03 Jul 2017 01:06:54 -0400 Original-Received: from mail-it0-x231.google.com ([2607:f8b0:4001:c0b::231]:38017) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dRtZS-0005zw-Sm; Mon, 03 Jul 2017 01:06:51 -0400 Original-Received: by mail-it0-x231.google.com with SMTP id k192so50599659ith.1; Sun, 02 Jul 2017 22:06:48 -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=WbXHgAs2B0lxoVTWvXR/pc7u4FrLvzw4P3KDkiwlXh0=; b=aQf2ITnGr09kmSiVc7gOXp+LWt5HRz3FM+CXh+ICWM3OX36tEpTu9ffXchflZTontY WanEBrz03K4IZYdwtUc6URkiK4L0xl/bkPvZcGCff2AQiHoJBGERrrvtD4vaqxyLsNjK 3wPY5nCwhs0/Ezo5EZkcqPhq3IlK18YGz/9wimOo+ZkGz2oQua6xvkFuLkyZWx8TirGG 8/r7XItgE1qiwKsQ2gnqcmZgwWiZxzDoDAiXSRdMlRFy7QuqYZ4sae/VMyzx5u/kBMvg +nZWBtGa9Csjccrv4QiTE6wwFRKlSasDidesTqmdHmHmTvCznbQJsLf5LJYtLuFVenWC o2hA== 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=WbXHgAs2B0lxoVTWvXR/pc7u4FrLvzw4P3KDkiwlXh0=; b=NdMZR+r3FH3d1Zok5uzR+62Alz8EyFUfis4kWcTDaTtlfhZMzQOUcI+obD7w+9s1ZH dHjQu66lka6peiUH9U8fgQO3ibB2Dld9U+tXzzFZXfbo5N1SKuMj8WOPFLM9amV19btY VwBSQZAhQd+kC5UT5qtfs6ZY5WAFY6d88CDAsU8uNJZ03WO/VuGqYDN+WQ/2TqM1eraS LlS3CkKx2AJMF4zjODenXrrb/mSqeO5hFS9MbRKIVUxG0MKPDAoffIRa7lIblhDJJUyb aesEK9C+j+2SGeRmK5TYi2/lwWLIWObzCg7CAODKrd+CmYYTnpeGFeuO8EqLWMPMsRF3 htMw== X-Gm-Message-State: AIVw110RgCgEXBwM7bvOjgAEkKPXhZl39WOYVoJYVvOisTnF/a68HwlD YCNzFDBt17FG0Oe7 X-Received: by 10.36.211.130 with SMTP id n124mr7081006itg.107.1499058407868; Sun, 02 Jul 2017 22:06:47 -0700 (PDT) Original-Received: from lylat (S010664777d9cebe3.ss.shawcable.net. [70.64.85.59]) by smtp.gmail.com with ESMTPSA id f19sm7846908ioe.58.2017.07.02.22.06.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 02 Jul 2017 22:06:46 -0700 (PDT) In-Reply-To: <837ezqq3gd.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 02 Jul 2017 18:10:58 +0300") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::231 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:216128 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Alex >> Cc: emacs-devel@gnu.org >> Date: Sat, 01 Jul 2017 23:16:11 -0600 >> > I couldn't (yet) find a way of doing that. >> >> That's unfortunate; hopefully this can be fixed. > > I think I fixed that now. The issue is a bit harder to encounter now, but it appears to still be present. In xdisp.c: M-g c 2970 RET C-u 16 C-n Then hit C-n a few times to reach line 87. The cursor will now be on column 26 instead of column 27. You can also test this by holding C-n or C-p and noticing the goal column changing. This also affects C-v and M-v with scroll-preserve-screen-position set to 'always. >> > I firmly believe that line numbers should not be displayed on the >> > margins, because that produces problems for packages that want to >> > display stuff there. >> >> That seems to me to be an extensibility problem rather than line numbers >> not belonging in the margins. Without fixing that problem, then there >> will still be problems when multiple packages attempt to use the margins >> simultaneously. > > That's correct, but since coexistence in the margin is problematic, > core features, especially popular ones, should not use the margins, so > as not to exacerbate the problems. > > And note that displaying the numbers in the margin would not have > solved the issue, since the width of the margins would still be > estimated by the same heuristics. So there's no reliable way to get the x-coordinate of the end of the left margin/fringe? Why don't these issues affect nlinum, since it sets the width dynamically? >> That way, line numbers can have its own special area, and there will >> be a clear x-coordinate for vertical-motion to start from, avoiding >> a whole class of errors that you've had to deal with so far. > > See above: these problems won't be solved by going to the margin. The > only way to solve them is to have a fixed width for line numbers, > something that can be done, if desired, by suitable setting of > display-line-number-width. That will definitely alleviate the issues, but won't completely solve them on its own (plus, one shouldn't have to set that to avoid them). On this note, I'd like to again ask for dynamic growing of the width, but not shrinking. That should also help towards avoiding this problem in growing buffers. I've edited and attached my previous proof of concept, but it uses Fmake_local_variable, which doesn't look like it's used a lot in the C side of Emacs. Is there a better way to make buffer local internal variables? --=-=-= 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 47b8141463..14f070d487 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -20872,7 +20872,12 @@ maybe_produce_line_number (struct it *it) /* Compute the required width if needed. */ if (!it->lnum_width) { - if (NATNUMP (Vdisplay_line_number_width)) + Lisp_Object cache = buffer_local_value (Qdisplay_line_number_width_cache, + it->w->contents); + + if (NATNUMP (cache)) + it->lnum_width = XFASTINT (cache); + else if (NATNUMP (Vdisplay_line_number_width)) it->lnum_width = XFASTINT (Vdisplay_line_number_width); /* Max line number to be displayed cannot be more than the one @@ -20891,6 +20896,9 @@ maybe_produce_line_number (struct it *it) 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); + if (display_line_numbers_grow_only) + Fset (Fmake_local_variable (Qdisplay_line_number_width_cache), + make_number (it->lnum_width)); eassert (it->lnum_width > 0); } if (EQ (Vdisplay_line_numbers, Qrelative)) @@ -32594,6 +32602,18 @@ Any other value is treated as nil. */); 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. */); + display_line_numbers_grow_only = false; + + DEFVAR_LISP ("display-line-number-width-cache", Vdisplay_line_number_width_cache, + doc: /* Stores the maximum line number width seen. */); + Vdisplay_line_number_width_cache = Qnil; + DEFSYM (Qdisplay_line_number_width_cache, "display-line-number-width-cache"); + Fmake_variable_buffer_local (Qdisplay_line_number_width_cache); + Funintern (Qdisplay_line_number_width_cache, Qnil); + DEFVAR_LISP ("display-line-numbers-current-absolute", Vdisplay_line_numbers_current_absolute, doc: /* Non-nil means display absolute number of current line. --=-=-=--