summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Chalmer <micah@micahchalmer.net>2016-05-06 00:30:07 -0400
committerMicah Chalmer <micah@micahchalmer.net>2016-05-06 00:30:07 -0400
commit4fce17848d7df44ea5a722577dbf69cccf39878b (patch)
treefad92d963bccbd1a31184e6181f635ea9a6251d0
parentb23efef0b6a6a632b70c1db5579a835059239e4c (diff)
parent40c33fd71d87e10776d86f15f35c4fb2a2202879 (diff)
downloadrust-mode-4fce17848d7df44ea5a722577dbf69cccf39878b.tar.gz
Merge pull request #154 from nikomatsakis/new-errors
add code to handle new-style rustc errors
-rw-r--r--rust-mode.el34
1 files changed, 34 insertions, 0 deletions
diff --git a/rust-mode.el b/rust-mode.el
index df7e93c..b0f8379 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -1381,6 +1381,16 @@ This is written mainly to be used as `end-of-defun-function' for Rust."
"Specifications for matching errors in rustc invocations.
See `compilation-error-regexp-alist' for help on their format.")
+(defvar rustc-new-compilation-regexps
+ (let ((file "\\([^\n]+\\)")
+ (start-line "\\([0-9]+\\)")
+ (start-col "\\([0-9]+\\)"))
+ (let ((re (concat "^ *--> " file ":" start-line ":" start-col ; --> 1:2:3
+ )))
+ (cons re '(1 2 3))))
+ "Specifications for matching errors in rustc invocations (new style).
+See `compilation-error-regexp-alist' for help on their format.")
+
;; Match test run failures and panics during compilation as
;; compilation warnings
(defvar cargo-compilation-regexps
@@ -1388,9 +1398,33 @@ See `compilation-error-regexp-alist' for help on their format.")
"Specifications for matching panics in cargo test invocations.
See `compilation-error-regexp-alist' for help on their format.")
+(defun rustc-scroll-down-after-next-error ()
+ "In the new style error messages, the regular expression
+ matches on the file name (which appears after `-->`), but the
+ start of the error appears a few lines earlier. This hook runs
+ after `M-x next-error`; it simply scrolls down a few lines in
+ the compilation window until the top of the error is visible."
+ (save-selected-window
+ (when (eq major-mode 'rust-mode)
+ (select-window (get-buffer-window next-error-last-buffer))
+ (when (save-excursion
+ (beginning-of-line)
+ (looking-at " *-->"))
+ (let ((start-of-error
+ (save-excursion
+ (beginning-of-line)
+ (while (not (looking-at "^[a-z]+:"))
+ (forward-line -1))
+ (point))))
+ (set-window-start (selected-window) start-of-error))))))
+
(eval-after-load 'compile
'(progn
(add-to-list 'compilation-error-regexp-alist-alist
+ (cons 'rustc-new rustc-new-compilation-regexps))
+ (add-to-list 'compilation-error-regexp-alist 'rustc-new)
+ (add-hook 'next-error-hook 'rustc-scroll-down-after-next-error)
+ (add-to-list 'compilation-error-regexp-alist-alist
(cons 'rustc rustc-compilation-regexps))
(add-to-list 'compilation-error-regexp-alist 'rustc)
(add-to-list 'compilation-error-regexp-alist-alist