about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-26T17·20+0300
committerclbot <clbot@tvl.fyi>2022-08-26T17·26+0000
commite70ef017ff3ff1c3aab6023b950b9206773d44dd (patch)
tree4b799f231f4b43fc328d5349c1c2071ef964f1d1
parent598c197422481ed31c605d4dc3b7a7e3f043aa85 (diff)
feat(tazjin/emacs): add `find-cargo-project` function r/4509
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 <tazjin@tvl.su>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
-rw-r--r--users/tazjin/emacs/config/functions.el10
1 files changed, 10 insertions, 0 deletions
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."