OLD | NEW |
1 ;;; gyp.el - font-lock-mode support for gyp files. | 1 ;;; gyp.el - font-lock-mode support for gyp files. |
2 | 2 |
3 ;; Copyright (c) 2012 Google Inc. All rights reserved. | 3 ;; Copyright (c) 2012 Google Inc. All rights reserved. |
4 ;; Use of this source code is governed by a BSD-style license that can be | 4 ;; Use of this source code is governed by a BSD-style license that can be |
5 ;; found in the LICENSE file. | 5 ;; found in the LICENSE file. |
6 | 6 |
7 ;; Put this somewhere in your load-path and | 7 ;; Put this somewhere in your load-path and |
8 ;; (require 'gyp) | 8 ;; (require 'gyp) |
9 | 9 |
10 (require 'python) | 10 (require 'python) |
11 (require 'cl) | 11 (require 'cl) |
12 | 12 |
13 (when (string-match "python-mode.el" (symbol-file 'python-mode 'defun)) | 13 (when (string-match "python-mode.el" (symbol-file 'python-mode 'defun)) |
14 (error (concat "python-mode must be loaded from python.el (bundled with " | 14 (error (concat "python-mode must be loaded from python.el (bundled with " |
15 "recent emacsen), not from the older and less maintained " | 15 "recent emacsen), not from the older and less maintained " |
16 "python-mode.el"))) | 16 "python-mode.el"))) |
17 | 17 |
18 (defadvice python-indent-calculate-levels (after gyp-outdent-closing-parens | 18 (defadvice python-indent-calculate-levels (after gyp-outdent-closing-parens |
19 activate) | 19 activate) |
20 "De-indent closing parens, braces, and brackets in gyp-mode." | 20 "De-indent closing parens, braces, and brackets in gyp-mode." |
21 (when (and (eq major-mode 'gyp-mode) | 21 (when (and (eq major-mode 'gyp-mode) |
22 (string-match "^ *[])}][],)}]* *$" | 22 (string-match "^ *[])}][],)}]* *$" |
23 (buffer-substring-no-properties | 23 (buffer-substring-no-properties |
24 (line-beginning-position) (line-end-position)))) | 24 (line-beginning-position) (line-end-position)))) |
25 (setf (first python-indent-levels) | 25 (setf (first python-indent-levels) |
26 (- (first python-indent-levels) python-indent-offset)))) | 26 (- (first python-indent-levels) python-continuation-offset)))) |
| 27 |
| 28 (defadvice python-indent-guess-indent-offset (around |
| 29 gyp-indent-guess-indent-offset |
| 30 activate) |
| 31 "Guess correct indent offset in gyp-mode." |
| 32 (or (and (not (eq major-mode 'gyp-mode)) |
| 33 ad-do-it) |
| 34 (save-excursion |
| 35 (save-restriction |
| 36 (widen) |
| 37 (goto-char (point-min)) |
| 38 ;; Find first line ending with an opening brace that is not a comment. |
| 39 (or (and (re-search-forward "\\(^[[{]$\\|^.*[^#].*[[{]$\\)") |
| 40 (forward-line) |
| 41 (/= (current-indentation) 0) |
| 42 (set (make-local-variable 'python-indent-offset) |
| 43 (current-indentation)) |
| 44 (set (make-local-variable 'python-continuation-offset) |
| 45 (current-indentation))) |
| 46 (message "Can't guess gyp indent offset, using default: %s" |
| 47 python-continuation-offset)))))) |
27 | 48 |
28 (define-derived-mode gyp-mode python-mode "Gyp" | 49 (define-derived-mode gyp-mode python-mode "Gyp" |
29 "Major mode for editing .gyp files. See http://code.google.com/p/gyp/" | 50 "Major mode for editing .gyp files. See http://code.google.com/p/gyp/" |
30 ;; gyp-parse-history is a stack of (POSITION . PARSE-STATE) tuples, | 51 ;; gyp-parse-history is a stack of (POSITION . PARSE-STATE) tuples, |
31 ;; with greater positions at the top of the stack. PARSE-STATE | 52 ;; with greater positions at the top of the stack. PARSE-STATE |
32 ;; is a list of section symbols (see gyp-section-name and gyp-parse-to) | 53 ;; is a list of section symbols (see gyp-section-name and gyp-parse-to) |
33 ;; with most nested section symbol at the front of the list. | 54 ;; with most nested section symbol at the front of the list. |
34 (set (make-local-variable 'gyp-parse-history) '((1 . (list)))) | 55 (set (make-local-variable 'gyp-parse-history) '((1 . (list)))) |
35 (gyp-add-font-lock-keywords)) | 56 (gyp-add-font-lock-keywords)) |
36 | 57 |
37 (defun gyp-set-indentation () | 58 (defun gyp-set-indentation () |
38 "Hook function to configure python indentation to suit gyp mode." | 59 "Hook function to configure python indentation to suit gyp mode." |
39 (setq python-continuation-offset 2 | 60 (set (make-local-variable 'python-indent-offset) 2) |
40 python-indent-offset 2 | 61 (set (make-local-variable 'python-continuation-offset) 2) |
41 python-indent-guess-indent-offset nil)) | 62 (set (make-local-variable 'python-indent-guess-indent-offset) t) |
| 63 (python-indent-guess-indent-offset)) |
42 | 64 |
43 (add-hook 'gyp-mode-hook 'gyp-set-indentation) | 65 (add-hook 'gyp-mode-hook 'gyp-set-indentation) |
44 | 66 |
45 (add-to-list 'auto-mode-alist '("\\.gyp\\'" . gyp-mode)) | 67 (add-to-list 'auto-mode-alist '("\\.gyp\\'" . gyp-mode)) |
46 (add-to-list 'auto-mode-alist '("\\.gypi\\'" . gyp-mode)) | 68 (add-to-list 'auto-mode-alist '("\\.gypi\\'" . gyp-mode)) |
47 (add-to-list 'auto-mode-alist '("/\\.gclient\\'" . gyp-mode)) | 69 (add-to-list 'auto-mode-alist '("/\\.gclient\\'" . gyp-mode)) |
48 | 70 |
49 ;;; Font-lock support | 71 ;;; Font-lock support |
50 | 72 |
51 (defconst gyp-dependencies-regexp | 73 (defconst gyp-dependencies-regexp |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 (font-lock-add-keywords | 238 (font-lock-add-keywords |
217 nil | 239 nil |
218 (list | 240 (list |
219 ;; Top-level keywords | 241 ;; Top-level keywords |
220 (list (concat "['\"]\\(" | 242 (list (concat "['\"]\\(" |
221 (regexp-opt (list "action" "action_name" "actions" "cflags" | 243 (regexp-opt (list "action" "action_name" "actions" "cflags" |
222 "cflags_cc" "conditions" "configurations" | 244 "cflags_cc" "conditions" "configurations" |
223 "copies" "defines" "dependencies" "destination" | 245 "copies" "defines" "dependencies" "destination" |
224 "direct_dependent_settings" | 246 "direct_dependent_settings" |
225 "export_dependent_settings" "extension" "files" | 247 "export_dependent_settings" "extension" "files" |
226 "include_dirs" "includes" "inputs" "libraries" | 248 "include_dirs" "includes" "inputs" "ldflags" "li
braries" |
227 "link_settings" "mac_bundle" "message" | 249 "link_settings" "mac_bundle" "message" |
228 "msvs_external_rule" "outputs" "product_name" | 250 "msvs_external_rule" "outputs" "product_name" |
229 "process_outputs_as_sources" "rules" "rule_name" | 251 "process_outputs_as_sources" "rules" "rule_name" |
230 "sources" "suppress_wildcard" | 252 "sources" "suppress_wildcard" |
231 "target_conditions" "target_defaults" | 253 "target_conditions" "target_defaults" |
232 "target_defines" "target_name" "toolsets" | 254 "target_defines" "target_name" "toolsets" |
233 "targets" "type" "variables" "xcode_settings")) | 255 "targets" "type" "variables" "xcode_settings")) |
234 "[!/+=]?\\)") 1 'font-lock-keyword-face t) | 256 "[!/+=]?\\)") 1 'font-lock-keyword-face t) |
235 ;; Type of target | 257 ;; Type of target |
236 (list (concat "['\"]\\(" | 258 (list (concat "['\"]\\(" |
237 (regexp-opt (list "loadable_module" "static_library" | 259 (regexp-opt (list "loadable_module" "static_library" |
238 "shared_library" "executable" "none")) | 260 "shared_library" "executable" "none")) |
239 "\\)") 1 'font-lock-type-face t) | 261 "\\)") 1 'font-lock-type-face t) |
240 (list "\\(?:target\\|action\\)_name['\"]\\s-*:\\s-*['\"]\\([^ '\"]*\\)" 1 | 262 (list "\\(?:target\\|action\\)_name['\"]\\s-*:\\s-*['\"]\\([^ '\"]*\\)" 1 |
241 'font-lock-function-name-face t) | 263 'font-lock-function-name-face t) |
242 (list 'gyp-section-match | 264 (list 'gyp-section-match |
243 (list 1 'font-lock-function-name-face t t) ; dependencies | 265 (list 1 'font-lock-function-name-face t t) ; dependencies |
244 (list 2 'font-lock-variable-name-face t t) ; variables, conditions | 266 (list 2 'font-lock-variable-name-face t t) ; variables, conditions |
245 (list 3 'font-lock-constant-face t t) ; sources | 267 (list 3 'font-lock-constant-face t t) ; sources |
246 (list 4 'font-lock-preprocessor-face t t)) ; preprocessor | 268 (list 4 'font-lock-preprocessor-face t t)) ; preprocessor |
247 ;; Variable expansion | 269 ;; Variable expansion |
248 (list "<@?(\\([^\n )]+\\))" 1 'font-lock-variable-name-face t) | 270 (list "<@?(\\([^\n )]+\\))" 1 'font-lock-variable-name-face t) |
249 ;; Command expansion | 271 ;; Command expansion |
250 (list "<!@?(\\([^\n )]+\\))" 1 'font-lock-variable-name-face t) | 272 (list "<!@?(\\([^\n )]+\\))" 1 'font-lock-variable-name-face t) |
251 ))) | 273 ))) |
252 | 274 |
253 (provide 'gyp) | 275 (provide 'gyp) |
OLD | NEW |