Skip to content

Instantly share code, notes, and snippets.

@kumagi
Created February 21, 2017 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumagi/2bda4dbdee8730136fd4c44b65878787 to your computer and use it in GitHub Desktop.
Save kumagi/2bda4dbdee8730136fd4c44b65878787 to your computer and use it in GitHub Desktop.
(require 'cl)
(require 'compile)
(defun upward-find-file (filename &optional startdir)
(let
((dirname (expand-file-name
(if startdir startdir ".")))
(found nil)
(top nil))
(while (not (or found top))
(if (string= (expand-file-name dirname) "/")
(setq top t))
(if (file-exists-p (expand-file-name filename dirname))
(setq found t)
(setq dirname (expand-file-name ".." dirname))))
(if found dirname nil)))
(defun cmake-compile ()
(interactive)
(setq builddir
(expand-file-name "build"
(upward-find-file "build" ".")))
(cd-absolute builddir)
(message "moved %s" builddir)
(compile (format "cmake .. -G Ninja && ninja"
(upward-find-file "build" "."))))
(global-set-key "\C-cc" 'cmake-compile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment