fix(lib): doom/add-directory-as-project
If the target directory wasn't in a project, this command would throw a type error (see #8032). This also adds more checks and informative error handling to the command. Fix: #8032
This commit is contained in:
parent
538ddf5e66
commit
22fc36dba7
1 changed files with 14 additions and 9 deletions
|
@ -79,16 +79,21 @@ file will be created within it so that it will always be treated as one. This
|
|||
command will throw an error if a parent of DIR is a valid project (which would
|
||||
mask DIR)."
|
||||
(interactive "D")
|
||||
(when-let ((proj-dir (doom-project-root dir)))
|
||||
(if (file-equal-p proj-dir dir)
|
||||
(user-error "ERROR: Directory is already a project: %s" proj-dir)
|
||||
(user-error "ERROR: Directory is already inside another project: %s" proj-dir)))
|
||||
(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 dir))))
|
||||
(when (projectile-ignored-project-p dir)
|
||||
(user-error "ERROR: Directory is in projectile's ignore list: %s" short-dir))
|
||||
(dolist (proj projectile-known-projects)
|
||||
(when (file-in-directory-p proj dir)
|
||||
(user-error "ERROR: Directory contains a known project: %s" short-dir))
|
||||
(when (file-equal-p proj dir)
|
||||
(user-error "ERROR: Directory is already a known project: %s" short-dir)))
|
||||
(with-temp-file (doom-path dir ".project"))
|
||||
(message "Added directory as a project: %s" short-dir)
|
||||
(projectile-add-known-project dir)))
|
||||
|
||||
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue