Add highlighting of rule in build statements
[platform/upstream/ninja.git] / misc / ninja-mode.el
1 ;;; ninja-mode.el --- Major mode for editing .ninja files
2
3 ;; Copyright 2011 Google Inc. All Rights Reserved.
4 ;;
5 ;; Licensed under the Apache License, Version 2.0 (the "License");
6 ;; you may not use this file except in compliance with the License.
7 ;; You may obtain a copy of the License at
8 ;;
9 ;;     http://www.apache.org/licenses/LICENSE-2.0
10 ;;
11 ;; Unless required by applicable law or agreed to in writing, software
12 ;; distributed under the License is distributed on an "AS IS" BASIS,
13 ;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ;; See the License for the specific language governing permissions and
15 ;; limitations under the License.
16
17 ;;; Commentary:
18
19 ;; Simple emacs mode for editing .ninja files.
20 ;; Just some syntax highlighting for now.
21
22 ;;; Code:
23
24 (defvar ninja-keywords
25       (list
26        '("^#.*" . font-lock-comment-face)
27        (cons (concat "^" (regexp-opt '("rule" "build" "subninja" "include"
28                                        "pool" "default")
29                                      'words))
30              font-lock-keyword-face)
31        '("\\([[:alnum:]_]+\\) =" . (1 font-lock-variable-name-face))
32        ;; Variable expansion.
33        '("\\($[[:alnum:]_]+\\)" . (1 font-lock-variable-name-face))
34        ;; Rule names
35        '("rule +\\([[:alnum:]_.-]+\\)" . (1 font-lock-function-name-face))
36        ;; Build Statement - highlight the rule used, allow for escaped $,: in outputs
37        '("build +\\(?:[^:$\n]\\|$[:$]\\)+ *: *\\([[:alnum:]_.-]+\\)" .
38          (1 font-lock-function-name-face))
39        
40        ))
41
42 ;;;###autoload       
43 (define-derived-mode ninja-mode fundamental-mode "ninja"
44   (setq comment-start "#")
45   ; Pass extra "t" to turn off syntax-based fontification -- we don't want
46   ; quoted strings highlighted.
47   (setq font-lock-defaults '(ninja-keywords t))
48   )
49
50 ;; Run ninja-mode for files ending in .ninja.
51 ;;;###autoload
52 (add-to-list 'auto-mode-alist '("\\.ninja$" . ninja-mode))
53
54 (provide 'ninja-mode)
55
56 ;;; ninja-mode.el ends here