Skip to content

Instantly share code, notes, and snippets.

@LesleyLai
Last active September 9, 2022 22:28
Show Gist options
  • Save LesleyLai/627085e275d2cf46429c0f44c27a92d7 to your computer and use it in GitHub Desktop.
Save LesleyLai/627085e275d2cf46429c0f44c27a92d7 to your computer and use it in GitHub Desktop.
Recompile the emacs lisp file on save if the byte-compiled file exist
(defun recompile-elc-on-save ()
"If you're saving an elisp file, likely the .elc is no longer valid."
(make-local-variable 'after-save-hook)
(add-hook 'after-save-hook
(lambda ()
(if (file-exists-p (byte-compile-dest-file buffer-file-name))
(byte-compile-file buffer-file-name)))))
(add-hook 'emacs-lisp-mode-hook 'recompile-elc-on-save
)
@roomworoof
Copy link

Very helpful. Thanks!

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