Skip to content

Instantly share code, notes, and snippets.

@brianloveswords
Last active December 19, 2015 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianloveswords/216ec67c6d3f2b567b2c to your computer and use it in GitHub Desktop.
Save brianloveswords/216ec67c6d3f2b567b2c to your computer and use it in GitHub Desktop.
(require 'flycheck)
(flycheck-define-checker cargo-rust
"A Rust syntax checker using cargo rustc.
This syntax checker needs Rust 1.1 or newer.
See URL `http://www.rust-lang.org'."
:command ("cargo" "rustc"
"--lib"
"--" "-Z" "no-trans"
"--test")
:error-patterns
((error line-start (file-name) ":" line ":" column ": "
(one-or-more digit) ":" (one-or-more digit) " error: "
(or
;; Multiline errors
(and (message (minimal-match (one-or-more anything)))
" [" (id "E" (one-or-more digit)) "]")
(message))
line-end)
(warning line-start (file-name) ":" line ":" column ": "
(one-or-more digit) ":" (one-or-more digit) " warning: "
(message) line-end)
(info line-start (file-name) ":" line ":" column ": "
(one-or-more digit) ":" (one-or-more digit) " " (or "note" "help") ": "
(message) line-end))
:modes rust-mode
:predicate (lambda ()
(flycheck-buffer-saved-p)))
(add-to-list 'flycheck-checkers 'cargo-rust)
(defun my-next-error-wrapped (&optional arg reset)
"Jumps to previous error if at first error jump to last error instead.
Prefix argument ARG says how many error messages to move forwards (or
backwards, if negative). With just C-u as prefix moves to first error"
(interactive "P")
(condition-case nil
(call-interactively 'next-error)
('user-error (next-error 1 t))))
(defun my-jump-to-last-error (buffer)
"Jump to last error in the BUFFER, this assumes that
the error is at last but third line"
(save-selected-window
(select-window (get-buffer-window buffer))
(goto-char (point-max))
(forward-line -3)
(call-interactively 'compile-goto-error)))
(defun my-previous-error-wrapped (&optional arg)
"Jumps to previous error if at first error jump to last error instead.
Prefix argument ARG says how many error messages to move backwards (or
forwards, if negative)."
(interactive "P")
(condition-case nil
(if (compilation-buffer-p (current-buffer))
(compilation-previous-error 1)
(call-interactively 'previous-error))
('user-error (progn
(let ((error-buffer (next-error-find-buffer)))
;; If the buffer has an associated error buffer use it to
;; to move to last error
(if (and (not (eq (current-buffer) error-buffer))
(compilation-buffer-p error-buffer))
(my-jump-to-last-error error-buffer)
;; Otherwise move to last point and invoke previous error
(goto-char (point-max))
(call-interactively 'previous-error)))))))
(define-key prog-mode-map (kbd "C-c C-n") 'my-next-error-wrapped)
(define-key prog-mode-map (kbd "C-c C-p") 'my-previous-error-wrapped)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment