Org Agenda: keep the buffer order untouched after saving all modified org buffers
I am managing emails from my Org Agenda. This implies that I save more
often buffers from there. In the Org Agenda buffer the
s key is
org-save-all-org-buffers, which quickly saves all modified
A side effect of saving buffers is that the order of buffers changes.
Say you have this order of buffers (tip: you can use the Elisp
(buffer-list) to get it):
And you call
org-save-all-org-buffers, then the order changes to
because there was a visit to the Org file for saving.
This is a problem for me because while I am working, I get my buffer order messed up and I get distracted.
The fix is an advice:
(defun ag/reorder-buffer-list (new-list) "https://www.gnu.org/software/emacs/manual/html_node/elisp/Buffer-List.html" (while new-list (bury-buffer (car new-list)) (setq new-list (cdr new-list)))) (defun ag/keep-buffer-list-unaltered (orig-fun &rest args) (let ((buffers (buffer-list)) (result (apply orig-fun args))) (reorder-buffer-list buffers) result)) (advice-add 'org-save-all-org-buffers :around #'ag/keep-buffer-list-unaltered)
ag/reorder-buffer-list function orders buffers by exploiting
bury-buffer side effect to push the buried buffer at the end of the
ag/keep-buffer-list-unaltered stores the buffers order
before saving buffers and reorder buffers after saving (i.e.,
Finally a little advice
org-save-all-org-buffers saves the day!