unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Gregory Heytings <gregory@heytings.org>
Cc: 56393@debbugs.gnu.org
Subject: bug#56393: Actually fix the long lines display bug
Date: Tue, 05 Jul 2022 15:54:59 +0300	[thread overview]
Message-ID: <83a69n90t8.fsf@gnu.org> (raw)
In-Reply-To: <38c1a31040f5546dbd3a@heytings.org> (message from Gregory Heytings on Tue, 05 Jul 2022 10:17:37 +0000)

> Date: Tue, 05 Jul 2022 10:17:37 +0000
> From: Gregory Heytings <gregory@heytings.org>
> 
> Gosh!  After including too little, I included too much.  The attached one 
> is correct (I hope).

Thanks!  It's a good idea, but I wonder how far we can safely take it;
see below.

> diff --git a/doc/emacs/trouble.texi b/doc/emacs/trouble.texi
> index f06b93759d..887e5c6170 100644
> --- a/doc/emacs/trouble.texi
> +++ b/doc/emacs/trouble.texi
> @@ -158,7 +158,6 @@ Lossage
>  * Crashing::              What Emacs does when it crashes.
>  * After a Crash::         Recovering editing in an Emacs session that crashed.
>  * Emergency Escape::      What to do if Emacs stops responding.
> -* Long Lines::            Mitigating slowness due to extremely long lines.
>  * DEL Does Not Delete::   What to do if @key{DEL} doesn't delete.
>  @end menu
>  
> @@ -433,64 +432,6 @@ Emergency Escape
>  emergency escape---but there are cases where it won't work, when a
>  system call hangs or when Emacs is stuck in a tight loop in C code.
>  
> -@node Long Lines
> -@subsection Long Lines
> -@cindex long lines

This removal is premature, IMO.  We should first establish that this
feature can indeed cope well enough with the important use cases, and
I'm not sure we are there yet.  It is possible that this feature will
be one of several available features that attempt to solve the same
problem in different ways, each way with its own advantages and
disadvantages.

> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -324,9 +324,6 @@ startup.  Previously, these functions ignored
>  \f
>  * Changes in Emacs 29.1
>  
> ----
> -** 'longlines-mode' is no longer obsolete.
> -

Likewise here.

> +** Emacs is now capable of editing files with arbitarily long lines.

I'd suggest saying something like

  Emacs now copes better with editing files with extremely long lines.

