This question is inspired by https://emacs.stackexchange.com/a/5947/.
Assume that I have a function like
(defun do-some-actions () ()
(..put a copy of the current file in a specific folder...)
)
And I would like that the above function to be run after saving files. The following hook can do the job:
(add-hook 'after-save-hook 'do-some-actions)
But in this way Emacs runs the function do-some-action
even for the files which have not been manually saved. For instance when I install the packages via Melpa, Emacs itself saves some files with the name package_name-autoloads.el
in the directory ~/.emacs.d/elpa/package_name/
and even though these files have not been saved manually, the function do-some-actions
is executed.
My question is about the possibility to prevent Emacs to this after-save-hook when the file has not been saved manually.
my-save-buffer
wrapper function that first calls(save-buffer)
and then doesdo-some-actions
and bind that toC-x C-s
in a specific mode map or as a buffer-local binding.M-x apropos-command RET save\|write RET
may help), and then test those conditions in your hook function (e.g. by checking whether thethis-command
value is a member of your list of "saved manually" commands).this-command
, indeed very useful command. What I had in mind by manually saving was saving viasave-buffer
(C-x C-s
). I think your comment to test ifthis-command
has beensave-buffer
is the answer of my question. If you are comfortable please feel free to convert your comment to an answer.after-save-hook
.