rougier / emacs-gtd

Get Things Done with Emacs
https://www.labri.fr/perso/nrougier/GTD/index.html
447 stars 31 forks source link

Automatically saving files after refile #9

Open KirmTwinty opened 3 years ago

KirmTwinty commented 3 years ago

First of all thank you for your GTD tutorial, very pedagogic.

I am still learning to handle it and found that saving each time the different org files after refiling was breaking the workflow of the whole process. Even though saving by hand is a way to make sure that you didn't make a mistake...

Here is how I have done to automatically save the files after refiling:

;; Automatically get the files in "~/Documents/org"
;; with fullpath
(setq org-agenda-files 
      (mapcar 'file-truename 
          (file-expand-wildcards "~/Documents/org/*.org")))

;; Save the corresponding buffers
(defun gtd-save-org-buffers ()
  "Save `org-agenda-files' buffers without user confirmation.
See also `org-save-all-org-buffers'"
  (interactive)
  (message "Saving org-agenda-files buffers...")
  (save-some-buffers t (lambda () 
             (when (member (buffer-file-name) org-agenda-files) 
               t)))
  (message "Saving org-agenda-files buffers... done"))

;; Add it after refile
(advice-add 'org-refile :after
        (lambda (&rest _)
          (gtd-save-org-buffers)))
rougier commented 3 years ago

You made my day ! I've the same problem and never took time to try to solve it.

rougier commented 3 years ago

Could you make a PR for the post with your code (and add your name)?