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

org-element-cache warning when saving with ws-butler-keep-whitespace-before-point #44

Open
bitclick opened this issue Sep 2, 2022 · 2 comments

Comments

@bitclick
Copy link

bitclick commented Sep 2, 2022

affected version:

GNU Emacs     v27.2           
Doom core     v3.0.0-dev      
Doom modules  v22.08.0-dev     grafted, HEAD -> master, origin/master, origin/HEAD c44bc81 2022-08-19 11:24:34 +0200
Org mode version 9.6 (9.6-??-00adad9)

problem

  • ws-butler-keep-whitespace-before-point set to t
  • org-element-use-cache is set to t
  • saving an orgmode buffer, with trailing spaces before the point
  • warning pops up:
Warning (org-element-cache): org-element--cache: Unregistered buffer modifications detected. Resetting.
If this warning appears regularly, please report the warning text to Org mode mailing list (M-x org-submit-bug-report).
The buffer is: xyz.org
 Current command: nil
 Backtrace:
"  backtrace-to-string(nil)
  org-element--cache-sync(#<buffer xyz.org>)
  apply(org-element--cache-sync #<buffer xyz.org>)
  timer-event-handler([t 0 5 323697 nil org-element--cache-sync (#<buffer xyz.org>) idle 850999])
"

notes

  • i think it is because ws-butler-after-save modifies the buffer while inhibiting org-element change-hook functions to run (org-element--cache-before-change and/or org-element--cache-after-change)
  • see fix in org-transclusion for a solution to a similar problem
  • workaround is disabling org-element cache 😒
@bitclick
Copy link
Author

bitclick commented Sep 2, 2022

dooms modules add an advice to ws-butler-after-save (modules/ui/modeline/config.el):

  ;; Some functions modify the buffer, causing the modeline to show a false
  ;; modified state, so force them to behave.
  (defadvice! +modeline--inhibit-modification-hooks-a (fn &rest args)
    :around #'ws-butler-after-save
    (with-silent-modifications (apply fn args)))

but this seems not to be the cause (i tested it without the advice), problem still occurs

@postcert
Copy link

postcert commented Mar 11, 2024

I know it's a bit late but I created a ws-butler-trim-predicate function that helps me partially avoid this issue.

(after! ws-butler
  (setq ws-butler-trim-predicate
      (lambda (beg end)
        (let* ((current-line (line-number-at-pos))
               (beg-line (line-number-at-pos beg))
               (end-line (line-number-at-pos end))
               ;; Assuming the use of evil-mode for insert mode detection. Adjust if using a different system.
               (in-insert-mode (and (bound-and-true-p evil-mode)
                                    (eq 'insert evil-state))))
          ;; Return true (allow trimming) unless in insert mode and the current line is within the region.
          (not (and in-insert-mode
                    (>= current-line beg-line)
                    (<= current-line end-line))))))
)

Simply avoid trimming a region if it contains the $current_line I am in insert-mode with.
I currently use auto-save @ the default interval so it'll eventually clean up any trailing whitespace.

For my use this expectation only fails when I switch buffers quickly (auto-save won't trigger anymore) but that is unrelated to ws-butler. I hope it helps @bitclick

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