From: g0dil Date: Mon, 18 Jun 2007 10:21:14 +0000 (+0000) Subject: cc-ide: Add ccide-project-search-upwards helper X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=14d89c903eb14c633405b750cdbc1f06cc0ecb42;p=emacsstuff.git cc-ide: Add ccide-project-search-upwards helper --- diff --git a/cc-ide/cc-ide.el b/cc-ide/cc-ide.el index 935bf7a..67d0de1 100644 --- a/cc-ide/cc-ide.el +++ b/cc-ide/cc-ide.el @@ -1414,16 +1414,21 @@ instatiations at point." (ccide-auto-decorate-new-files)) (defun ccide-project-load-config () - (let ((dir (buffer-file-name)) - last-dir conf) + (let ((conf (ccide-project-search-upwards "project.el" (file-name-directory (buffer-file-name))))) + (when conf + (set (make-local-variable 'ccide-project-root) (file-name-directory conf)) + (load-file conf)))) + +(defun ccide-project-search-upwards (file &optional dir) + "Search for FILE in all directories starting at DIR and going up the directory hierarchy. +DIR defaults to ccide-project-root" + (let (conf last-dir) + (setq dir (expand-file-name "x" (or dir ccide-project-root))) (while (and (not (string= (setq last-dir dir dir (directory-file-name (file-name-directory dir))) last-dir)) - (setq conf (expand-file-name "project.el" dir)) + (setq conf (expand-file-name file dir)) (not (file-readable-p conf)))) - (if (file-readable-p conf) - (progn - (set (make-local-variable 'ccide-project-root) dir) - (load-file conf))))) + (and (file-readable-p conf) conf))) (add-hook 'c-mode-hook 'ccide-install-it) (add-hook 'c++-mode-hook 'ccide-install-it)