Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(require 'cl)
(require 'compile)
(defun upward-find-file (filename &optional startdir)
((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 ()
(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