Prefer simpler, more idiomatic project-find-function

This version avoids installed all of the custom `cl-defmethods` for a
`'monorepo` type and instead uses the existing `'transient`.
This commit is contained in:
William Carroll 2020-08-24 11:19:47 +01:00
parent 7ab86f5423
commit 7a1e56e7d1

View file

@ -207,31 +207,12 @@
(defun project-find-function--briefcase (dir) (defun project-find-function--briefcase (dir)
"Find the nearest default.nix file; otherwise, terminate at the .git "Find the nearest default.nix file; otherwise, terminate at the .git
directory." directory."
(let ((filenames (->> dir f-files (-map #'f-filename))) (when (s-starts-with? (getenv "BRIEFCASE") (f-expand dir))
(dirnames (->> dir f-directories (-map #'f-dirname)))) (if (f-exists? (f-join dir "default.nix"))
(if (or (-contains? filenames "default.nix") (cons 'transient dir)
(-contains? dirnames ".git")) (project-find-function--briefcase (f-parent dir)))))
(cons 'monorepo dir)
(if (f-parent dir)
(project-find-function--briefcase (f-parent dir))
nil))))
(cl-defmethod project-root ((project (head monorepo))) (add-to-list 'project-find-functions #'project-find-function--briefcase)
(cdr project))
(cl-defmethod project-roots ((project (head monorepo)))
(list (cdr project)))
(cl-defmethod project-external-roots ((project (head monorepo)))
(project-external-roots (cons 'vc (cdr project))))
(cl-defmethod project-ignores ((project (head monorepo)) dir)
(project-ignores (cons 'vc (cdr project)) dir))
(cl-defmethod project-files ((project (head monorepo)) &optional dirs)
(project-files (cons 'vc (cdr project)) dirs))
(setq project-find-functions (list #'project-find-function--briefcase))
(use-package deadgrep (use-package deadgrep
:config :config