-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrobots-txt-mode.el
87 lines (72 loc) · 2.58 KB
/
robots-txt-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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;;; robots-txt-mode.el --- Major mode for editing robots.txt
;; Copyright (C) 2018 Friends of Emacs-PHP development
;; Author: USAMI Kenta <[email protected]>
;; Created: 9 Mar 2016
;; Version: 0.0.9
;; Keywords: languages, comm, web
;; URL: https://github.com/emacs-php/robots-txt-mode
;; This file is NOT part of GNU Emacs.
;; 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/>.
;;; Commentary:
;; This is a major-mode for editing `robots.txt'.
;;; Code:
(defvar robots-txt-mode-directives
'("Allow" ; Google
"Disallow" ; Standard
"Sitemap")
"Directive keywords for robots.")
(defvar robots-txt-mode-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?. "_" table)
(modify-syntax-entry ?/ "_" table)
(modify-syntax-entry ?: "." table)
(modify-syntax-entry ?? "_" table)
(modify-syntax-entry ?\n ">" table)
(modify-syntax-entry ?_ "_" table)
table))
(defconst robots-txt-mode-syntax-keywords
(list
(cons
(concat
"^[ \t]*\\(User-agent[ \t]*:\\)"
"[ \t]*"
"\\(\\*\\|[a-zA-Z_-]*\\)"
"[ \t]*"
"\\(.*\\)")
'((1 font-lock-keyword-face)
(2 font-lock-function-name-face)
(3 font-lock-warning-face)))
(cons ; Directive
(concat
"^[ \t]*\\(" (regexp-opt robots-txt-mode-directives) "[ \t]*:\\)"
"[ \t]*"
"\\(.+\\)")
'((1 font-lock-type-face)
(2 font-lock-string-face)))
(cons ; Non standard directive
(concat
"^[ \t]*\\(\\(?:[-a-zA-Z]\\)+[ \t]*:\\)"
"[ \t]*"
"\\(.+\\)")
'((1 font-lock-builtin-face)
(2 font-lock-string-face)))))
;;;###autoload
(define-derived-mode robots-txt-mode prog-mode "[o_-]"
"Major mode for editing `robots.txt'"
:syntax-table robots-txt-mode-syntax-table
(setq comment-start "# ")
(setq font-lock-defaults '(robots-txt-mode-syntax-keywords nil t)))
;;;###autoload
(add-to-list 'auto-mode-alist '("/robots\\.txt\\'" . robots-txt-mode))
(provide 'robots-txt-mode)
;;; robots-txt-mode.el ends here