emacs with ninja

520 views
Skip to first unread message

Pete Williamson

unread,
Aug 7, 2012, 12:07:08 PM8/7/12
to chromi...@chromium.org
Can anyone share a .emacs snippet for getting ninja compile to work in a compilation buffer?  Here is what I have so far, but it isn't quite there yet...

;; Chromium specific commands
;; compile using ninja
(when *ninja-compile-enabled*
  (setq-default my-ninja-command nil)
  ;; somehow this isn't good enough, we need to add this to the path used by the shell inside emacs, not to the path used by emacs
  (setq exec-path (append exec-path '("~/depot_tools")))
  (defun ninja-c-mode-compile (command)
    (interactive (list (read-string "target: " my-ninja-command)))
    (setq my-ninja-command command)
    (interactive)
    (save-some-buffers t)
    (cd "~/chromium/src/")
    (compile (concat "ninja -C out/Debug " command))))

Thanks!

Nico Weber

unread,
Aug 7, 2012, 12:09:41 PM8/7/12
to pet...@google.com, chromi...@chromium.org
Does tools/emacs/flymake-chromium.el help?

Nico
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev

Pete Williamson

unread,
Aug 7, 2012, 12:26:42 PM8/7/12
to Nico Weber, chromi...@chromium.org
Thanks!  
I did look at src/tools/emacs, but I didn't see anything obvious there.  I saw the filetypes .el file, which sets up the .gyp file extension for good editing, and flymake-chromium, and something for the trybot.

I looked at flymake-chromium.el, and it looks like a way to set up on the fly compilation of a file as you edit, which is good, but not the same as doing a build of everything in the compilation buffer.

Mike Wittman

unread,
Aug 7, 2012, 2:15:38 PM8/7/12
to pet...@google.com, Nico Weber, chromi...@chromium.org
If you (setq compilation-ask-about-save nil), you can do the rest via the standard "compile" command:

cd ~/chromium/src && PATH=${PATH}:~/depot_tools ninja -C out/Debug targets...

-Mike

David Holloway

unread,
Aug 7, 2012, 2:28:35 PM8/7/12
to wit...@google.com, pet...@google.com, Nico Weber, chromi...@chromium.org
(this time from @chromium.dev)

On Tue, Aug 7, 2012 at 11:27 AM, David Holloway <> wrote:

I use erg's find-things-fast.el for it's ftf-compile command (which sets your cwd essentially)


and then setup ninja like so:

(setq-default compile-command "time ninja -C out/Debug")
(setq compilation-scroll-output t)
(defun my-compile ()
  "Run compile and resize the compile window."
  (interactive)
  (progn
    (call-interactively 'ftf-compile)
    (setq cur (selected-window))
    (setq w (get-buffer-window "*compilation*"))
    (select-window w)
    (setq h (window-height w))
    (shrink-window (- h 15))
    (select-window cur)))
(global-set-key "\C-xm" 'my-compile)

Pete Williamson

unread,
Aug 7, 2012, 2:48:44 PM8/7/12
to David Holloway, wit...@google.com, Nico Weber, chromi...@chromium.org
Thanks, everyone!

It seems that my problem was that when running from the Dock on a mac, lots of normal path variables don't get set.  A second problem is that often don't have the directory set to .../chromium/src. This is how I fixed it in my .emacs file, and it worked for me.  I'm absolutely open if anyone has a better answer.

;; OS dependent settings at the top of my .emacs file
(setq depot-tools-path "~/depot_tools:")
(setq chromium-src-dir "/Source/chromium/src")


  ;; On the Mac
  (when (string-equal system-type "darwin")
    ;; put things I need onto the global path, since the dock doesn't use $PATH
    (setenv "PATH" (concat depot-tools-path (getenv "PATH")))
    (push depot-tools-path exec-path))

  ;; set up ninja compilation
  (setq-default my-ninja-command nil)
  (defun ninja-c-mode-compile (command)
    (interactive (list (read-string "target: " my-ninja-command)))
    (setq my-ninja-command command)
    (interactive)
    (save-some-buffers t)
    (cd chromium-src-dir)
    (compile (concat "ninja -C out/Debug " command)))



Then I can just run M-x ninja<tab>  <target> to compile.
Reply all
Reply to author
Forward
0 new messages