File: flymake-ats2.el

package info (click to toggle)
ats2-lang 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,064 kB
  • sloc: ansic: 389,637; makefile: 7,123; lisp: 812; sh: 657; php: 573; python: 387; perl: 365
file content (70 lines) | stat: -rw-r--r-- 2,558 bytes parent folder | download | duplicates (5)
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
;; ATS Flymake Mode
;; Detects syntax and type errors and reports their location.
;;
;; Install: add the following to your .emacs
;;
;; (require 'flymake-ats2)
;;
;; The ATSHOME environment variable may need to be set from within emacs:
;;
;; (setenv "ATSHOME" "/path/to/ats2")
;;
;; If you use PATSHOME instead of ATSHOME, please set PATSHOME as follows:
;;
;; (setenv "PATSHOME" "/path/to/ats2")

;;
;; Author: Quackzone
;; The original code was posted by 'Quackzone' to ATS-subreddit (2012)
;; Modified by Brandon Barker and Hongwei Xi
;;

(require 'flymake)

(defvar flymake-ats2-command
  "patscc"
  "Command used to check an ATS2 file for errors")

(defvar flymake-ats2-command-options
  "-tcats"
  "Options passed to the command used to check a file for errors")

(defun flymake-ats2-init ()
  (let* ((temp-file   (flymake-init-create-temp-buffer-copy
                       'flymake-create-temp-inplace))
	 (local-file  (file-relative-name
                       temp-file
                       (file-name-directory buffer-file-name))))
    (list flymake-ats2-command
          (list flymake-ats2-command-options local-file))))

;; List of file extensions that trigger flymake-ats2.
(push '(".+\\.sats$" flymake-ats2-init flymake-simple-cleanup) flymake-allowed-file-name-masks)
(push '(".+\\.dats$" flymake-ats2-init flymake-simple-cleanup) flymake-allowed-file-name-masks)
(push '(".+\\.hats$" flymake-ats2-init flymake-simple-cleanup) flymake-allowed-file-name-masks)

;; Regular expressions for detecting and reporting errors.
(push '("^\\(syntax error\\): *\\([^ ]+\\):.*line=\\([0-9]+\\).*$" 2 3 nil 1)
      flymake-err-line-patterns)
(push '("^\\(.+.dats\\|.+.sats\\|.+.hats\\):.*line=\\([0-9]+\\).*\\(error.+\\)$" 1 2 nil 3)
      flymake-err-line-patterns)

(defun flymake-ats2-load ()
  (flymake-mode t)

  ;; Utility key bindings for navigating errors reported by flymake.
  (local-set-key (kbd "C-c C-d") 'flymake-display-err-menu-for-current-line)
  (local-set-key (kbd "C-c C-n") 'flymake-goto-next-error)
  (local-set-key (kbd "C-c C-p") 'flymake-goto-prev-error)

  ;; Prevents flymake from throwing a configuration error
  ;; This must be done because atsopt returns a non-zero return value
  ;; when it finds an error, flymake expects a zero return value.
  (defadvice flymake-post-syntax-check (before flymake-force-check-was-interrupted)
    (setq flymake-check-was-interrupted t))
  (ad-activate 'flymake-post-syntax-check))

(add-hook 'ats2-mode-hook 'flymake-ats2-load)

(provide 'ats2-flymake)
;;; flymake-ats2.el ends here