Skip to content

Instantly share code, notes, and snippets.

@PhilHudson
Created July 18, 2012 15:17
Show Gist options
  • Save PhilHudson/3136807 to your computer and use it in GitHub Desktop.
Save PhilHudson/3136807 to your computer and use it in GitHub Desktop.
Auto-compile elisp
(defun ph/is-elisp-file (filename)
"Returns non-nil if FILENAME ends in either '.el' or '.el.gz'"
(string-match-p "\\.el\\(\\.gz\\)?\\'" filename)
)
(defun ph/autocompile-elisp ()
"Compiles and tags my custom elisp code files on save:
<`dot-emacs'>, and files under the <`ph/elisp-root'> directory.
References: `dot-emacs-file'"
(interactive)
(when
(and
(ph/is-elisp-file (buffer-file-name))
(or
(string= (buffer-file-name) dot-emacs-file)
(string-match-p (concat "^" ph/elisp-root) (buffer-file-name))
)
)
(byte-compile-file (buffer-file-name))
(call-process "rebuild_tags" nil "*Messages*")
)
)
(add-hook 'after-save-hook 'ph/autocompile-elisp)
@PhilHudson
Copy link
Author

'dot-emacs-file' is the pathname of your init.el or .emacs

@PhilHudson
Copy link
Author

'ph/elisp-root' is the directory where you keep your own elisp code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment