Subject: Re: bug#40532: 28.0.50; eww/shr: Anchor link does not work

From: "Basil L. Contovounesios" <[email-masked]>
Date: Wed, 22 Apr 2020 12:38:17 +0100

found 40532 27.0.50
tags 40532 + patch
quit

Arnaud Fontaine <[email-masked]> writes:

> I have  investigated a little  and it  seems to be  because of a  bug in
> eww-follow-link (bound to RET key).

Indeed; I think it's a regression in Emacs 27 caused by the following
fix for bug#28441:

Make #anchors work again in eww
fa41693799 2018-04-13 14:55:55 +0200
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=fa416937997a113d84ab4e4910d730ce5d77613d

Previously, eww-follow-link depended on eww-display-html to set
shr-target-id, but following this change that's no longer the case.

This doesn't affect eww-reload, which also calls eww-display-html,
because it passes it an explicit position to jump to.

> It goes to the anchor link by clicking on it (<mouse-2>) or with 'v' key
> as it  actually calls  shr-browse-url (but this  has the  side-effect of
> reloading the whole page though).

Yes, we wouldn't want eww-follow-link to do that, and in fact it already
contains logic to avoid reloading the whole page, modulo the
aforementioned regression in Emacs 27.

Lars, Eli, how's the following fix for emacs-27?

>From 213264081a827e9041dbab294a5ff72fdc71b45f Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <[email-masked]>
Date: Wed, 22 Apr 2020 11:42:17 +0100
Subject: [PATCH] Fix following target on same page in EWW

* lisp/net/eww.el (eww-follow-link): Set shr-target-id before
calling eww-display-html as the latter no longer does so for
us (bug#28441, bug#40532).
---
 lisp/net/eww.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index c83884fd25..8bbbcae9c2 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -1578,7 +1578,8 @@ eww-follow-link
      ;; This is a #target url in the same page as the current one.
      ((and (url-target (url-generic-parse-url url))
 	   (eww-same-page-p url (plist-get eww-data :url)))
-      (let ((dom (plist-get eww-data :dom)))
+      (let ((dom (plist-get eww-data :dom))
+            (shr-target-id (url-target (url-generic-parse-url url))))
 	(eww-save-history)
 	(plist-put eww-data :url url)
 	(eww-display-html 'utf-8 url dom nil (current-buffer))))
-- 
2.26.1

Thanks,

-- 
Basil