I’ve spent a lot of time doing repetitive tasks in Emacs lately, which prompted med to make the following function. This function asks for a name and a keyboard binding, saves the latest defined macro in my .emacs (my .emacs is located in .emacs.d since I have .emacs.d in a git repository), adds a keybinding to it, saves my .emacs file, reloads it so the keybinding will work immediately and updates the git repository that my .emacs file resides in.
(defun save-macro (name keybinding)
"save latest macro defined macro and a keybinding to it to .emacs"
(interactive "Name of the macro: \nSKey binding for macro %s: ")
(kmacro-name-last-macro name)
(find-file "~/.emacs.d/.emacs")
(goto-char (point-max))
(newline)
(insert-kbd-macro name)
(newline)
(insert (format "(global-set-key (kbd \"%s\") '%s)" keybinding name))
(newline)
(save-buffer)
(switch-to-buffer nil)
(load-file "~/.emacs.d/.emacs")
(shell-command "cd ~/.emacs.d;git pull origin master;git commit -am 'added macro to .emacs';git push;")
(kill-buffer "*Shell Command Output*"))