This question How to run an `after-save-hook` only when the buffer has been saved manually provides a way to have after-save hook run after pressing Ctrl-x Ctrl-s, in the answer Here's an alternative solution.

However the hook cannot take a argument. I understand a -function is needed and add-function is to be used instead. The argument I wish to pass to the function is the file path of the buffer being saved as I wish to rsync it to a remote compile server.

1 Answer 1


You don’t need to pass any arguments to anything. The new hook that you have created, after-save-interactively-hook, is called just after saving the current buffer. Any hook functions you add to that list can simply call buffer-file-name to get the name of the file visited by the current buffer. For more information, use C-h f buffer-file-name to view the documentation of this function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.