unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: michael_heerdegen@web.de
Cc: 21012@debbugs.gnu.org
Subject: bug#21012: 25.0.50; eww: last char of a line sometimes not fully visible
Date: Thu, 09 Jul 2015 18:34:03 +0300	[thread overview]
Message-ID: <834mlduyz8.fsf@gnu.org> (raw)
In-Reply-To: <83a8v6ukbe.fsf@gnu.org>

> Date: Thu, 09 Jul 2015 05:38:29 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: 21012@debbugs.gnu.org
> 
> > I think you looked at the wrong `if' branch...?  What I changed was to
> > use `end-of-visual-line', which I hope is more accurate than
> > 
> >   (vertical-motion (cons (/ column (frame-char-width)) 0))
> > 
> > for finding the right point for breaking the line.
> 
> Maybe, it sounds like I need to take a better look.

I did that now.  There are a few subtle issues with this, as described
below.  Please try the patch at the end of this message, and see if it
gives good results.  You didn't provide a reproducible test case for
the screenshots you show, so I used Yamaoka-san's recipe; the patch
below fixes all the issues I saw with that recipe.

First, regarding your suggestion above to use end-of-visual-line: this
is only TRT when shr-width is nil, i.e. shr is filling text to the
full window width.  But shr-vertical-motion should also support the
case when shr-width is some specific number of columns or pixels, in
which case end-of-visual-line will put us at the wrong position.

Now to the issues I found.

First, the value of shr-internal-width was computed incorrectly: it
used window-width, which, as you discovered, is more than the text
area width, and it subtracted 2 columns from that value, whereas it
really needs to subtract only 1 (since column numbers are zero-based).

The 2nd issue was in shr-find-fill-point, where it deals with CJK
characters using the kinsoku feature: (a) it preferred to look for a
breakable point forward even when shr-width is nil, which produces
continuation lines; and (b) it mistakenly allowed to break the line
before a character that is forbidden by kinsoku to be at BOL.

Yet another subtlety is only visible when you disable one of the
fringes (or both): the calculation of shr-internal-width should in
that case subtract one more column, to be reserved for the
continuation glyph.  The patch below fixes that as well, albeit
slightly crudely (we sometimes lose a column); suggestions for how to
do that better are welcome.

Here's a patch that attempts at fixing all but the last of these
issues; if it gives good results, I will install it.  If not, please
show a test case that reproduces whatever problems are left.

Thanks.

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 0ce77b9..f440abf 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -222,10 +222,29 @@ (defun shr-insert-document (dom)
 				     (if (not shr-use-fonts)
 					 shr-width
 				       (* shr-width (frame-char-width))))
