I thought it would be great to save a Elisp file (in my init), and it compiles automatically a byte-compile Elisp-file.
So I wrote a function for this.
(defun remove-elc-and-compile-on-save ()
"If you're saving an elisp file, likely the .elc is no longer valid. And automatically byte-recompile this file whenever it's saved."
(interactive)
(if (file-exists-p (concat buffer-file-name "c"))
(delete-file (concat buffer-file-name "c"))
nil)
(byte-compile-file buffer-file-name)
)
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(add-hook 'after-save-hook 'remove-elc-and-compile-on-save nil 'make-it-local)))
For example, the directory structure where my Elisp files are: C:\foobar\Emacs\setup-foobar.el.
(It's a Windows structure).
It works perfectly. However, my Emacs directory with the Elips-files will be spoiled with the compiled .elc
-files all over the place. So I thought to move the .elc
-files to a specific directory.
For example, the directory structure where my Elisp files are: C:\foobar\Emacs\setup-foobar.el.
(It's a Windows structure).
Then I would like to move the .elc
files to C:\foobar\Emacs\setup\setup-foobar.el.
When I checked the documentation of the functions file-exists-p
, delete-file
, byte-compile-file
, there is no optional parameter available to specify the path where the delete/compilation operations should occur. They're executed in the same directory as the buffer-file-name
.
I tried another ways like:
(byte-compile-file (concat "C:/foobar/Emacs/setup/" buffer-file-name))
But it didn't worked out, and it's not applicable for the file-exists-p
and delete-file
functions.
So I'm wondering in which way I could specify the path where the operations should be executed, instead in the same directory as the buffer?