blob: b148c5538f3dc4e4291e070d74bfd98991f7f5bf (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
;;; flymake-rust.el --- A flymake handler for rust-mode files
;;
;;; Author: Joao Oliveira <joaoxsouls@gmail.com>
;;; URL: https://github.com/joaoxsouls/flymake-rust
;; Package-Version: 20170729.2139
;; Package-Commit: 2f42d1f2dad73ec9de460eda6176e3ab25c446f0
;;; Version: DEV
;;; Package-Requires: ((flymake-easy "0.1"))
;; This file 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, or (at your option)
;; any later version.
;; This file 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 <http://www.gnu.org/licenses/>.;;;
;;; Commentary:
;; Usage:
;; (require 'flymake-rust)
;; (add-hook 'rust-mode-hook 'flymake-rust-load)
;;
;; If you want to use rustc compiler, you must add following string:
;; (setq flymake-rust-use-cargo 1)
;;
;; Uses flymake-easy, from https://github.com/purcell/flymake-easy
;;; Code:
(require 'flymake-easy)
(defconst flymake-rust-err-line-patterns
'(("^\\(.*\\)\n --> \\(.*.rs\\):\\([0-9]+\\):\\([0-9]+\\)$" 2 3 4 1)
("^\\(.*.rs\\):\\([0-9]+\\):[0-9]+: [0-9]+:[0-9]+ [a-z]+: \\(.*\\)$" 1 2 nil 3)
("^\\(.*.rs\\):\\([0-9]+\\) \\(.*\\)$" 1 2 nil 3)))
(setq-default flymake-rust-use-cargo 1)
(if flymake-rust-use-cargo
(defvar flymake-rust-executable "cargo"
"The rust executable to use for syntax checking.")
(defvar flymake-rust-executable "rustc"
"The rust executable to use for syntax checking.")
)
;; Invoke rust "--parse-only" to get syntax checking
(defun flymake-rust-command (filename)
"Construct a command that flymake can use to check rust source."
(if flymake-rust-use-cargo
(list flymake-rust-executable "build")
(list flymake-rust-executable "--no-trans" filename)
)
)
;; Load rust-flymake
(defun flymake-rust-load ()
"Configure flymake mode to check the current buffer's rust syntax."
(interactive)
(flymake-easy-load 'flymake-rust-command
flymake-rust-err-line-patterns
'inplace
"rs"))
(provide 'flymake-rust)
;;; flymake-rust.el ends here
|