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)))) |
gavinp
2014/09/25 20:07:33
Why this change? I say we just lose python-continu
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Because I found out python-continutation-offset is
| |
27 | |
28 (defun gyp-indent-guess-indent-offset () | |
gavinp
2014/09/25 20:07:33
Maybe:
(defadvice python-indent-guess-indent-offs
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
29 "Guess correct indent offset in gyp-mode." | |
30 (interactive) | |
gavinp
2014/09/25 20:07:33
Really?
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
It's in python.el, this code is largely based arou
| |
31 (save-excursion | |
32 (save-restriction | |
33 (widen) | |
34 (goto-char (point-min)) | |
35 (let ((indentation)) | |
gavinp
2014/09/25 20:07:32
I found this logic hard to follow. How about this
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
36 ;; Find first line ending with an opening bracket | |
gavinp
2014/09/25 20:07:33
Nit: I think "brace" is a better word to use here.
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
37 ;; that is not a comment. | |
gavinp
2014/09/25 20:07:33
Nit: this comment fits on one line.
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
38 (when (re-search-forward "\\(^[[{]$\\|^.*[^#].*[[{]$\\)" nil nil) | |
gavinp
2014/09/25 20:07:33
Nit: don't provide default values to &optional arg
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
39 (next-line 1) | |
gavinp
2014/09/25 20:07:33
Nit: Don't use next-line https://www.gnu.org/softw
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
40 (setq indentation (current-indentation))) | |
gavinp
2014/09/25 20:07:33
Nit: Avoid side effects. See https://engdoc.corp.g
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
41 (if (and indentation (not (zerop indentation))) | |
gavinp
2014/09/25 20:07:33
Nit: Don't use IF when one of the clauses would be
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
42 (progn | |
43 (set (make-local-variable 'python-indent-offset) indentation) | |
44 (set (make-local-variable 'python-continuation-offset) indentation )) | |
45 (message "Can't guess gyp indent offset, using defaults: %s" | |
gavinp
2014/09/25 20:07:33
Nit, grammar: defaults --> default, right?
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
46 python-indent-offset)))))) | |
gavinp
2014/09/25 20:07:33
Nit: This can go on the previous line.
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
27 | 47 |
28 (define-derived-mode gyp-mode python-mode "Gyp" | 48 (define-derived-mode gyp-mode python-mode "Gyp" |
29 "Major mode for editing .gyp files. See http://code.google.com/p/gyp/" | 49 "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, | 50 ;; gyp-parse-history is a stack of (POSITION . PARSE-STATE) tuples, |
31 ;; with greater positions at the top of the stack. PARSE-STATE | 51 ;; 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) | 52 ;; 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. | 53 ;; with most nested section symbol at the front of the list. |
34 (set (make-local-variable 'gyp-parse-history) '((1 . (list)))) | 54 (set (make-local-variable 'gyp-parse-history) '((1 . (list)))) |
35 (gyp-add-font-lock-keywords)) | 55 (gyp-add-font-lock-keywords)) |
36 | 56 |
37 (defun gyp-set-indentation () | 57 (defun gyp-set-indentation () |
38 "Hook function to configure python indentation to suit gyp mode." | 58 "Hook function to configure python indentation to suit gyp mode." |
39 (setq python-continuation-offset 2 | 59 (setq python-continuation-offset 2 |
40 python-indent-offset 2 | 60 python-indent-offset 2 |
gavinp
2014/09/25 20:07:32
I'm alarmed. Either you don't need to use make-loc
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
These are wrong.
| |
41 python-indent-guess-indent-offset nil)) | 61 python-indent-guess-indent-offset nil) |
gavinp
2014/09/25 20:07:33
Since our code basically duplicates python-indent-
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Done.
| |
62 (gyp-indent-guess-indent-offset)) | |
42 | 63 |
43 (add-hook 'gyp-mode-hook 'gyp-set-indentation) | 64 (add-hook 'gyp-mode-hook 'gyp-set-indentation) |
44 | 65 |
45 (add-to-list 'auto-mode-alist '("\\.gyp\\'" . gyp-mode)) | 66 (add-to-list 'auto-mode-alist '("\\.gyp\\'" . gyp-mode)) |
46 (add-to-list 'auto-mode-alist '("\\.gypi\\'" . gyp-mode)) | 67 (add-to-list 'auto-mode-alist '("\\.gypi\\'" . gyp-mode)) |
47 (add-to-list 'auto-mode-alist '("/\\.gclient\\'" . gyp-mode)) | 68 (add-to-list 'auto-mode-alist '("/\\.gclient\\'" . gyp-mode)) |
48 | 69 |
49 ;;; Font-lock support | 70 ;;; Font-lock support |
50 | 71 |
51 (defconst gyp-dependencies-regexp | 72 (defconst gyp-dependencies-regexp |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 (font-lock-add-keywords | 237 (font-lock-add-keywords |
217 nil | 238 nil |
218 (list | 239 (list |
219 ;; Top-level keywords | 240 ;; Top-level keywords |
220 (list (concat "['\"]\\(" | 241 (list (concat "['\"]\\(" |
221 (regexp-opt (list "action" "action_name" "actions" "cflags" | 242 (regexp-opt (list "action" "action_name" "actions" "cflags" |
222 "cflags_cc" "conditions" "configurations" | 243 "cflags_cc" "conditions" "configurations" |
223 "copies" "defines" "dependencies" "destination" | 244 "copies" "defines" "dependencies" "destination" |
224 "direct_dependent_settings" | 245 "direct_dependent_settings" |
225 "export_dependent_settings" "extension" "files" | 246 "export_dependent_settings" "extension" "files" |
226 "include_dirs" "includes" "inputs" "libraries" | 247 "include_dirs" "includes" "inputs" "ldflags" |
gavinp
2014/09/25 20:07:33
This is just adding "ldflags", no other changes, r
Fabrice (no longer in Chrome)
2014/09/26 12:23:37
Yes just ldflags. My OCD compelled me to set every
| |
227 "link_settings" "mac_bundle" "message" | 248 "libraries" "link_settings" "mac_bundle" |
228 "msvs_external_rule" "outputs" "product_name" | 249 "message" "msvs_external_rule" "outputs" |
229 "process_outputs_as_sources" "rules" "rule_name" | 250 "product_name" "process_outputs_as_sources" |
230 "sources" "suppress_wildcard" | 251 "rules" "rule_name" "sources" |
231 "target_conditions" "target_defaults" | 252 "suppress_wildcard" "target_conditions" |
232 "target_defines" "target_name" "toolsets" | 253 "target_defaults" "target_defines" |
233 "targets" "type" "variables" "xcode_settings")) | 254 "target_name" "toolsets" "targets" "type" |
255 "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 |