From a83e5acab1a8ab9ab8c7a7fbdf5adfdcd6259d2b Mon Sep 17 00:00:00 2001 From: "thakis@chromium.org" Date: Tue, 28 Oct 2014 16:35:40 +0000 Subject: Add indentation offset guess for gyp emacs mode. This fixes the indentation for some of the gyp files using 4 spaces indentation instead of the usual 2. Also adds "ldflags" in the list of keywords. Review URL: https://codereview.chromium.org/598023002/ Patch from Fabrice de Gans ! git-svn-id: http://gyp.googlecode.com/svn/trunk@1995 78cadc50-ecff-11dd-a971-7dbc132099af --- tools/emacs/gyp.el | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/tools/emacs/gyp.el b/tools/emacs/gyp.el index 60619b52..b98b155c 100644 --- a/tools/emacs/gyp.el +++ b/tools/emacs/gyp.el @@ -23,7 +23,28 @@ (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) (setf (first python-indent-levels) - (- (first python-indent-levels) python-indent-offset)))) + (- (first python-indent-levels) python-continuation-offset)))) + +(defadvice python-indent-guess-indent-offset (around + gyp-indent-guess-indent-offset + activate) + "Guess correct indent offset in gyp-mode." + (or (and (not (eq major-mode 'gyp-mode)) + ad-do-it) + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + ;; Find first line ending with an opening brace that is not a comment. + (or (and (re-search-forward "\\(^[[{]$\\|^.*[^#].*[[{]$\\)") + (forward-line) + (/= (current-indentation) 0) + (set (make-local-variable 'python-indent-offset) + (current-indentation)) + (set (make-local-variable 'python-continuation-offset) + (current-indentation))) + (message "Can't guess gyp indent offset, using default: %s" + python-continuation-offset)))))) (define-derived-mode gyp-mode python-mode "Gyp" "Major mode for editing .gyp files. See http://code.google.com/p/gyp/" @@ -36,9 +57,10 @@ (defun gyp-set-indentation () "Hook function to configure python indentation to suit gyp mode." - (setq python-continuation-offset 2 - python-indent-offset 2 - python-indent-guess-indent-offset nil)) + (set (make-local-variable 'python-indent-offset) 2) + (set (make-local-variable 'python-continuation-offset) 2) + (set (make-local-variable 'python-indent-guess-indent-offset) t) + (python-indent-guess-indent-offset)) (add-hook 'gyp-mode-hook 'gyp-set-indentation) @@ -223,7 +245,7 @@ "copies" "defines" "dependencies" "destination" "direct_dependent_settings" "export_dependent_settings" "extension" "files" - "include_dirs" "includes" "inputs" "libraries" + "include_dirs" "includes" "inputs" "ldflags" "libraries" "link_settings" "mac_bundle" "message" "msvs_external_rule" "outputs" "product_name" "process_outputs_as_sources" "rules" "rule_name" -- cgit v1.2.3