aboutsummaryrefslogtreecommitdiffstats
path: root/oni-compilation.el
diff options
context:
space:
mode:
authorGravatar Tom Willemse2019-02-26 01:14:57 -0800
committerGravatar Tom Willemse2019-02-26 01:14:57 -0800
commitdb73942082f4d314fb017c832b2a2aea216d73ab (patch)
tree6144daf83203b780ef4b3de83bc70cf02aa1bf97 /oni-compilation.el
parent931e4b0bf5905517d7d038fae8fdc19767b7e793 (diff)
downloademacs-config-db73942082f4d314fb017c832b2a2aea216d73ab.tar.gz
emacs-config-db73942082f4d314fb017c832b2a2aea216d73ab.zip
Add oni-compilation
Diffstat (limited to 'oni-compilation.el')
-rw-r--r--oni-compilation.el80
1 files changed, 80 insertions, 0 deletions
diff --git a/oni-compilation.el b/oni-compilation.el
new file mode 100644
index 0000000..4df7aeb
--- /dev/null
+++ b/oni-compilation.el
@@ -0,0 +1,80 @@
+;;; oni-compilation.el --- Compilation configuration -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2019 Tom Willemse
+
+;; Author: Tom Willemse <tom@ryuslash.org>
+;; Keywords: local
+;; Version: 20190226011246
+;; Package-Requires: (oni-shackle)
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Configuration for the compilation mode.
+
+;;; Code:
+
+(require 'compile)
+(require 'shackle)
+(require 'subr-x)
+
+(setq compilation-scroll-output t)
+
+(defun oni-compilation--maybe-dont-show-window (buffer-or-name alist plist)
+ "Don't show BUFFER-OR-NAME unless it absolutely must.
+
+ALIST and PLIST contain extra information about the buffer."
+ (if (alist-get 'allow-no-window alist)
+ buffer-or-name
+ (funcall (plist-get plist :fallback) buffer-or-name alist
+ (plist-put (copy-sequence plist) :custom nil))))
+
+(defun oni-compilation--maybe-display-compilation-window (buffer status)
+ "Display BUFFER if STATUS is not finished."
+ (unless (string= (string-trim status) "finished")
+ (display-buffer buffer)))
+
+(defun oni-compilation--ansi-color-for-compilation-filter ()
+ "Apply ANSI terminal escape codes to compilation output."
+ (ansi-color-apply-on-region compilation-filter-start (point)))
+
+(defun oni-compilation--compilation-finish-notify-function (buffer status)
+ "Show an alert of the status of the compliation.
+
+BUFFER is the `compilation-mode' buffer and STATUS is the exit
+status of the process."
+ (when (string= (buffer-name buffer) "*compilation*")
+ (if (string= (string-trim status) "finished")
+ (alert "Compilation finished succesfully")
+ (alert "Compilation finished with an error"))))
+
+(add-to-list 'shackle-rules
+ '(compilation-mode :custom oni-compilation--maybe-dont-show-window
+ :fallback shackle-display-buffer
+ :other t :select t))
+
+(add-hook 'compilation-filter-hook
+ #'oni-compilation--ansi-color-for-compilation-filter)
+
+(add-hook 'compilation-finish-functions
+ #'oni-compilation--maybe-display-compilation-window)
+
+(add-hook 'compilation-finish-functions
+ #'oni-compilation--compilation-finish-notify-function)
+
+;;;###autoload(with-eval-after-load 'compile (require 'oni-compilation))
+
+(provide 'oni-compilation)
+;;; oni-compilation.el ends here