To speak to others is to first silence those in whose name we speak. (Callon 1986)

Automating Emacs

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 "SName 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*"))
        
posted on 22 Sep 2010

About me

    • Languages of choice
    • C, python, perl and lisp
    • Current interests
    • GSM-networks and technology, Emacs, Stumpwm, org-mode, philosophy and ethics, microprocessors, Drupal, Latex and writing.