-
Notifications
You must be signed in to change notification settings - Fork 0
/
flymake-pug.el
55 lines (49 loc) · 2.24 KB
/
flymake-pug.el
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
;;; flymake-pug.el --- Flymake backend for Pug using pug-lint -*- lexical-binding: t; -*-
(require 'flymake)
(defgroup flymake-pug nil
"Flymake backend for pug using pug-lint."
:group 'flymake)
(defvar-local flymake-pug--proc nil)
(defun flymake-pug (report-fn &rest _args)
"Make pug-lint process."
(unless (executable-find
"pug-lint") (error "Cannot find a suitable pug-lint"))
(when (process-live-p flymake-pug--proc)
(kill-process flymake-pug--proc))
(let ((source (current-buffer)))
(save-restriction
(widen)
(setq flymake-pug--proc
(make-process
:name "pug-flymake" :noquery t :connection-type 'pipe
:buffer (generate-new-buffer " *Flymake-Pug*")
:command (list "pug-lint" (buffer-file-name source))
:sentinel
(lambda (proc _event)
(when (eq 'exit (process-status proc))
(unwind-protect
(if (with-current-buffer source (eq proc flymake-pug--proc))
(with-current-buffer (process-buffer proc)
(goto-char (point-min))
(cl-loop
while (search-forward-regexp
"\\(.*.pug\\):\\([0-9]+\\):[0-9]+\\(.*\n\\)+\n\\(.*\\)"
nil t)
for msg = (match-string 4)
for (beg . end) = (flymake-diag-region
source
(string-to-number (match-string 2)))
for type = :warning
collect (flymake-make-diagnostic source beg end type msg)
into diags
finally (funcall report-fn diags)))
(flymake-log :warning "Canceling obsolete check %s" proc))
(kill-buffer (process-buffer proc))))))))))
;;;###autoload
(defun flymake-pug-turn-on ()
"Enable `flymake-pug' as buffer-local Flymake backend."
(interactive)
(flymake-mode 1)
(add-hook 'flymake-diagnostic-functions 'flymake-pug nil t))
(provide 'flymake-pug)
;;; flymake-pug.el ends here