From 1419b9dc41d16bd2c3928ea5eb89ee9491a7c225 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 26 Sep 2021 13:45:25 +0200 Subject: [PATCH] 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. --- core/autoload/projects.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/autoload/projects.el b/core/autoload/projects.el index fb7a81210..e6ce39fd0 100644 --- a/core/autoload/projects.el +++ b/core/autoload/projects.el @@ -69,6 +69,24 @@ they are absolute." "Find a file under `doom-emacs-dir', recursively." (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