Subject: bug#71450: closed (Re: bug#71450: [PATCH] Wrong eww-history-position after desktop restore if within history)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 16 Jun 2024 00:04:01 +0000

Your bug report

#71450: [PATCH] Wrong eww-history-position after desktop restore if within history

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
71450: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71450
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#71450: [PATCH] Wrong eww-history-position after desktop restore if within history
From: Jim Porter <[email-masked]>
To: James Thomas <[email-masked]>, [email-masked]
Date: Sat, 15 Jun 2024 17:01:55 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

On 6/10/2024 2:36 PM, James Thomas via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
> Here's an updated patch, which I've tested somewhat:

Thanks, this looks good to me, so I've merged it as 65b7f87a31d. Closing 
this bug now.

Subject: [PATCH] Wrong eww-history-position after desktop restore if within history
From: James Thomas <[email-masked]>
To: [email-masked]
Date: Sun, 09 Jun 2024 17:53:29 +0530
List-Id: <debbugs-submit.debbugs.gnu.org>

- emacs -Q
- M-x eww RET <any website> RET
- RET (on any link)
- l
- M-x desktop-save RET <any directory> RET
- C-x C-c (exit)
- emacs -Q
- M-x desktop-read RET <the above directory> RET
- g (to reload the webpage)
- RET (on any link) fails

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.18.0) of 2024-06-09 built on
 user-Inspiron-3493
Repository revision: e9a0256a556622474bcbb015f88d790666db2cc9
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: Ubuntu 23.10

Configured using:
 'configure --with-native-compilation=aot'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP
NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_IN
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: iso-latin-1-unix

Major mode: VC dir

Minor modes in effect:
  rcirc-track-minor-mode: t
  display-time-mode: t
  pdf-occur-global-minor-mode: t
  vc-dir-git-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  desktop-environment-mode: t
  server-mode: t
  erc-track-mode: t
  erc-ring-mode: t
  erc-netsplit-mode: t
  erc-menu-mode: t
  erc-match-mode: t
  erc-log-mode: t
  erc-list-mode: t
  erc-irccontrols-mode: t
  erc-noncommands-mode: t
  erc-move-to-prompt-mode: t
  erc-readonly-mode: t
  erc-button-mode: t
  erc-fill-mode: t
  erc-stamp-mode: t
  erc-autojoin-mode: t
  savehist-mode: t
  midnight-mode: t
  icomplete-mode: t
  fido-mode: t
  erc-networks-mode: t
  display-battery-mode: t
  desktop-save-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

This is a patch that I think is simple enough to forgo the extensive
testing which it hasn't been subjected to.

From c5a9be613fb2c0a96db0dadb11ff2584c4ebbc8c Mon Sep 17 00:00:00 2001
From: James Thomas <[email-masked]>
Date: Sun, 9 Jun 2024 17:35:21 +0530
Subject: [PATCH] Correct eww-history-position in desktop restore

Account for duplicate removal from eww-history.

* lisp/net/eww.el (eww-desktop-misc-data): Add :history-position
(eww-restore-desktop): Use it.
(desktop-locals-to-save): Remove the raw variable.
---
 lisp/net/eww.el | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 977210e9cc8..bd63e52ee77 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -2754,11 +2754,17 @@ eww-desktop-misc-data
 Generally, the list should not include the (usually overly large)
 :dom, :source and :text properties."
   (let ((history (mapcar #'eww-desktop-data-1
-                         (cons eww-data eww-history))))
-    (list :history (if eww-desktop-remove-duplicates
-                       (cl-remove-duplicates
-                        history :test #'eww-desktop-history-duplicate)
-                     history))))
+                         (cons eww-data eww-history)))
+        rval)
+    (list :history
+          (setq rval (if eww-desktop-remove-duplicates
+                         (cl-remove-duplicates
+                          history :test #'eww-desktop-history-duplicate)
+                       history))
+          :history-position
+          (cl-position
+           (elt history eww-history-position)
+           rval :test #'eww-desktop-history-duplicate))))

 (defun eww-restore-desktop (file-name buffer-name misc-data)
   "Restore an eww buffer from its desktop file record.
@@ -2772,7 +2778,8 @@ eww-restore-desktop
     (setq eww-history       (cdr (plist-get misc-data :history))
 	  eww-data      (or (car (plist-get misc-data :history))
 			    ;; backwards compatibility
-			    (list :url (plist-get misc-data :uri))))
+			    (list :url (plist-get misc-data :uri)))
+          eww-history-position (plist-get misc-data :history-position))
     (unless file-name
       (when (plist-get eww-data :url)
 	(cl-case eww-restore-desktop
@@ -2784,8 +2791,6 @@ eww-restore-desktop
     ;; .
     (current-buffer)))

-(add-to-list 'desktop-locals-to-save
-	     'eww-history-position)
 (add-to-list 'desktop-buffer-mode-handlers
              '(eww-mode . eww-restore-desktop))

--
2.40.1