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.
Thanks!
Executing External Commands. You can execute an external shell command from within Emacs using `M-!’ (‘shell-command’). The output from the shell command is displayed in the minibuffer or in a separate buffer, depending on the output size.
Running a Shell Command Asynchronously. You can run a shell command asynchronously by adding an ampersand ( &) after it, if you have a UNIX or UNIX-like environment. Here is some EmacsLisp code that modifies ‘shell-command’ to allow many commands to execute asynchronously (and show the command at the top of the buffer):
ex – Function ‘ex-defun’ defines an EmacsLisp function that does its job by invoking an external interpreted language run-command – Package ‘run-command’ allows creating dynamic lists of external commands and selecting from them using auto-completion
If the value of the variable confirm-kill-emacs is non- nil, C-x C-c assumes that its value is a predicate function, and calls that function. If the result of the function call is non- nil, the session is killed, otherwise Emacs continues to run.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With