Run function before exit emacs
emacs, org-mode, version-control
Solution
vc-dir takes an argument (the "dir").
So you can do:
(add-hook 'kill-emacs-hook (lambda () (vc-dir "your-dir-here")))
Of course this won't stop emacs from exiting: vc-dir opens a buffer but does not "wait" for user input. For the interactive approach you want you can do this:
(add-hook 'kill-emacs-query-functions
(lambda ()
(if (y-or-n-p "Do you want to run function vc-dir before exit?")
(progn
(vc-dir "your-directory")
nil)
t)))
Change `"your-directory"` by `default-directory` if you want to use the last visited buffer as vc-directory.
Problem
I want such feature in org-mode: before exiting emacs (while org-mode is running) it asks me: "Do you want to run function vc-dir before exit?" I tried this: ``` (add-hook 'kill-emacs-hook 'vc-dir) ``` But it errors: "wrong number of arguments" also tried as found here: ``` (defadvice save-buffers-kill-emacs (before update-mod-flag activate) (vc-dir)) ``` The same error. - So how to make it work in easy way: vc-dir runs always on exit. - Or how to make it work with warning message (the best way)? Thanks!