1 ;;; ninja-mode.el --- Major mode for editing .ninja files
3 ;; Copyright 2011 Google Inc. All Rights Reserved.
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
9 ;; http://www.apache.org/licenses/LICENSE-2.0
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.
19 ;; Simple emacs mode for editing .ninja files.
20 ;; Just some syntax highlighting for now.
24 (defvar ninja-keywords
26 '("^#.*" . font-lock-comment-face)
27 (cons (concat "^" (regexp-opt '("rule" "build" "subninja" "include"
30 font-lock-keyword-face)
31 '("\\([[:alnum:]_]+\\) =" . (1 font-lock-variable-name-face))
32 ;; Variable expansion.
33 '("\\($[[:alnum:]_]+\\)" . (1 font-lock-variable-name-face))
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))
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))
50 ;; Run ninja-mode for files ending in .ninja.
52 (add-to-list 'auto-mode-alist '("\\.ninja$" . ninja-mode))
56 ;;; ninja-mode.el ends here