Created
August 1, 2013 12:26
-
-
Save ffevotte/6130884 to your computer and use it in GitHub Desktop.
Define multiple compilation commands in Emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This macro creates new compilation commands | |
(defmacro ff/add-compilation-command (name &optional key) | |
(let ((buffer-name (concat "*" name "*")) | |
(compile-symbol (intern name)) | |
(recompile-symbol (intern (concat "re" name)))) | |
(when (fboundp compile-symbol) | |
(warn "redefining command `%s'" name)) | |
(when (fboundp recompile-symbol) | |
(warn "redefining command `re%s'" name)) | |
`(progn | |
(defun ,compile-symbol () | |
,(format | |
"This function behaves similarly to `compile', except it puts compilation | |
results in the %s buffer." buffer-name) | |
(interactive) | |
(let ((compilation-buffer-name-function | |
(lambda (mode) "" ,buffer-name))) | |
(call-interactively 'compile))) | |
(defun ,recompile-symbol () | |
,(format | |
"This function behaves similarly to `recompile', except it reuses the | |
last compilation parameters from buffer %s." buffer-name) | |
(interactive) | |
(if (get-buffer ,buffer-name) | |
(with-current-buffer ,buffer-name | |
(let ((compilation-buffer-name-function | |
(lambda (mode) "" ,buffer-name))) | |
(call-interactively 'recompile))) | |
(call-interactively ',compile-symbol))) | |
,(when key | |
`(global-set-key ,key | |
(lambda (arg) | |
,(format "With two universal prefix arguments, call `%s' with | |
a prefix arg, otherwise call `%s'" | |
(symbol-name compile-symbol) | |
(symbol-name recompile-symbol)) | |
(interactive "P") | |
(cond ((equal arg '(16)) | |
(let ((current-prefix-arg '(4))) | |
(call-interactively ',compile-symbol))) | |
(t | |
(call-interactively ',recompile-symbol))))))))) | |
;; Create 4 compilation commands, associated to <F5>--<F8> | |
(ff/add-compilation-command "compile5" (kbd "<f5>")) | |
(ff/add-compilation-command "compile6" (kbd "<f6>")) | |
(ff/add-compilation-command "compile7" (kbd "<f7>")) | |
(ff/add-compilation-command "compile8" (kbd "<f8>")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment