-
Notifications
You must be signed in to change notification settings - Fork 5
/
satysfi.el
117 lines (93 loc) · 3.7 KB
/
satysfi.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;;; satysfi.el --- SATySFi -*- lexical-binding: t; -*-
;; Copyright (C) 2017-2018 Takashi SUWA
(provide 'satysfi)
(defface satysfi-inline-command-face
'((t (:foreground "#8888ff")))
"SATySFi inline command")
(defface satysfi-block-command-face
'((t (:foreground "#ff8888")))
"SATySFi block command")
(defface satysfi-var-in-string-face
'((t (:foreground "#44ff88")))
"SATySFi variable in string")
(defface satysfi-escaped-character
'((t (:foreground "#cc88ff")))
"SATySFi escaped character")
(defface satysfi-literal-area
'((t (:foreground "#ffff44")))
"SATySFi literal area")
(defvar satysfi-pdf-viewer-command "open")
(defvar satysfi-command "satysfi -b")
(defun satysfi-mode/insert-pair-scheme (open-string close-string)
(cond ((use-region-p)
(let ((rb (region-beginning)))
(let ((re (region-end)))
(progn
(goto-char rb)
(insert open-string)
(goto-char (+ (length open-string) re))
(insert close-string)
(forward-char -1)))))
(t
(progn
(insert (format "%s%s" open-string close-string))
(forward-char -1)))))
(defun satysfi-mode/insert-paren-pair ()
(interactive)
(satysfi-mode/insert-pair-scheme "(" ")"))
(defun satysfi-mode/insert-brace-pair ()
(interactive)
(satysfi-mode/insert-pair-scheme "{" "}"))
(defun satysfi-mode/insert-square-bracket-pair ()
(interactive)
(satysfi-mode/insert-pair-scheme "[" "]"))
(defun satysfi-mode/insert-angle-bracket-pair ()
(interactive)
(satysfi-mode/insert-pair-scheme "<" ">"))
(defun satysfi-mode/insert-math-brace-pair ()
(interactive)
(satysfi-mode/insert-pair-scheme "${" "}"))
(defun satysfi-mode/open-pdf ()
(interactive)
(let ((pdf-file-path (concat (file-name-sans-extension buffer-file-name) ".pdf")))
(progn
(message "Opening '%s' ..." pdf-file-path)
(async-shell-command (format "%s %s\n" satysfi-pdf-viewer-command pdf-file-path)))))
(defun satysfi-mode/typeset ()
(interactive)
(progn
(message "Typesetting '%s' ..." buffer-file-name)
(async-shell-command (format "%s %s\n" satysfi-command buffer-file-name))))
(defvar satysfi-mode-map (copy-keymap global-map))
(define-key satysfi-mode-map (kbd "(") 'satysfi-mode/insert-paren-pair)
(define-key satysfi-mode-map (kbd "[") 'satysfi-mode/insert-square-bracket-pair)
(define-key satysfi-mode-map (kbd "<") 'satysfi-mode/insert-angle-bracket-pair)
(define-key satysfi-mode-map (kbd "{") 'satysfi-mode/insert-brace-pair)
(define-key satysfi-mode-map (kbd "$") 'satysfi-mode/insert-math-brace-pair)
(define-key satysfi-mode-map (kbd "C-c C-t") 'satysfi-mode/typeset)
(define-key satysfi-mode-map (kbd "C-c C-f") 'satysfi-mode/open-pdf)
;;;###autoload
(define-generic-mode satysfi-mode
'(?%)
'("let" "let-rec" "let-mutable" "let-inline" "let-block" "let-math" "in" "and"
"match" "with" "when" "as" "if" "then" "else" "fun"
"type" "constraint" "val" "direct" "of"
"module" "struct" "sig" "end"
"before" "while" "do"
"controls" "cycle")
'(("\\(\\\\\\(?:\\\\\\\\\\)*\\([a-zA-Z0-9\\-]+\\.\\)*[a-zA-Z0-9\\-]+\\)\\>"
(1 'satysfi-inline-command-face t))
("\\(\\+\\([a-zA-Z0-9\\-]+\\.\\)*[a-zA-Z0-9\\-]+\\)\\>"
(1 'satysfi-block-command-face t))
("\\(@[a-z][0-9A-Za-z\\-]*\\)\\>"
(1 'satysfi-var-in-string-face t))
("\\(\\\\\\(?:@\\|`\\|\\*\\| \\|%\\||\\|;\\|{\\|}\\|<\\|>\\|\\$\\|#\\|\\\\\\)\\)"
(1 'satysfi-escaped-character t))
; ("\\(`\\(?:[^`]\\|\\n\\)+`\\)" (1 'satysfi-literal-area t))
)
nil
'((lambda () (use-local-map satysfi-mode-map))))
;;;###autoload
(add-to-list 'auto-mode-alist
'("\\.\\(saty\\|satyh\\)\\'"
. satysfi-mode))