-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathob-api-mode.el
55 lines (50 loc) · 2.28 KB
/
ob-api-mode.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
;;; ob-api-mode.el --- syntax highlight for ob-api
;; Copyright (C) 2020 Jongseok Choi
;;
;; This code has been derived from ob-http-mode.el
(require 's)
(setq ob-api-mode-keywords
(let* ((ob-api-methods
'(GET POST PUT PATCH DELETE OPTIONS HEAD TRACE CONNECT))
(ob-api-headers
'(Accept Accept-Charset Accept-Encoding Accept-Language
Accept-Datetime Authorization Cache-Control
Connection Cookie Content-Length Content-MD5
Content-Type Date Expect From Host If-Match
If-Modified-Since If-None-Match If-Range
If-Unmodified-Since Max-Forwards Origin Pragma
Proxy-Authorization Range Referer TE User-Agent
Upgrade Via Warning))
(ob-api-methods-regexp
(rx-to-string
`(seq
bol
(? (1+ space))
(group-n 1 (or ,@(mapcar 'symbol-name ob-api-methods)))
space
(group-n 2 (1+ any))
eol)))
(ob-api-headers-regexp
(rx-to-string
`(seq
bol
(? (1+ space))
(group-n 1 (or ,@(mapcar 'symbol-name ob-api-headers)))
": "
(group-n 2 (1+ any))
eol)))
(ob-api-custom-headers-regexp
"\\(^X-[^ :]+\\): \\(.*\\)$")
(ob-api-variable-regexp
"\\([^ ?&=\n]+\\)=\\([^&\n]*\\)")
(ob-api-misc-regexp
"\\(&\\|=\\|?\\|{\\|}\\|\\[\\|\\]\\|\\,\\|:\\)"))
`((,ob-api-headers-regexp (1 font-lock-variable-name-face) (2 font-lock-string-face))
(,ob-api-custom-headers-regexp (1 font-lock-variable-name-face) (2 font-lock-string-face))
(,ob-api-variable-regexp (1 font-lock-variable-name-face) (2 font-lock-string-face))
(,ob-api-methods-regexp (1 font-lock-constant-face) (2 font-lock-function-name-face))
(,ob-api-misc-regexp (1 font-lock-comment-face)))))
(define-derived-mode ob-api-mode fundamental-mode "ob api"
(set (make-local-variable 'font-lock-defaults) '(ob-api-mode-keywords)))
(provide 'ob-api-mode)
;;; ob-api-mode.el ends here