+                                ;; We need to adjust the available
+                                ;; width for when the user disables
+                                ;; the fringes, which will cause the
+                                ;; display engine usurp one column for
+                                ;; the continuation glyph.
 				(if (not shr-use-fonts)
-				    (- (window-width) 2)
-				  (- (window-pixel-width)
-				     (* (frame-fringe-width) 2))))))
+				    (- (window-body-width) 1
+                                       (if (and (null shr-width)
+                                                (or (zerop
+                                                     (fringe-columns 'right))
+                                                    (zerop
+                                                     (fringe-columns 'left))))
+                                           0
+                                         1))
+				  (- (window-body-width nil t)
+                                     (frame-char-width)
+                                     (if (and (null shr-width)
+                                              (or (zerop
+                                                   (fringe-columns 'right))
+                                                  (zerop
+                                                   (fringe-columns 'left))))
+                                         (* (frame-char-width) 2)
+                                       0))))))
     (shr-descend dom)
     (shr-fill-lines start (point))
     (shr-remove-trailing-whitespace start (point))
@@ -439,8 +458,18 @@ (defun shr-fill-text (text)
     (with-temp-buffer
       (let ((shr-indentation 0)
 	    (shr-start nil)
-	    (shr-internal-width (- (window-pixel-width)
-				   (* (frame-fringe-width) 2))))
+	    (shr-internal-width (- (window-body-width nil t)
+                                   (frame-char-width)
+                                   ;; Adjust the window width for when
+                                   ;; the user disables the fringes,
+                                   ;; which causes the display engine
+                                   ;; usurp one coplumn for the
+                                   ;; continuation glyph.
+                                   (if (and (null shr-width)
+                                            (or (zerop (fringe-columns 'right))
+                                                (zerop (fringe-columns 'left))))
+                                       (* (frame-char-width) 2)
+                                     0))))
 	(shr-insert text)
 	(buffer-string)))))
 
@@ -620,7 +649,9 @@ (defun shr-find-fill-point (start)
 	;; There's no breakable point, so we give it up.
 	(let (found)
 	  (goto-char bp)
-	  (unless shr-kinsoku-shorten
+          ;; Don't overflow the window edge, even if
+          ;; shr-kinsoku-shorten is nil.
+	  (unless (or shr-kinsoku-shorten (null shr-width))
 	    (while (setq found (re-search-forward
 				"\\(\\c>\\)\\| \\|\\c<\\|\\c|"
 				(line-end-position) 'move)))
@@ -632,9 +663,12 @@ (defun shr-find-fill-point (start)
        ;; Don't put kinsoku-bol characters at the beginning of a line,
        ;; or kinsoku-eol characters at the end of a line.
        (cond
-	(shr-kinsoku-shorten
+        ;; Don't overflow the window edge, even if shr-kinsoku-shorten
+        ;; is nil.
+	((or shr-kinsoku-shorten (null shr-width))
 	 (while (and (not (memq (preceding-char) (list ?\C-@ ?\n ? )))
-		     (shr-char-kinsoku-eol-p (preceding-char)))
+		     (or (shr-char-kinsoku-eol-p (preceding-char))
+                         (shr-char-kinsoku-bol-p (following-char))))
 	   (backward-char 1))
 	 (when (setq failed (<= (point) start))
 	   ;; There's no breakable point that doesn't violate kinsoku,





  parent reply	other threads:[~2015-07-09 15:34 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 18:10 bug#21012: 25.0.50; eww: last char of a line sometimes not fully visible Michael Heerdegen
2015-07-08 20:03 ` Eli Zaretskii
2015-07-08 20:24   ` Michael Heerdegen
2015-07-09  2:38     ` Eli Zaretskii
2015-07-09 11:01       ` Michael Heerdegen
2015-07-09 14:43         ` Eli Zaretskii
2015-07-09 19:42           ` Michael Heerdegen
2015-07-09 15:34       ` Eli Zaretskii [this message]
2015-07-09 20:06         ` Michael Heerdegen
2015-07-10  6:03           ` Eli Zaretskii
2015-07-10 12:55             ` Michael Heerdegen
2015-07-10 13:06               ` Eli Zaretskii
2015-07-10 14:16                 ` Michael Heerdegen
2015-07-10 14:43                   ` Eli Zaretskii
2015-07-10 18:04                     ` Michael Heerdegen
2015-07-10 18:45                       ` Eli Zaretskii
2015-07-10 19:19                         ` Michael Heerdegen
2015-07-10 19:31                           ` Eli Zaretskii
2015-07-11 12:02                             ` Michael Heerdegen
2015-07-11 13:45                               ` Eli Zaretskii
2015-07-20 16:33                                 ` Michael Heerdegen
2015-07-20 16:34                                   ` Eli Zaretskii
2015-07-21 18:49                                     ` Michael Heerdegen
2015-09-25  4:00                                       ` Katsumi Yamaoka
2015-09-25 14:45                                         ` Michael Heerdegen
2015-09-28 21:30                                           ` Michael Heerdegen
2015-09-29  5:37                                             ` Eli Zaretskii
2015-10-03  8:08                                               ` Michael Heerdegen
2015-10-03  9:42                                                 ` Eli Zaretskii
2015-10-03 12:41                                                   ` Michael Heerdegen
2015-10-04  6:31                                                     ` Michael Heerdegen
2015-10-04  7:09                                                       ` Eli Zaretskii
2015-10-04  7:11                                                       ` Michael Heerdegen
2015-10-04  7:39                                                         ` Michael Heerdegen
2015-10-04  8:49                                                           ` Eli Zaretskii
2015-10-04 10:18                                                             ` Michael Heerdegen
2015-07-08 20:31   ` Michael Heerdegen
2015-10-07  6:34 ` bug#21012: Close Michael Heerdegen

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=834mlduyz8.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=21012@debbugs.gnu.org \
    --cc=michael_heerdegen@web.de \
    /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).