unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: darthandrus@gmail.com
Cc: 11133@debbugs.gnu.org
Subject: bug#11133: 24.0.94; Cursor gets "stuck" on an indented line with wrapped overlay
Date: Fri, 06 Apr 2012 18:48:15 +0300	[thread overview]
Message-ID: <8362dcc14w.fsf@gnu.org> (raw)
In-Reply-To: <83y5qiyso5.fsf@gnu.org>

> Date: Fri, 30 Mar 2012 19:12:10 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: 11133@debbugs.gnu.org
> 
> > From: Ivan Andrus <darthandrus@gmail.com>
> > Date: Fri, 30 Mar 2012 16:47:05 +0200
> > 
> > Put the following (including comments) in a buffer and evaluate.
> > 
> > #+begin_src emacs-lisp
> > ;; Note that the next line is indented
> >  ;; This buffer is for notes you don't want to save, and for Lisp evaluation.;; If you want to create a file, visit that file with C-x C-f,;; then enter the text in that file's own buffer.
> > 
> > ;; evaluate this
> > (let ((ov (make-overlay
> > 	   (progn (goto-char (point-min))
> > 		  (forward-line)
> > 		  (back-to-indentation)
> > 		  (point))
> > 	   (progn (end-of-line)
> > 		  (point))
> > 	   nil t nil)))
> >  (overlay-put ov 'display
> > 	       (make-string 500 ?b)))
> > 
> > #+end_src
> > 
> > Now run `previous-line' several times and it will get stuck at the
> > indentation of the bbbbb line.  If you have an extremely wide screen you
> > may need to shrink the emacs window so that the bbbb line wraps.  Also
> > note that running `previous-line' with a large prefix-argument will
> > move past the line
> 
> More accurately, "large enough" is the number of screen lines taken by
> the overlay string.  In my case, it was 7.
> 
> > This does not seem to be a problem in Emacs 22.1.1 in a terminal which
> > is the only other emacs I have easy access to.
> 
> This is a bug in visual line movement.  Visual line movement was
> introduced in Emacs 23, that's why you don't see this in Emacs 22.  In
> Emacs 23, the cursor gets stuck similarly, so this is not a regression
> wrt Emacs 23.  Disable line-move-visual with the current 24 trunk, and
> the problem will go away in Emacs 24 as well.

The problem here is that vertical-motion does not consider the case of
a display string that starts at point and takes more than one screen
line (because it's long).  The patch below plumbs that hole.

Stefan and Chong, please tell me whether to install now or wait until
after the Emacs 24.1 branch is cut.

=== modified file 'src/indent.c'
--- src/indent.c	2012-01-19 07:21:25 +0000
+++ src/indent.c	2012-04-06 15:40:43 +0000
@@ -2021,6 +2021,7 @@ whether or not it is currently displayed
       EMACS_INT it_start;
       int first_x, it_overshoot_count = 0;
       int overshoot_handled = 0;
+      int disp_string_at_start_p = 0;
 
       itdata = bidi_shelve_cache ();
       SET_TEXT_POS (pt, PT, PT_BYTE);
@@ -2035,6 +2036,8 @@ whether or not it is currently displayed
 	{
 	  const char *s = SSDATA (it.string);
 	  const char *e = s + SBYTES (it.string);
+
+	  disp_string_at_start_p = it.string_from_display_prop_p;
 	  while (s < e)
 	    {
 	      if (*s++ == '\n')
@@ -2062,19 +2065,29 @@ whether or not it is currently displayed
       /* IT may move too far if truncate-lines is on and PT lies
 	 beyond the right margin.  IT may also move too far if the
 	 starting point is on a Lisp string that has embedded
-	 newlines.  In these cases, backtrack.  */
+	 newlines, or spans several screen lines.  In these cases,
+	 backtrack.  */
       if (IT_CHARPOS (it) > it_start)
 	{
-	  /* We need to backtrack also if the Lisp string contains no
-	     newlines, but there is a newline right after it.  In this
-	     case, IT overshoots if there is an after-string just
-	     before the newline.  */
-	  if (it_overshoot_count < 0
-	      && it.method == GET_FROM_BUFFER
-	      && it.c == '\n')
-	    it_overshoot_count = 1;
-	  if (it_overshoot_count > 0)
-	    move_it_by_lines (&it, -it_overshoot_count);
+	  if (it_overshoot_count < 0)
+	    {
+	      /* We need to backtrack also if the Lisp string contains
+		 no newlines, but there is a newline right after it.
+		 In this case, IT overshoots if there is an
+		 after-string just before the newline.  */
+	      if (it.method == GET_FROM_BUFFER && it.c == '\n')
+		it_overshoot_count = 1;
+	      else if (disp_string_at_start_p && it.vpos > 0)
+		{
+		  /* This is the case of a display string that spans
+		     several screen lines.  In that case, we end up at
+		     the end of the string, and it.vpos tells us how
+		     many screen lines we need to backtrack.  */
+		  it_overshoot_count = it.vpos;
+		}
+	      if (it_overshoot_count > 0)
+		move_it_by_lines (&it, -it_overshoot_count);
+	    }
 
 	  overshoot_handled = 1;
 	}






  parent reply	other threads:[~2012-04-06 15:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-30 14:47 bug#11133: 24.0.94; Cursor gets "stuck" on an indented line with wrapped overlay Ivan Andrus
2012-03-30 16:12 ` Eli Zaretskii
2012-03-30 16:49   ` Ivan Andrus
2012-04-06 15:48   ` Eli Zaretskii [this message]
2012-04-07  4:10     ` Stefan Monnier
2012-04-07  7:57       ` Eli Zaretskii

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=8362dcc14w.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=11133@debbugs.gnu.org \
    --cc=darthandrus@gmail.com \
    /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).