tcw165/history

Invalid window-start corrupt history stack

Opened this issue · 0 comments

I have an issue where the history gets corrupted when I go history-prev-history then history-next-history.

I investigated and It seems to happen when (window-start) returns 1 when it should have returned > 1 in the advice after jump.

I debugged by adding some (message "..." ...) to a few functions, and annotated the output to hopefully explain what happens:

;; - starting in file test.rs, at char 136

;; - jumping to marker.rs@10630:
history-add-history ;; advice before jump
history-create/push-history (:marker #<at 136 in test.rs> :window-start 1)
racer-find-definition ;; jump
history-add-history ;; advice after jump
history-create/push-history (:marker #<at 10630 in marker.rs> :window-start 1)
;; >> WRONG (window-start) returned 1, should have returned 8718

;; - here, now running `M-: (window-start)` returns the right value of 8718, not 1

;; - go back to test.rs@136:
history-prev-history
history-use-current-history: (:marker #<at 136 in test.rs> :window-start 1)

;; - go next, return to marker.rs@10630:
history-next-history
history-use-current-history: (:marker #<at 10630 in marker.rs> :window-start 1)
;; >> now we are at wrong location: jumped at marker.rs@1153 instead of 10630,
;; probably because (set-window-start nil 1) should have been 8718
;; and then (goto-char 10630) somehow didn't work properly ??

;; - now at marker.rs@1153 instead of 10630

I don't have much idea what I'm doing here, poked around, I couldn't get (window-start) to return the right value, so tried something else and this seems to fix the issue for me, without breaking #6 :

diff --git a/history.el b/history.el
index f8aa91d9010d..d1faea30ece9 100644
--- a/history.el
+++ b/history.el
@@ -374,7 +374,7 @@ whether `history-window-local-history' is true or false."
     (set-window-buffer (history-window) buffer)
     (set-buffer buffer)
     ;; Update window-start.
-    (set-window-start nil wpos)
+    (set-window-start nil wpos 'noforce)
     ;; Update point.
     (goto-char pos)))

Not ideal I think, window-start/wpos is still invalid, but set-window-start with NOFORCE seems to not make goto-char go to the wrong location.


Note: It happens with all the jump functions I use; here is my config:

(require 'history)
(add-to-list 'history-advised-before-functions 'rtags-find-symbol-at-point t)
(add-to-list 'history-advised-after-functions 'rtags-find-symbol-at-point t)
(add-to-list 'history-advised-before-functions 'godef-jump t)
(add-to-list 'history-advised-after-functions 'godef-jump t)
(add-to-list 'history-advised-before-functions 'racer-find-definition t)
(add-to-list 'history-advised-after-functions 'racer-find-definition t)
(setq-default history-window-local-history t)
(history-mode 1)

emacs --version: GNU Emacs 26.1