Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 ;; Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 ;; Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 ;; Use of this source code is governed by a BSD-style license that can be | 2 ;; Use of this source code is governed by a BSD-style license that can be |
| 3 ;; found in the LICENSE file. | 3 ;; found in the LICENSE file. |
| 4 | 4 |
| 5 ;; Set up flymake for use with chromium code. Uses ninja (since none of the | 5 ;; Set up flymake for use with chromium code. Uses ninja (since none of the |
| 6 ;; other chromium build systems have latency that allows interactive use). | 6 ;; other chromium build systems have latency that allows interactive use). |
| 7 ;; | 7 ;; |
| 8 ;; Requires a modern emacs (GNU Emacs >= 23) and that gyp has already generated | 8 ;; Requires a modern emacs (GNU Emacs >= 23) and that gyp has already generated |
| 9 ;; the build.ninja file(s). See defcustoms below for settable knobs. | 9 ;; the build.ninja file(s). See defcustoms below for settable knobs. |
| 10 | 10 |
| 11 | 11 |
| 12 (require 'flymake) | 12 (require 'flymake) |
| 13 | 13 |
| 14 (defcustom cr-flymake-ninja-build-file "out/Debug/build.ninja" | 14 (defcustom cr-flymake-ninja-build-file "out/Debug/build.ninja" |
| 15 "Relative path from chromium's src/ directory to the | 15 "Relative path from chromium's src/ directory to the |
| 16 build.ninja file to use.") | 16 build.ninja file to use.") |
| 17 | 17 |
| 18 (defcustom cr-flymake-ninja-executable "ninja" | 18 (defcustom cr-flymake-ninja-executable "ninja" |
| 19 "Ninja executable location; either in $PATH or explicitly given.") | 19 "Ninja executable location; either in $PATH or explicitly given.") |
| 20 | 20 |
| 21 (defun cr-flymake-absbufferpath () | |
| 22 "Return the absolute path to the current buffer. On some | |
| 23 Emacsen, buffer-file-truename is not absolute but rather uses a | |
|
Ami GONE FROM CHROMIUM
2011/12/08 16:17:01
I believe this behavior is in fact the case for al
Ami GONE FROM CHROMIUM
2011/12/08 19:27:49
Remove the second sentence of the docstring.
Jói
2011/12/08 20:46:16
Done.
| |
| 24 path relative to the user's home dir (with ~)." | |
| 25 (when buffer-file-truename | |
| 26 (expand-file-name buffer-file-truename))) | |
| 27 | |
| 21 (defun cr-flymake-chromium-src () | 28 (defun cr-flymake-chromium-src () |
| 22 "Return chromium's src/ directory, or nil on failure." | 29 "Return chromium's src/ directory, or nil on failure." |
| 23 (locate-dominating-file buffer-file-truename cr-flymake-ninja-build-file)) | 30 (let ((srcdir (locate-dominating-file |
| 31 (cr-flymake-absbufferpath) cr-flymake-ninja-build-file))) | |
| 32 (when srcdir (expand-file-name srcdir)))) | |
|
Ami GONE FROM CHROMIUM
2011/12/08 19:27:49
You don't need this when (and thus the above let)
Jói
2011/12/08 20:46:16
locate-dominating-file is fine with a nil and then
Ami GONE FROM CHROMIUM
2011/12/08 20:49:16
I was mis-reading the code before (thinking you're
| |
| 24 | 33 |
| 25 (defun cr-flymake-string-prefix-p (prefix str) | 34 (defun cr-flymake-string-prefix-p (prefix str) |
| 26 "Return non-nil if PREFIX is a prefix of STR (23.2 has string-prefix-p but | 35 "Return non-nil if PREFIX is a prefix of STR (23.2 has string-prefix-p but |
| 27 that's case insensitive and also 23.1 doesn't have it)." | 36 that's case insensitive and also 23.1 doesn't have it)." |
| 28 (string= prefix (substring str 0 (length prefix)))) | 37 (string= prefix (substring str 0 (length prefix)))) |
| 29 | 38 |
| 30 (defun cr-flymake-current-file-name () | 39 (defun cr-flymake-current-file-name () |
| 31 "Return the relative path from chromium's src/ directory to the | 40 "Return the relative path from chromium's src/ directory to the |
| 32 file backing the current buffer or nil if it doesn't look like | 41 file backing the current buffer or nil if it doesn't look like |
| 33 we're under chromium/src/." | 42 we're under chromium/src/." |
| 34 (when (and (cr-flymake-chromium-src) | 43 (when (and (cr-flymake-chromium-src) |
| 35 (cr-flymake-string-prefix-p | 44 (cr-flymake-string-prefix-p |
| 36 (cr-flymake-chromium-src) buffer-file-truename)) | 45 (cr-flymake-chromium-src) (cr-flymake-absbufferpath))) |
| 37 (substring buffer-file-truename (length (cr-flymake-chromium-src))))) | 46 (substring (cr-flymake-absbufferpath) (length (cr-flymake-chromium-src))))) |
|
Ami GONE FROM CHROMIUM
2011/12/08 16:17:01
I don't understand the need for these abspath chan
| |
| 38 | 47 |
| 39 (defun cr-flymake-from-build-to-src-root () | 48 (defun cr-flymake-from-build-to-src-root () |
| 40 "Return a path fragment for getting from the build.ninja file to src/." | 49 "Return a path fragment for getting from the build.ninja file to src/." |
| 41 (replace-regexp-in-string | 50 (replace-regexp-in-string |
| 42 "[^/]+" ".." | 51 "[^/]+" ".." |
| 43 (substring | 52 (substring |
| 44 (file-name-directory | 53 (file-name-directory |
| 45 (file-truename (or (and (cr-flymake-string-prefix-p | 54 (file-truename (or (and (cr-flymake-string-prefix-p |
| 46 "/" cr-flymake-ninja-build-file) | 55 "/" cr-flymake-ninja-build-file) |
| 47 cr-flymake-ninja-build-file) | 56 cr-flymake-ninja-build-file) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 61 (list "-C" | 70 (list "-C" |
| 62 (concat (cr-flymake-chromium-src) | 71 (concat (cr-flymake-chromium-src) |
| 63 (file-name-directory cr-flymake-ninja-build-file)) | 72 (file-name-directory cr-flymake-ninja-build-file)) |
| 64 (concat (cr-flymake-from-build-to-src-root) | 73 (concat (cr-flymake-from-build-to-src-root) |
| 65 (cr-flymake-current-file-name) "^"))))) | 74 (cr-flymake-current-file-name) "^"))))) |
| 66 | 75 |
| 67 (defun cr-flymake-kick-off-check-after-save () | 76 (defun cr-flymake-kick-off-check-after-save () |
| 68 "Kick off a syntax check after file save, if flymake-mode is on." | 77 "Kick off a syntax check after file save, if flymake-mode is on." |
| 69 (when flymake-mode (flymake-start-syntax-check))) | 78 (when flymake-mode (flymake-start-syntax-check))) |
| 70 | 79 |
| 71 (defadvice next-error (around cr-flymake-next-error activate) | 80 (defadvice next-error (around flymake-next-error activate) |
|
Ami GONE FROM CHROMIUM
2011/12/08 16:17:01
This change is wrong - that particular arg to defa
| |
| 72 "If flymake has something to say, let it say it; otherwise | 81 "If flymake has something to say, let it say it; otherwise |
| 73 revert to normal next-error behavior." | 82 revert to normal next-error behavior." |
| 74 (if (not flymake-err-info) | 83 (if (not flymake-err-info) |
| 75 (condition-case msg | 84 (condition-case msg |
| 76 ad-do-it | 85 ad-do-it |
| 77 (error (message "%s" (prin1-to-string msg)))) | 86 (error (message "%s" (prin1-to-string msg)))) |
| 78 (flymake-goto-next-error) | 87 (flymake-goto-next-error) |
| 79 ;; copy/pasted from flymake-display-err-menu-for-current-line because I | 88 ;; copy/pasted from flymake-display-err-menu-for-current-line because I |
| 80 ;; couldn't find a way to have it tell me what the relevant error for this | 89 ;; couldn't find a way to have it tell me what the relevant error for this |
| 81 ;; line was in a single call: | 90 ;; line was in a single call: |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 105 (kill-local-variable 'flymake-allowed-file-name-masks)))) | 114 (kill-local-variable 'flymake-allowed-file-name-masks)))) |
| 106 | 115 |
| 107 (add-hook 'find-file-hook 'cr-flymake-find-file 'append) | 116 (add-hook 'find-file-hook 'cr-flymake-find-file 'append) |
| 108 (add-hook 'after-save-hook 'cr-flymake-kick-off-check-after-save) | 117 (add-hook 'after-save-hook 'cr-flymake-kick-off-check-after-save) |
| 109 | 118 |
| 110 ;; Show flymake infrastructure ERRORs in hopes of fixing them. Set to 3 for | 119 ;; Show flymake infrastructure ERRORs in hopes of fixing them. Set to 3 for |
| 111 ;; DEBUG-level output from flymake.el. | 120 ;; DEBUG-level output from flymake.el. |
| 112 (setq flymake-log-level 0) | 121 (setq flymake-log-level 0) |
| 113 | 122 |
| 114 (provide 'flymake-chromium) | 123 (provide 'flymake-chromium) |
| OLD | NEW |