diff options
-rw-r--r-- | emacs.d/core/core-bindings.el | 2 | ||||
-rw-r--r-- | emacs.d/core/core-defun.el | 29 |
2 files changed, 31 insertions, 0 deletions
diff --git a/emacs.d/core/core-bindings.el b/emacs.d/core/core-bindings.el index 377b89c..a9d1b4d 100644 --- a/emacs.d/core/core-bindings.el +++ b/emacs.d/core/core-bindings.el @@ -8,4 +8,6 @@ (global-set-key (kbd "s-N") 'fcuny/switch-to-scratch) +(global-set-key (kbd "C-c t") 'fcuny/jump-to-build-file) + (provide 'core-bindings) diff --git a/emacs.d/core/core-defun.el b/emacs.d/core/core-defun.el index 5180e68..be7899f 100644 --- a/emacs.d/core/core-defun.el +++ b/emacs.d/core/core-defun.el @@ -39,4 +39,33 @@ (ansi-term (getenv "SHELL"))) (switch-to-buffer-other-window "*ansi-term*"))) +;; jump to the BUILD file +(defvar fcuny/build-file "BUILD" + "Name of the file containing our build targets") + +(defun fcuny/find-root-directory-for-build-file (file) + "Find the root." + (let ((root nil) + try) + (while (not (or root + (null file) + (string-match locate-dominating-stop-dir-regexp file))) + (setq try (if (stringp fcuny/build-file) + (file-exists-p (expand-file-name fcuny/build-file file)) + (message "found file exists -> %s" file))) + (cond (try (setq root file)) + ((equal file (setq file (file-name-directory + (directory-file-name file)))) + (setq file nil)))) + (and root (expand-file-name (file-name-as-directory root))))) + +(defun fcuny/jump-to-build-file () + "Open the BUILD file in a buffer if it exists." + (interactive) + (let ((build-file (fcuny/find-root-directory-for-build-file (file-name-directory (buffer-file-name))))) + (message "found a file %s" build-file) + (if build-file + (find-file (concat build-file fcuny/build-file)) + (error "Could not find %s" fcuny/build-file)))) + (provide 'core-defun) |