-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathob-http-mode.el
66 lines (58 loc) · 2.87 KB
/
ob-http-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
56
57
58
59
60
61
62
63
64
65
66
;;; ob-http-mode.el --- syntax highlight for ob-http
;; Copyright (C) 2015 Feng Zhou
;; This program 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 of the License, or
;; (at your option) any later version.
;; This program 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/>.
(require 's)
(setq ob-http-mode-keywords
(let* ((ob-http-methods
'(GET POST PUT PATCH DELETE OPTIONS HEAD TRACE CONNECT))
(ob-http-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-http-methods-regexp
(rx-to-string
`(seq
bol
(? (1+ space))
(group-n 1 (or ,@(mapcar 'symbol-name ob-http-methods)))
space
(group-n 2 (1+ any))
eol)))
(ob-http-headers-regexp
(rx-to-string
`(seq
bol
(? (1+ space))
(group-n 1 (or ,@(mapcar 'symbol-name ob-http-headers)))
": "
(group-n 2 (1+ any))
eol)))
(ob-http-custom-headers-regexp
"\\(^X-[^ :]+\\): \\(.*\\)$")
(ob-http-variable-regexp
"\\([^ ?&=\n]+\\)=\\([^&\n]*\\)")
(ob-http-misc-regexp
"\\(&\\|=\\|?\\|{\\|}\\|\\[\\|\\]\\|\\,\\|:\\)"))
`((,ob-http-headers-regexp (1 font-lock-variable-name-face) (2 font-lock-string-face))
(,ob-http-custom-headers-regexp (1 font-lock-variable-name-face) (2 font-lock-string-face))
(,ob-http-variable-regexp (1 font-lock-variable-name-face) (2 font-lock-string-face))
(,ob-http-methods-regexp (1 font-lock-constant-face) (2 font-lock-function-name-face))
(,ob-http-misc-regexp (1 font-lock-comment-face)))))
(define-derived-mode ob-http-mode fundamental-mode "ob http"
(set (make-local-variable 'font-lock-defaults) '(ob-http-mode-keywords)))
(provide 'ob-http-mode)
;;; ob-http-mode.el ends here