Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

void-variable revert-buffer-preserve-modes #210

Closed
fleimgruber opened this issue Feb 19, 2024 · 1 comment
Closed

void-variable revert-buffer-preserve-modes #210

fleimgruber opened this issue Feb 19, 2024 · 1 comment

Comments

@fleimgruber
Copy link

When follow-mode is enabled, I am seeing this error:

Debugger entered--Lisp error: (void-variable revert-buffer-preserve-modes)
  diff-hl-after-revert()
  auto-revert-tail-handler(70974)
  auto-revert-handler()
  auto-revert-buffer(#<buffer report.log>)
  #<subr auto-revert-buffers>()
  auto-revert-buffers--buffer-list-filter(#<subr auto-revert-buffers>)
  apply(auto-revert-buffers--buffer-list-filter #<subr auto-revert-buffers> nil)
  auto-revert-buffers()
  apply(auto-revert-buffers nil)
  timer-event-handler([t 26067 15968 683324 5 auto-revert-buffers nil nil 0 nil])

I am able to work around this via setting this in user config:

(setq revert-buffer-preserve-modes t)

I found related #205 (comment), and in particular calling diff-hl-after-revert outside of after-revert-hook is not supported, so I am figuring out why it gets called this way. Could not find anything related in my user config or Spacemacs setup.

@dgutov
Copy link
Owner

dgutov commented Feb 19, 2024

Hi!

It seems like the prerequisite was enabling auto-revert-tail-mode. It reuses the hook, whether that's a good idea or not, so we'll need to adapt.

I wonder whether it's a good idea to run diff-hl-after-revert every time auto-revert-tail-handler fires (supposedly it can fire quite often), but if we should revert as well, the fix would look like this:

diff --git a/diff-hl.el b/diff-hl.el
index 2a8bce5..4885b16 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -466,7 +466,8 @@ the current version of the file)."
 
 (defun diff-hl-after-revert ()
   (defvar revert-buffer-preserve-modes)
-  (when revert-buffer-preserve-modes
+  (when (or (not (boundp 'revert-buffer-preserve-modes))
+            revert-buffer-preserve-modes)
     (diff-hl-update)))
 
 (defun diff-hl-diff-goto-hunk-1 (historic)

Otherwise, it will be this:

diff --git a/diff-hl.el b/diff-hl.el
index 2a8bce5..56f66b4 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -465,8 +465,7 @@ the current version of the file)."
       (diff-hl-update))))
 
 (defun diff-hl-after-revert ()
-  (defvar revert-buffer-preserve-modes)
-  (when revert-buffer-preserve-modes
+  (when (bound-and-true-p revert-buffer-preserve-modes)
     (diff-hl-update)))
 
 (defun diff-hl-diff-goto-hunk-1 (historic)

@dgutov dgutov closed this as completed in f66345e Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants