forked from magit/git-modes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitignore-mode.el
More file actions
64 lines (50 loc) · 2.27 KB
/
gitignore-mode.el
File metadata and controls
64 lines (50 loc) · 2.27 KB
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
;;; gitignore-mode.el --- Major mode for editing .gitignore files -*- lexical-binding: t; -*-
;; Copyright (c) 2012-2013 Sebastian Wiesner
;; Author: Sebastian Wiesner <lunaryorn@gmail.com>
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
;; Version: 0.14.0
;; Homepage: https://github.com/magit/git-modes
;; Keywords: convenience vc git
;; This file is not part of GNU Emacs.
;; This file 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, or (at your option)
;; any later version.
;; This file 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 Magit. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; A major mode for editing .gitignore files.
;;; Code:
(require 'rx)
(require 'conf-mode)
(defvar gitignore-mode-font-lock-keywords
`((,(rx line-start (syntax comment-start) (zero-or-more not-newline) line-end)
. 'font-lock-comment-face)
(,(rx line-start (group (optional "!"))) ; Negated patterns
(1 'font-lock-negation-char-face))
("/" . 'font-lock-constant-face) ; Directory separators
(,(rx (or "*" "?")) . 'font-lock-keyword-face) ; Glob patterns
(,(rx "[" (minimal-match (one-or-more not-newline)) "]")
. 'font-lock-keyword-face) ; Ranged glob patterns
))
;;;###autoload
(define-derived-mode gitignore-mode conf-unix-mode "Gitignore"
"A major mode for editing .gitignore files."
(conf-mode-initialize "#")
;; Disable syntactic font locking, because comments are only valid at
;; beginning of line.
(setq font-lock-defaults '(gitignore-mode-font-lock-keywords t t))
(set (make-local-variable 'conf-assignment-sign) nil))
;;;###autoload
(dolist (pattern (list (rx "/.gitignore" string-end)
(rx "/.git/info/exclude" string-end)))
(add-to-list 'auto-mode-alist (cons pattern 'gitignore-mode)))
(provide 'gitignore-mode)
;; Local Variables:
;; indent-tabs-mode: nil
;; End:
;;; gitignore-mode.el ends here