Created
May 23, 2012 07:40
-
-
Save NeoCat/2773738 to your computer and use it in GitHub Desktop.
.emacs to bind "C-c c" to `make' in the directory with the nearest Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'cl) | |
(defun* get-closest-file-dir (&optional (file "Makefile")) | |
"Determine the directory of the first instance of FILE starting from the current directory towards root. | |
This may not do the correct thing in presence of links. If it does not find FILE, then it shall return nil." | |
(let ((root (expand-file-name "/"))) | |
(loop | |
for d = default-directory then (expand-file-name ".." d) | |
if (file-exists-p (expand-file-name file d)) return d | |
if (equal d root) return nil))) | |
(require 'compile) | |
(add-hook 'c-mode-common-hook | |
'(lambda () | |
(define-key c-mode-base-map "\C-cc" 'compile) | |
(define-key c-mode-base-map "\C-ce" 'next-error) | |
(c-toggle-hungry-state 1) | |
(c-set-style "linux") | |
(setq tab-width 8) | |
(if (equal compile-command "make -k ") ;; default | |
(set 'compile-command | |
(format "make -C %s " (get-closest-file-dir)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment