Commit b8095aa83fa3

Vincent Demeester <vincent@sbr.pm>
2026-02-13 11:49:02
fix(emacs): removed disruptive buffer reverts from org-batch-functions
Removed all revert-buffer calls that were forcing Emacs to reload org files from disk during batch operations. This was extremely disruptive when working interactively, causing cursor position resets and discarding unsaved changes. Affected functions now work on current buffer state with documentation notes explaining disk sync behavior.
1 parent 7d5c5fa
Changed files (1)
dots
config
emacs
dots/config/emacs/site-lisp/org-batch-functions.el
@@ -351,9 +351,9 @@ NEW in v2.0."
 (defun org-batch-get-all-entries (file &optional level)
   "Get all headings from FILE, including non-TODO entries.
 LEVEL: if provided, only get headings at that level (default: all top-level).
-Includes both TODO items and plain entries (like links, notes)."
+Includes both TODO items and plain entries (like links, notes).
+NOTE: Works on current buffer state - save before calling if disk sync needed."
   (with-current-buffer (find-file-noselect file)
-    (revert-buffer t t)
     (org-ql-select (current-buffer)
       (if level
           `(level ,level)
@@ -1091,10 +1091,10 @@ ERROR: error message if any"
 (defun org-batch-get-refile-targets (file &optional max-level)
   "Get valid refile targets from FILE up to MAX-LEVEL depth.
 MAX-LEVEL defaults to 2 (sections and sub-sections).
-Returns list of targets with their outline path and positions."
+Returns list of targets with their outline path and positions.
+NOTE: Works on current buffer state - save before calling if disk sync needed."
   (let ((depth (or max-level 2)))
     (with-current-buffer (find-file-noselect file)
-      (revert-buffer t t)
       (org-ql-select (current-buffer)
         `(and (level <= ,depth)
               (not (todo "DONE" "CANX")))
@@ -1110,10 +1110,9 @@ Returns list of targets with their outline path and positions."
 
 (defun org-batch-refile-entry (source-file source-heading target-file target-section)
   "Refile entry with SOURCE-HEADING from SOURCE-FILE to TARGET-SECTION in TARGET-FILE.
-Returns t on success, signals error on failure."
+Returns t on success, signals error on failure.
+NOTE: Works on current buffer state - save buffers before calling if disk sync needed."
   (with-current-buffer (find-file-noselect source-file)
-    ;; Ensure buffer is up-to-date with disk
-    (revert-buffer t t)
     ;; Find the source heading (match with or without TODO keyword)
     (goto-char (point-min))
     (unless (re-search-forward
@@ -1127,7 +1126,6 @@ Returns t on success, signals error on failure."
     ;; Find target location in target file
     (let* ((target-buf (find-file-noselect target-file))
            (target-pos (with-current-buffer target-buf
-                        (revert-buffer t t)
                         (goto-char (point-min))
                         (when (re-search-forward
                                (concat "^\\* " (regexp-quote target-section))
@@ -1153,9 +1151,9 @@ Returns t on success, signals error on failure."
 TARGET-SECTION is used as the label for org-refile.
 TARGET-POSITION must be a buffer position in TARGET-FILE.
 SOURCE-POSITION, if provided, is used directly instead of searching.
-Returns t on success, signals error on failure."
+Returns t on success, signals error on failure.
+NOTE: Works on current buffer state - save buffers before calling if disk sync needed."
   (with-current-buffer (find-file-noselect source-file)
-    (revert-buffer t t)
     (if source-position
         ;; Use exact position
         (goto-char source-position)
@@ -1168,10 +1166,8 @@ Returns t on success, signals error on failure."
         (error "Heading not found in %s: %s" source-file source-heading))
       (goto-char (line-beginning-position)))
 
-    ;; Ensure target buffer is up-to-date
+    ;; Get target buffer
     (let ((target-buf (find-file-noselect target-file)))
-      (with-current-buffer target-buf
-        (revert-buffer t t))
 
       ;; Perform the refile using org-refile with the exact position
       (org-refile nil nil