aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/oni-compilation.el
blob: 54e20f045f4133e5e94bb16b48067f872d481d79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
;; Start of oni-stillness

(use-package compile
  :config
  (require 'subr-x)
  (require 'xterm-color)

  (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--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-match-p (rx "*compilation*" "*Chanced Tests*") (buffer-name buffer))
      (if (string= (string-trim status) "finished")
          (alert "Compilation finished succesfully")
        (alert "Compilation finished with an error"))))

  (defun oni-compilation--filter-xterm-colors (func proc string)
    "Call FUNC with PROC and STRING filtered through ‘xterm-color-filter’."
    (funcall func proc (xterm-color-filter string)))

  (setq compilation-scroll-output t)
  (setq compilation-environment '("TERM=xterm-256color"))

  (add-to-list 'display-buffer-alist
               '("\\`\\*compilation\\*\\'" display-buffer-in-side-window
                 (side . bottom)
                 (slot . 0)
                 (window-height . 0.33)))

  (add-hook 'compilation-finish-functions
            #'oni-compilation--maybe-display-compilation-window)

  (add-hook 'compilation-finish-functions
            #'oni-compilation--compilation-finish-notify-function)

  (advice-add 'compilation-filter :around #'oni-compilation--filter-xterm-colors))

;; End of oni-stillness