Created
November 28, 2014 15:25
-
-
Save gdsfh/a87f039e5796e57e2c3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; create before first run: | |
(defun user-macro-file() "~/.emacs.d/custom-macros.el") | |
(load (user-macro-file)) | |
(defun save-macro (name) | |
"save a macro. Take a name as argument and save the last defined macro under this name at the end of your .emacs" | |
(interactive "SName of the macro: ") ; ask for the name of the macro | |
(kmacro-name-last-macro name) ; use this name for the macro | |
(find-file (user-macro-file)) ; open ~/.emacs or other user init file | |
(goto-char (point-max)) ; go to the end of the .emacs | |
(newline) ; insert a newline | |
(insert-kbd-macro name) ; copy the macro | |
(newline) ; insert a newline | |
(save-buffer) | |
(switch-to-buffer nil)) ; return to the initial buffer | |
(defun save-macro-bind-key (name key) | |
"save a macro. Take a name, keybinding as arguments and save the last defined macro under this name at the end of your .emacs" | |
(interactive "SName of the macro: \nKKey binding: ") ; ask for the name of the macro and a keybinding | |
(kmacro-name-last-macro name) ; use this name for the macro | |
(find-file (user-macro-file)) ; open ~/.emacs or other user init file | |
(goto-char (point-max)) ; go to the end of the .emacs | |
(newline) ; insert a newline | |
(insert-kbd-macro name) ; copy the macro | |
(newline) ; insert a newline | |
(insert (format "(global-set-key (kbd \"%s\") '%s)" | |
(key-description key) name)) | |
(newline) | |
(save-buffer) | |
(switch-to-buffer nil) ; return to the initial buffer | |
(global-set-key key name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment