Is it possible to run a keyboard macro in Emacs right after opening a file? For example, when I open a text file I want to get information in buffer
Keyboard macro vs. Function
Emacs has a lot of "hooks" - lists of functions run at certain point that you can customize for your needs.
"Opening a file" is done by
find-file in Emacs.
Thus, M-x apropos RET find hook RET shows a list of hooks in the
*Apropos* buffer, and you immediately see the one you need:
So, all you need to do is (untested!)
(defun my-find-file-hook () "Mention the newly visited file in the 'Hello World' buffer." (let ((fname buffer-file-name)) (with-current-buffer "Hello World" (insert "just opened files " fname) (display-buffer (current-buffer))))) (add-hook 'find-file-hook 'my-find-file-hook)