lewang / ws-butler

Unobtrusively trim extraneous white-space *ONLY* in lines edited.
242 stars 26 forks source link

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

Open bitclick opened 1 year ago

bitclick commented 1 year ago

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

notes

bitclick commented 1 year ago

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 commented 5 months ago

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