diff options
author | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-23 17:27:42 +0000 |
---|---|---|
committer | fischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-23 17:27:42 +0000 |
commit | f7fe6fa5dab88538d47e4cc024aa62a39d98fe97 (patch) | |
tree | 50ba864d232f0594bd0e19e4d20e263c71859e50 /tools/emacs | |
parent | a1f9db4caa39cb2d9b3024410373b51e27fe79cf (diff) | |
download | chromium_src-f7fe6fa5dab88538d47e4cc024aa62a39d98fe97.zip chromium_src-f7fe6fa5dab88538d47e4cc024aa62a39d98fe97.tar.gz chromium_src-f7fe6fa5dab88538d47e4cc024aa62a39d98fe97.tar.bz2 |
Add ninja-based flymake support for working with chromium source code.
Saving a buffer kicks off an async syntax check and highlights error lines.
BUG=none
TEST=manual
Review URL: http://codereview.chromium.org/8008008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102518 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/emacs')
-rw-r--r-- | tools/emacs/flymake-chromium.el | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tools/emacs/flymake-chromium.el b/tools/emacs/flymake-chromium.el new file mode 100644 index 0000000..fe1e775 --- /dev/null +++ b/tools/emacs/flymake-chromium.el @@ -0,0 +1,108 @@ +;; Copyright (c) 2011 The Chromium Authors. All rights reserved. +;; Use of this source code is governed by a BSD-style license that can be +;; found in the LICENSE file. + +;; Set up flymake for use with chromium code. Uses ninja (since none of the +;; other chromium build systems have latency that allows interactive use). +;; +;; Requires a modern emacs (GNU Emacs >= 23) and that gyp has already generated +;; the build.ninja file(s). See defcustoms below for settable knobs. + + +(require 'flymake) + +(defcustom cr-flymake-ninja-build-file "out/Debug/build.ninja" + "Relative path from chromium's src/ directory to the + build.ninja file to use.") + +(defcustom cr-flymake-ninja-executable "ninja" + "Ninja executable location; either in $PATH or explicitly given.") + +(defun cr-flymake-chromium-src () + "Return chromium's src/ directory, or nil on failure." + (locate-dominating-file buffer-file-truename cr-flymake-ninja-build-file)) + +(defun cr-flymake-current-file-name () + "Return the relative path from chromium's src/ directory to the + file backing the current buffer or nil if it doesn't look like + we're under chromium/src/." + (when (and (cr-flymake-chromium-src) + (string-prefix-p (cr-flymake-chromium-src) buffer-file-truename)) + (substring buffer-file-truename (length (cr-flymake-chromium-src))))) + +(defun cr-flymake-from-build-to-src-root () + "Return a path fragment for getting from the build.ninja file to src/." + (replace-regexp-in-string + "[^/]+" ".." + (substring + (file-name-directory + (file-truename (or (and (string-prefix-p "/" cr-flymake-ninja-build-file) + cr-flymake-ninja-build-file) + (concat (cr-flymake-chromium-src) + cr-flymake-ninja-build-file)))) + (length (cr-flymake-chromium-src))))) + +(defun cr-flymake-getfname (file-name-from-error-message) + "Strip cruft from the passed-in filename to help flymake find the real file." + (concat (cr-flymake-chromium-src) + (substring file-name-from-error-message + (length (cr-flymake-from-build-to-src-root))))) + +(defun cr-flymake-ninja-command-line () + "Return the command-line for running ninja, as a list of strings, or nil if + we're not during a save" + (unless (buffer-modified-p) + (list cr-flymake-ninja-executable + (list "-C" + (concat (cr-flymake-chromium-src) + (file-name-directory cr-flymake-ninja-build-file)) + (concat (cr-flymake-from-build-to-src-root) + (cr-flymake-current-file-name) "^"))))) + +(defun cr-flymake-kick-off-check-after-save () + "Kick off a syntax check after file save, if flymake-mode is on." + (when flymake-mode (flymake-start-syntax-check))) + +(defadvice next-error (around cr-flymake-next-error activate) + "If flymake has something to say, let it say it; otherwise + revert to normal next-error behavior." + (if (not flymake-err-info) + (condition-case msg + ad-do-it + (error (message "%s" (prin1-to-string msg)))) + (flymake-goto-next-error) + ;; copy/pasted from flymake-display-err-menu-for-current-line because I + ;; couldn't find a way to have it tell me what the relevant error for this + ;; line was in a single call: + (let* ((line-no (flymake-current-line-no)) + (line-err-info-list + (nth 0 (flymake-find-err-info flymake-err-info line-no))) + (menu-data (flymake-make-err-menu-data line-no line-err-info-list))) + (prin1 (caaadr menu-data) t)))) + +(defun cr-flymake-find-file () + "Enable flymake, but only if it makes sense, and immediately + disable timer-based execution." + (when (and (not flymake-mode) + (not buffer-read-only) + (cr-flymake-current-file-name)) + ;; Since flymake-allowed-file-name-masks requires static regexps to match + ;; against, can't use cr-flymake-chromium-src here. Instead we add a + ;; generic regexp, but only to a buffer-local version of the variable. + (set (make-local-variable 'flymake-allowed-file-name-masks) + (list (list (concat "\\." (make-regexp '("c" "cc" "cpp")) "$") + 'cr-flymake-ninja-command-line + nil + 'cr-flymake-getfname))) + (flymake-find-file-hook) + (if flymake-mode + (cancel-timer flymake-timer) + (kill-local-variable 'flymake-allowed-file-name-masks)))) + +(add-hook 'find-file-hook 'cr-flymake-find-file 'append) +(add-hook 'after-save-hook 'cr-flymake-kick-off-check-after-save) + +;; Show flymake infrastructure ERRORs in hopes of fixing them. +(setq flymake-log-level 0) + +(provide 'flymake-chromium) |