feat: add doom/add-directory-as-project command

Will register any arbitrary directory as a projectile project, adding a
.project file to it if necessary.
This commit is contained in:
Henrik Lissner 2021-09-26 13:45:25 +02:00
parent 002711ff9b
commit 1419b9dc41

View file

@ -69,6 +69,24 @@ they are absolute."
"Find a file under `doom-emacs-dir', recursively." "Find a file under `doom-emacs-dir', recursively."
(interactive) (doom-project-find-file doom-emacs-dir)) (interactive) (doom-project-find-file doom-emacs-dir))
;;;###autoload
(defun doom/add-directory-as-project (dir)
"Register an arbitrary directory as a project.
If DIR is not a valid project, a .project file will be created within it. This
command will throw an error if a parent of DIR is a valid project (which would
mask DIR)."
(interactive "D")
(let ((short-dir (abbreviate-file-name dir)))
(unless (file-equal-p (doom-project-root dir) dir)
(with-temp-file (doom-path dir ".project")))
(let ((proj-dir (doom-project-root dir)))
(unless (file-equal-p proj-dir dir)
(user-error "Can't add %S as a project, because %S is already a project"
short-dir (abbreviate-file-name proj-dir)))
(message "%S was not a project; adding .project file to it"
short-dir (abbreviate-file-name proj-dir))
(projectile-add-known-project directory))))
;; ;;
;;; Library ;;; Library