> +(defcustom auto-narrow-display-length 30000
> +  "Number of characters to which display is restricted in `auto-narrow-mode'."

This should tell how the narrowed region is positioned relative to
point, I think, because without it the doc string tells too little.

> +(defcustom auto-narrow-widen-automatically
> +  '( move-beginning-of-line move-end-of-line backward-sentence forward-sentence
> +     backward-sexp forward-sexp beginning-of-defun end-of-defun
> +     beginning-of-buffer end-of-buffer goto-char goto-line
> +     mark-sexp mark-defun mark-paragraph mark-whole-buffer mark-page
> +     exchange-point-and-mark pop-global-mark set-mark-command jump-to-register
> +     bookmark-jump)
> +  "Commands for which display is automatically widened in `auto-narrow-mode'."

What are the criteria for this default?  (I'm surprised the list is so
short, for the reasons I explain below.)

> +(setq auto-narrow-long-line-threshold 30000
> +      auto-narrow-pre-command-function #'auto-narrow-pre-command-function
> +      auto-narrow-post-command-function #'auto-narrow-post-command-function)

We might eventually decide to have this turned off by default.

> --- a/src/fileio.c
> +++ b/src/fileio.c
> @@ -4997,6 +4997,20 @@ because (1) it preserves some marker positions (in unchanged portions
>  	   Otherwise start with an empty undo_list.  */
>  	bset_undo_list (current_buffer, EQ (old_undo, Qt) ? Qt : Qnil);
>  
> +      if (!noninteractive && !NILP (Vauto_narrow_long_line_threshold))
> +	{
> +	  ptrdiff_t cur, next, found, max = 0;
> +	  for (cur = PT; cur < PT + inserted; cur = next)
> +	    {
> +	      next = find_newline1 (cur, CHAR_TO_BYTE (cur), 0, -1, 1,
> +				    &found, NULL, true);
> +	      if (next - cur > max) max = next - cur;
> +	      if (!found) break;
> +	    }
> +	  if (max > XFIXNUM (Vauto_narrow_long_line_threshold))
> +	    safe_call (1, Qauto_narrow_mode);
> +	}
> +

This will invoke auto-narrow-mode for any file that is for some reason
inserted by Emacs into some buffer.  Many Emacs commands insert files
into temporary buffers or buffers that are never meant for display,
and AFAIU the above will narrow such a buffer if a file inserted
happens to have long lines, is that correct?  If so, a Lisp program
that inserts such a file, and then processes it, might fail to do its
job because it will bump into the auto-narrowed restriction.  I think
this is a symptom of a larger problem with this approach; more about
it below.

> +  DEFVAR_LISP ("auto-narrow-long-line-threshold",
> +	       Vauto_narrow_long_line_threshold,
> +	       doc: /* Line length above which `auto-narrow-mode' is entered.
> +When non-nil, and when a file with one or more lines longer than
> +`auto-narrow-long-line-threshold' is opened or inserted in a buffer,
> +`auto-narrow-mode' is automatically enabled.
> +When nil, `auto-narrow-mode' is not entered automatically.  */);
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  "When nil, `auto-narrow-mode' is disabled."

> --- a/src/keyboard.c
> +++ b/src/keyboard.c
> @@ -1290,6 +1290,9 @@ command_loop_1 (void)
>  
>    if (NILP (Vmemory_full))
>      {
> +      if (!NILP (Vauto_narrow_post_command_function) && !NILP (Vrun_hooks))
> +	safe_run_hooks (Qauto_narrow_post_command_function);
> +
>        /* Make sure this hook runs after commands that get errors and
>  	 throw to top level.  */
> [...]
> @@ -1522,6 +1527,8 @@ command_loop_1 (void)
>            }
>        kset_last_prefix_arg (current_kboard, Vcurrent_prefix_arg);
>  
> +      safe_run_hooks (Qauto_narrow_post_command_function);
> +
>        safe_run_hooks (Qpost_command_hook);

AFAIU, this means post-command-hook functions will run with the
current buffer narrowed, right?  That could cause them to fail, if
they for some reason want to access the buffer portions outside the
restriction.

> @@ -1472,6 +1475,8 @@ command_loop_1 (void)
>        Vreal_this_command = cmd;
>        safe_run_hooks (Qpre_command_hook);
>  
> +      safe_run_hooks (Qauto_narrow_pre_command_function);
> +

And here's a similar problem with pre-command-hook functions.

A similar problem will happen with any Lisp that is run from the
redisplay code: it will only see the narrowed region.

I don't quite see clearly what these general issues could mean, but
they are at least worrisome, I think, because they could potentially
mean significant breakage in many places.  The simple measure of
having a list of commands that automatically widen the buffer is
insufficient, I'm afraid, because the real problem is not on the
command level, it is on the level of Lisp programs which say
save-excursion and then go far away for whatever purposes.  Also for
commands written by users: for example, if someone writes a command
that is a trivial wrapper around goto-line, that command will no
longer automatically widen as goto-line does, right?

Can we come up with a better solution for these potential problems?
Alternatively, maybe you will explain that I'm bothered by a
non-existent problem?

Other observations:

Since the narrowing is basically in effect only during redisplay, it
doesn't help with commands that use display code outside of redisplay
proper.  For example, C-n, C-v, C-l, and other commands are still
extremely sluggish in files with long lines.  E.g., try the file
long-line.xml mentioned here:

  https://debbugs.gnu.org/cgi/bugreport.cgi?bug=45898#80

Or try dragging the mode line of a window showing that file.

Also, the automatic restriction is very visible and causes surprising
effects: (point-min) and (point-max) evaluate to the narrowed region
(so it's basically very hard to know the real size of the buffer), and
scrolling through the buffer causes the scroll-bar thumb move in a
non-monotonic manner: I scroll towards the end of the buffer, but the
thumb sometimes jumps back up, as if I moved towards the beginning.

And sometimes I see that C-n moves point horizontally, i.e. point
stays on the same screen line, instead of the expected vertical
movement.  I guess this is because the restriction violates some
assumptions that Emacs makes regarding horizontal coordinates of some
reference position.

I think at this point it is best to have this feature on a feature
branch, so that people could try it, and so that improving it won't
need to post the entire patch each time anew.

Thanks.





  parent reply	other threads:[~2022-07-05 12:54 UTC|newest]

Thread overview: 205+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05  8:49 bug#56393: Actually fix the long lines display bug Gregory Heytings
2022-07-05  9:28 ` Gregory Heytings
2022-07-05  9:58   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-05 10:17     ` Gregory Heytings
2022-07-05 11:24       ` Lars Ingebrigtsen
2022-07-05 12:16         ` Gregory Heytings
2022-07-05 12:59           ` Gerd Möllmann
2022-07-07 11:29             ` Gerd Möllmann
2022-07-07 13:36               ` Eli Zaretskii
2022-07-07 14:10                 ` Eli Zaretskii
2022-07-08  5:49                   ` Gerd Möllmann
2022-07-08  6:55                     ` Eli Zaretskii
2022-07-08  7:01                       ` Gerd Möllmann
2022-07-08 21:41                       ` Gregory Heytings
2022-07-09  7:03                         ` Eli Zaretskii
2022-07-09  8:56                           ` Gregory Heytings
2022-07-09  9:20                             ` Eli Zaretskii
2022-07-09  9:23                               ` Eli Zaretskii
2022-07-09  9:32                                 ` Gregory Heytings
2022-07-09  9:30                               ` Eli Zaretskii
2022-07-09  9:49                               ` Gregory Heytings
2022-07-09 10:01                                 ` Eli Zaretskii
2022-07-09 10:50                                   ` Gregory Heytings
2022-07-09 11:16                                     ` Eli Zaretskii
2022-07-09 11:48                                       ` Gregory Heytings
2022-07-09 11:59                                         ` Eli Zaretskii
2022-07-09 12:07                                           ` Gregory Heytings
2022-07-09 12:34                                             ` Eli Zaretskii
2022-07-09 12:36                                               ` Gregory Heytings
2022-07-09 12:09                                           ` Ihor Radchenko
2022-07-09 12:37                                             ` Eli Zaretskii
2022-07-09 10:54                             ` Eli Zaretskii
2022-07-09 11:09                               ` Eli Zaretskii
2022-07-09 11:12                               ` Gregory Heytings
2022-07-09 11:20                                 ` Gregory Heytings
2022-07-09 12:29                                   ` Lars Ingebrigtsen
2022-07-09 12:38                                     ` Gregory Heytings
2022-07-16 19:39                                       ` Gregory Heytings
2022-07-17 15:21                                         ` Eli Zaretskii
2022-07-17 15:37                                           ` Gregory Heytings
2022-07-17 16:00                                             ` Eli Zaretskii
2022-07-18 10:19                                               ` Gregory Heytings
2022-07-18 12:20                                                 ` Eli Zaretskii
2022-07-18 12:58                                                   ` Gregory Heytings
2022-07-18 13:33                                                     ` Eli Zaretskii
2022-07-18 14:00                                                       ` Gregory Heytings
2022-07-18 14:10                                                         ` Gregory Heytings
2022-07-18 14:22                                                           ` Eli Zaretskii
2022-07-18 14:34                                                             ` Gregory Heytings
2022-07-18 16:06                                                             ` Gregory Heytings
2022-07-18 16:21                                                               ` Gregory Heytings
2022-07-18 17:04                                                                 ` Eli Zaretskii
2022-07-18 17:07                                                                   ` Gregory Heytings
2022-07-18 17:09                                                                     ` Eli Zaretskii
2022-07-18 18:33                                                                       ` Gregory Heytings
2022-07-18 16:48                                                               ` Eli Zaretskii
2022-07-18 17:11                                                                 ` Gregory Heytings
2022-07-18 17:19                                                                   ` Eli Zaretskii
2022-07-18 18:17                                                                     ` Gregory Heytings
2022-07-18 18:26                                                                   ` Gregory Heytings
2022-07-18 18:56                                                                     ` Eli Zaretskii
2022-07-18 20:14                                                                       ` Gregory Heytings
2022-07-19  2:34                                                                         ` Eli Zaretskii
2022-07-19  5:39                                                                           ` Gregory Heytings
2022-07-19 12:00                                                                             ` Eli Zaretskii
2022-07-19 12:07                                                                               ` Gerd Möllmann
2022-07-19 12:49                                                                               ` Gregory Heytings
2022-07-19 13:16                                                                                 ` Eli Zaretskii
2022-07-19 13:42                                                                                   ` Gregory Heytings
2022-07-19 13:56                                                                                     ` Eli Zaretskii
2022-07-19 14:06                                                                                       ` Gregory Heytings
2022-07-19 14:15                                                                                         ` Lars Ingebrigtsen
2022-07-19 14:24                                                                                           ` Gregory Heytings
     [not found]                                                                                           ` <364167b2-83e-c5af-1981-221d53e33ce6@heytings.org>
2022-07-19 21:55                                                                                             ` Gregory Heytings
2022-07-19 14:19                                                                                         ` Eli Zaretskii
2022-07-19 14:33                                                                                           ` Gregory Heytings
2022-07-19 16:14                                                                                             ` Eli Zaretskii
2022-07-19 21:40                                                                                               ` Gregory Heytings
2022-07-20 12:07                                                                                                 ` Eli Zaretskii
2022-07-20 13:06                                                                                                   ` Gregory Heytings
2022-07-20 13:23                                                                                                     ` Eli Zaretskii
2022-07-20 13:42                                                                                                       ` Gregory Heytings
2022-07-20 15:54                                                                                                         ` Eli Zaretskii
2022-07-20 17:33                                                                                                           ` Gregory Heytings
2022-07-21  6:32                                                                                                             ` Eli Zaretskii
2022-07-21  7:39                                                                                                               ` Gregory Heytings
2022-07-21  7:49                                                                                                                 ` Gregory Heytings
2022-07-21  8:00                                                                                                                   ` Eli Zaretskii
2022-07-21  7:56                                                                                                                 ` Eli Zaretskii
2022-07-21  8:20                                                                                                                   ` Gregory Heytings
2022-07-21  8:58                                                                                                                     ` Eli Zaretskii
2022-07-21  9:00                                                                                                                       ` Gregory Heytings
2022-07-21  9:18                                                                                                                         ` Lars Ingebrigtsen
2022-07-21 11:56                                                                                                                           ` Gregory Heytings
2022-07-21 12:22                                                                                                                             ` Eli Zaretskii
     [not found]                                                                               ` <bce7aad8-6872-97ec-77ac-6a593ff66a27@heytings.org>
2022-07-19 12:57                                                                                 ` Gregory Heytings
2022-07-21  9:42                                                                       ` Eli Zaretskii
2022-07-08  5:47                 ` Gerd Möllmann
2022-07-08  5:56                   ` Eli Zaretskii
2022-07-08  6:25                     ` Gerd Möllmann
2022-07-08  7:19                       ` Eli Zaretskii
2022-07-07 18:38               ` Gregory Heytings
2022-07-08  5:59                 ` Gerd Möllmann
2022-07-05 12:54       ` Eli Zaretskii [this message]
2022-07-05 13:53         ` Gregory Heytings
2022-07-05 14:14           ` Eli Zaretskii
2022-07-05 14:30             ` Gregory Heytings
2022-07-05 15:21               ` Robert Pluim
2022-07-05 15:46               ` Eli Zaretskii
2022-07-05 16:21                 ` Gregory Heytings
2022-07-05 16:34                   ` Eli Zaretskii
2022-07-05 23:09                     ` Lars Ingebrigtsen
2022-07-05 23:12                       ` Gregory Heytings
2022-07-06 12:29                         ` Eli Zaretskii
2022-07-06 13:01                           ` Gregory Heytings
2022-07-06 13:25                             ` Eli Zaretskii
2022-07-06 13:56                               ` Gregory Heytings
2022-07-06 14:09                                 ` Eli Zaretskii
2022-07-06 14:41                                   ` Gregory Heytings
2022-07-06 16:19                                     ` Eli Zaretskii
2022-07-06 16:57                                       ` Gregory Heytings
2022-07-06 17:50                                         ` Eli Zaretskii
2022-07-07  0:28                                           ` Ihor Radchenko
2022-07-07  5:43                                             ` Eli Zaretskii
2022-07-07  0:38                                           ` Gregory Heytings
2022-07-07  5:53                                             ` Eli Zaretskii
2022-07-07  8:23                                               ` Gregory Heytings
2022-07-07 10:10                                                 ` Eli Zaretskii
2022-07-07 18:08                                                   ` Gregory Heytings
2022-07-09  6:20                                                   ` Eli Zaretskii
2022-07-09  8:24                                                     ` Gregory Heytings
2022-07-09  9:13                                                       ` Eli Zaretskii
2022-07-09  9:39                                                         ` Gregory Heytings
2022-07-09  9:59                                                           ` Eli Zaretskii
2022-07-09 10:20                                                             ` Gregory Heytings
2022-07-09 10:41                                                               ` Eli Zaretskii
2022-07-09 11:09                                                                 ` Gregory Heytings
2022-07-09 11:18                                                                   ` Eli Zaretskii
2022-07-09 11:38                                                                     ` Gregory Heytings
2022-07-09 11:48                                                                       ` Eli Zaretskii
2022-07-09 12:01                                                                         ` Gregory Heytings
2022-07-09 12:24                                                                           ` Eli Zaretskii
2022-07-09 12:31                                                                             ` Gregory Heytings
2022-07-07 14:25                                             ` Drew Adams
2022-07-07 15:58                                               ` Eli Zaretskii
2022-07-07 17:50                                                 ` Eli Zaretskii
2022-07-07 18:46                                                   ` Gregory Heytings
2022-07-07 19:05                                                     ` Eli Zaretskii
2022-07-07 18:49                                               ` Gregory Heytings
2022-07-06 13:34                             ` Stefan Kangas
2022-07-06 14:10                               ` Gregory Heytings
2022-07-06 14:37                                 ` Stefan Kangas
2022-07-06 14:47                                   ` Gregory Heytings
2022-07-06 15:03                                     ` Stefan Kangas
2022-07-06 15:31                                       ` Gregory Heytings
2022-07-06 15:50                                   ` Eli Zaretskii
2022-07-05 23:10                     ` Gregory Heytings
2022-07-06  9:49                       ` Gerd Möllmann
2022-07-06 10:21                         ` Gregory Heytings
2022-07-06 11:31                       ` Lars Ingebrigtsen
2022-07-06 12:13                         ` Gregory Heytings
2022-07-06 12:44                           ` Gregory Heytings
2022-07-07  7:48                             ` Lars Ingebrigtsen
2022-07-06 12:50                         ` Eli Zaretskii
2022-07-06 13:16                         ` Phil Sainty
2022-07-06 13:45                           ` Gregory Heytings
2022-07-06 14:05                             ` Phil Sainty
2022-07-06 12:39                       ` Eli Zaretskii
2022-07-06 13:06                         ` Gregory Heytings
2022-07-06 13:32                           ` Eli Zaretskii
2022-07-06 14:05                             ` Gregory Heytings
2022-07-06 14:13                               ` Eli Zaretskii
2022-07-06 14:27                                 ` Gregory Heytings
2022-07-06 16:53                                   ` Eli Zaretskii
2022-07-06 17:17                                     ` Gregory Heytings
2022-07-06 17:30                                       ` Eli Zaretskii
2022-07-06 21:53                                         ` Gregory Heytings
2022-07-07  7:47                               ` Lars Ingebrigtsen
2022-07-18  9:44 ` bug#56393: Soon also looking at your branch Gerd Möllmann
2022-07-18 10:11   ` Michael Albinus
2022-07-18 10:26     ` Gerd Möllmann
2022-07-18 11:43       ` Michael Albinus
2022-07-18 12:15         ` Gerd Möllmann
2022-07-18 12:19           ` Michael Albinus
2022-07-18 10:49   ` Gregory Heytings
2022-07-19  8:21     ` bug#56393: Actually fix the long lines display bug Gerd Möllmann
2022-07-19  8:53       ` Gregory Heytings
2022-07-19  8:58         ` Gregory Heytings
2022-07-19  9:31           ` bug#56393: Resetting long_line_optimization_p to 0 Gerd Möllmann
2022-07-19  9:51             ` Gregory Heytings
2022-07-19 11:20               ` Gerd Möllmann
2022-07-20  6:58                 ` bug#56393: Actually fix the long lines display bug Gerd Möllmann
2022-07-20  9:13                   ` Gregory Heytings
2022-07-19 12:21           ` Eli Zaretskii
2022-07-19  9:17         ` bug#56393: Auto narrowing autside of redisplay Gerd Möllmann
2022-07-19  9:51           ` Gregory Heytings
2022-07-19 10:56             ` bug#56393: Actually fix the long lines display bug Gerd Möllmann
2022-07-19  9:25         ` bug#56393: Turn on narrowing in redisplay_window Gerd Möllmann
2022-07-19  9:52           ` Gregory Heytings
2022-07-19 11:26             ` Gerd Möllmann
2022-07-19 12:43               ` Eli Zaretskii
2022-07-20  6:30                 ` bug#56393: Actually fix the long lines display bug Gerd Möllmann
2022-07-20  9:08                   ` Gregory Heytings
2022-07-19 12:48         ` Eli Zaretskii
2022-07-20  6:32           ` Gerd Möllmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83a69n90t8.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=56393@debbugs.gnu.org \
    --cc=gregory@heytings.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).