• Home
  • Raw
  • Download

Lines Matching +full:build +full:- +full:mode

1 ;;; ninja-mode.el --- Major mode for editing .ninja files -*- lexical-binding: t -*-
3 ;; Package-Requires: ((emacs "24"))
11 ;; http://www.apache.org/licenses/LICENSE-2.0
21 ;; Simple emacs mode for editing .ninja files.
25 (defcustom ninja-indent-offset 2
31 (defconst ninja-keywords-re
32 (concat "^" (regexp-opt '("rule" "build" "subninja" "include" "pool" "default")
35 (defvar ninja-keywords
36 `((,ninja-keywords-re . font-lock-keyword-face)
37 ("^[[:space:]]*\\([[:alnum:]_]+\\)[[:space:]]*=" 1 font-lock-variable-name-face)
39 ("$[[:alnum:]_]+" . font-lock-variable-name-face)
40 ("${[[:alnum:]._]+}" . font-lock-variable-name-face)
42 ("rule +\\([[:alnum:]_.-]+\\)" 1 font-lock-function-name-face)
43 ;; Build Statement - highlight the rule used,
45 ("build +\\(?:[^:$\n]\\|$[:$]\\)+ *: *\\([[:alnum:]_.-]+\\)"
46 1 font-lock-function-name-face)))
48 (defvar ninja-mode-syntax-table
49 (let ((table (make-syntax-table)))
50 (modify-syntax-entry ?\" "." table)
52 "Syntax table used in `ninja-mode'.")
54 (defun ninja-syntax-propertize (start end)
55 (save-match-data
56 (goto-char start)
57 (while (search-forward "#" end t)
58 (let ((match-pos (match-beginning 0)))
60 ;; Is it the first non-white character on the line?
61 (eq match-pos (save-excursion (back-to-indentation) (point)))
62 (save-excursion
63 (goto-char (line-end-position 0))
67 (not (eq ?$ (char-before)))
70 (nth 4 (syntax-ppss)))))
71 (put-text-property match-pos (1+ match-pos) 'syntax-table '(11))
72 (let ((line-end (line-end-position)))
74 ;; Otherwise we get an `args-out-of-range' error.
75 (unless (= line-end (1+ (buffer-size)))
76 (put-text-property line-end (1+ line-end) 'syntax-table '(12)))))))))
78 (defun ninja-compute-indentation ()
80 (save-excursion
81 (beginning-of-line)
82 (if (or (looking-at ninja-keywords-re)
83 (= (line-number-at-pos) 1))
85 (forward-line -1)
86 (if (looking-at ninja-keywords-re)
87 ninja-indent-offset
88 (current-indentation)))))
90 (defun ninja-indent-line ()
92 available or `ninja-indent-offset'"
94 (indent-line-to (ninja-compute-indentation)))
97 (define-derived-mode ninja-mode prog-mode "ninja"
98 (set (make-local-variable 'comment-start) "#")
99 (set (make-local-variable 'parse-sexp-lookup-properties) t)
100 (set (make-local-variable 'syntax-propertize-function) #'ninja-syntax-propertize)
101 (set (make-local-variable 'indent-line-function) 'ninja-indent-line)
102 (setq font-lock-defaults '(ninja-keywords)))
104 ;; Run ninja-mode for files ending in .ninja.
106 (add-to-list 'auto-mode-alist '("\\.ninja$" . ninja-mode))
108 (provide 'ninja-mode)
110 ;;; ninja-mode.el ends here