Skip to content

Commit

Permalink
add auto-compile-inhibit-compile-hook
Browse files Browse the repository at this point in the history
to allow inhibiting automatic compilation under user-defined
circumstances.

Also add `auto-compile-inhibit-compile-detached-git-head' but do
not add it to the hook variable's default value.

Start using `cl-defun' to define `auto-compile-byte-compile' and
then use `cl-return-from' to abort compilation when the hook succeeds.
This avoids having to reindent the whole thing.
  • Loading branch information
tarsius committed May 18, 2014
1 parent 92ab443 commit 1094863
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion auto-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ found quietly skip this step."
:group 'auto-compile
:type 'boolean)

(defcustom auto-compile-inhibit-compile-hook nil
"Hook used to inhibit automatic compilation.
This hook is run before automatic compilation takes place, if
any of the hook functions returns non-nil, then do not compile."
:group 'auto-compile
:options '(auto-compile-inhibit-compile-detached-git-head)
:type 'hook)

(defcustom auto-compile-verbose nil
"Whether to print messages describing progress of byte-compiler.
Expand Down Expand Up @@ -452,8 +461,10 @@ pretend the byte code file exists.")
(with-current-buffer auto-compile-file-buffer
(cl-incf auto-compile-warnings)))

(defun auto-compile-byte-compile (&optional file start)
(cl-defun auto-compile-byte-compile (&optional file start)
"Perform byte compilation for Auto-Compile mode."
(when (run-hook-with-args-until-success 'auto-compile-inhibit-compile-hook)
(cl-return-from auto-compile-byte-compile))
(let ((default-directory default-directory)
dest buf auto-compile-file-buffer success loaddefs)
(when (and file
Expand Down Expand Up @@ -589,6 +600,13 @@ is only asked once about each such file."
(let ((version-control 'never))
(save-buffer))))))))

(defun auto-compile-inhibit-compile-detached-git-head ()
"Inhibit compiling in Git repositories when `HEAD' is detached.
This is especially useful during rebase sessions."
(with-temp-buffer
(call-process "git" nil t nil "symbolic-ref" "HEAD")
(equal (buffer-string) "fatal: ref HEAD is not a symbolic ref\n")))

;;; Mode-Line

(defvar mode-line-auto-compile
Expand Down

0 comments on commit 1094863

Please sign in to comment.