Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Unified Diff: tools/gn/misc/emacs/gn-mode.el

Issue 1887233004: Make it easy to run `gn format' on an emacs buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bad content. Try to upload again. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/misc/emacs/gn-mode.el
diff --git a/tools/gn/misc/emacs/gn-mode.el b/tools/gn/misc/emacs/gn-mode.el
index 66822907c67d178dc12e9bf7af4cb5ae6b3523d3..435e872c9ad45f8eebeefd2db035ac9006a980f2 100644
--- a/tools/gn/misc/emacs/gn-mode.el
+++ b/tools/gn/misc/emacs/gn-mode.el
@@ -36,6 +36,11 @@
:group 'gn
:type 'integer)
+(defcustom gn-format-command "gn format --stdin"
+ "The command to run to format gn files in place."
+ :group 'gn
+ :type 'string)
+
(defgroup gn-faces nil
"Faces used in Generate Ninja mode."
:group 'gn
@@ -123,6 +128,20 @@ variable name or the '{{' and '}}' which surround it."
;; if we do.
t))
+(defun gn-run-format ()
+ "Run 'gn format' on the buffer in place."
+ (interactive)
+ ;; We can't `save-excursion' here; that will put us at the beginning of the
+ ;; shell output, aka the beginning of the document.
+ (let ((my-start-line (line-number-at-pos)))
+ (shell-command-on-region (point-min) (point-max) gn-format-command nil t)
+ (goto-line my-start-line)))
+
+(defvar gn-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "\C-c\C-f" 'gn-run-format)
+ map))
+
;;;###autoload
(define-derived-mode gn-mode prog-mode "GN"
"Major mode for editing gn (Generate Ninja)."
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698