From e70ef017ff3ff1c3aab6023b950b9206773d44dd Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 26 Aug 2022 20:20:05 +0300 Subject: feat(tazjin/emacs): add `find-cargo-project` function This is useful for eglot launching rust-analyzer when I'm outside of a depot project. Change-Id: I1fa1dc11e3eabe4bdedbd6389b55411641391c7e Reviewed-on: https://cl.tvl.fyi/c/depot/+/6176 Reviewed-by: tazjin Autosubmit: tazjin Tested-by: BuildkiteCI --- users/tazjin/emacs/config/functions.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'users') diff --git a/users/tazjin/emacs/config/functions.el b/users/tazjin/emacs/config/functions.el index e725c23ccf..f64907a591 100644 --- a/users/tazjin/emacs/config/functions.el +++ b/users/tazjin/emacs/config/functions.el @@ -293,6 +293,16 @@ the GPG agent correctly." (add-to-list 'project-find-functions #'find-depot-project) +(defun find-cargo-project (dir) + "Attempt to find the current project in `project-find-functions' +by looking for a `Cargo.toml' file." + (unless (equal "/" dir) + (if (f-exists-p (f-join dir "Cargo.toml")) + (cons 'transient dir) + (find-cargo-project (f-parent dir))))) + +(add-to-list 'project-find-functions #'find-cargo-project) + (defun magit-find-file-worktree () (interactive) "Find a file in the current (ma)git worktree." -- cgit 1.4.1