summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/rust-compile.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/rust-compile.el')
-rw-r--r--.emacs.d/lisp/rust-compile.el83
1 files changed, 83 insertions, 0 deletions
diff --git a/.emacs.d/lisp/rust-compile.el b/.emacs.d/lisp/rust-compile.el
new file mode 100644
index 0000000..1bb3103
--- /dev/null
+++ b/.emacs.d/lisp/rust-compile.el
@@ -0,0 +1,83 @@
1;;; rust-compile.el --- Compile facilities -*-lexical-binding: t-*-
2;;; Commentary:
3
4;; This library teaches `compilation-mode' about "rustc" output.
5
6;;; Code:
7
8(require 'compile)
9
10;;; _
11
12(defvar rustc-compilation-location
13 (let ((file "\\([^\n]+\\)")
14 (start-line "\\([0-9]+\\)")
15 (start-col "\\([0-9]+\\)"))
16 (concat "\\(" file ":" start-line ":" start-col "\\)")))
17
18(defvar rustc-compilation-regexps
19 (let ((re (concat "^\\(?:error\\|\\(warning\\)\\|\\(note\\)\\)[^\0]+?--> "
20 rustc-compilation-location)))
21 (cons re '(4 5 6 (1 . 2) 3)))
22 "Specifications for matching errors in rustc invocations.
23See `compilation-error-regexp-alist' for help on their format.")
24
25(defvar rustc-colon-compilation-regexps
26 (let ((re (concat "^ *::: " rustc-compilation-location)))
27 (cons re '(2 3 4 0 1)))
28 "Specifications for matching `:::` hints in rustc invocations.
29See `compilation-error-regexp-alist' for help on their format.")
30
31(defvar rustc-refs-compilation-regexps
32 (let ((re "^\\([0-9]+\\)[[:space:]]*|"))
33 (cons re '(nil 1 nil 0 1)))
34 "Specifications for matching code references in rustc invocations.
35See `compilation-error-regexp-alist' for help on their format.")
36
37;; Match test run failures and panics during compilation as
38;; compilation warnings
39(defvar cargo-compilation-regexps
40 '("', \\(\\([^:]+\\):\\([0-9]+\\)\\)"
41 2 3 nil nil 1)
42 "Specifications for matching panics in cargo test invocations.
43See `compilation-error-regexp-alist' for help on their format.")
44
45(defun rustc-scroll-down-after-next-error ()
46 "In the new style error messages, the regular expression
47matches on the file name (which appears after `-->`), but the
48start of the error appears a few lines earlier. This hook runs
49after `next-error' (\\[next-error]); it simply scrolls down a few lines in
50the compilation window until the top of the error is visible."
51 (save-selected-window
52 (when (eq major-mode 'rust-mode)
53 (select-window (get-buffer-window next-error-last-buffer 'visible))
54 (when (save-excursion
55 (beginning-of-line)
56 (looking-at " *-->"))
57 (let ((start-of-error
58 (save-excursion
59 (beginning-of-line)
60 (while (not (looking-at "^[a-z]+:\\|^[a-z]+\\[E[0-9]+\\]:"))
61 (forward-line -1))
62 (point))))
63 (set-window-start (selected-window) start-of-error))))))
64
65(eval-after-load 'compile
66 '(progn
67 (add-to-list 'compilation-error-regexp-alist-alist
68 (cons 'rustc-refs rustc-refs-compilation-regexps))
69 (add-to-list 'compilation-error-regexp-alist 'rustc-refs)
70 (add-to-list 'compilation-error-regexp-alist-alist
71 (cons 'rustc rustc-compilation-regexps))
72 (add-to-list 'compilation-error-regexp-alist 'rustc)
73 (add-to-list 'compilation-error-regexp-alist-alist
74 (cons 'rustc-colon rustc-colon-compilation-regexps))
75 (add-to-list 'compilation-error-regexp-alist 'rustc-colon)
76 (add-to-list 'compilation-error-regexp-alist-alist
77 (cons 'cargo cargo-compilation-regexps))
78 (add-to-list 'compilation-error-regexp-alist 'cargo)
79 (add-hook 'next-error-hook #'rustc-scroll-down-after-next-error)))
80
81;;; _
82(provide 'rust-compile)
83;;; rust-compile.el ends here