1

I would like to write a function that does the equivalent of the shell command:

vim $MY_FILE && $MY_COMMAND

In other words, I would like to open a file in a buffer, and then when I save/close that buffer, I want it to run a certain shell command. How would I do this?

Furthermore, the shell command must be run in su mode, so I need to either run it in an interactive shell so that the sudo mode prompts for the password, or maybe have a popup that asks for the superuser password somehow.

  • Just use after-save-hook: C-h v after-save-hook. – Drew Dec 24 '16 at 23:30
  • @Drew Is there a function equivalent of C-h v? I'm writing a function, not looking for a key combination. – sid-kap Dec 26 '16 at 17:02
  • 1
    @sid-kap C-h v after-save-hook RET will give you the documentation for the variable after-save-hook, which is what @Drew suggests you use. You can add a hook with (add-hook 'after-save-hook #'my-function) or (add-hook 'after-save-hook (lambda () ...)). – Basil May 17 '17 at 7:38
  • @sid-kap See also variable kill-buffer-hook. – Basil May 17 '17 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.