Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a projectile-root-marked function for finding roots #1812

Merged
merged 2 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [#1591](https://github.com/bbatsov/projectile/issues/1591): Add `project.el` integration that will make Projectile the default provider for project lookup.
* Add new command `projectile-find-references` (bound to `C-c C-p ?` and `C-c C-p s x`).
* [#1737](https://github.com/bbatsov/projectile/pull/1737): Add helpers for `dir-local-variables` for 3rd party use. Functions `projectile-add-dir-local-variable` and `projectile-delete-dir-local-variable` wrap their built-in counterparts. They always use `.dir-locals.el` from the root of the current Projectile project.
* Add a new defcustom (`projectile-dirconfig-file`) controlling the name of the file used as Projectile’s root marker and configuration file.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouln't the new projectile-root-marked function be mentioned in the changelog as well?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it should. Those things should also be covered somewhere in the docs, so it's easier to discover but I'll do this myself when I can.

### Bug fixed

Expand Down
20 changes: 16 additions & 4 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ See `projectile-register-project-type'."
:type '(repeat string))

(defcustom projectile-project-root-files-bottom-up
'(".projectile" ; projectile project marker
".git" ; Git VCS root dir
'(".git" ; Git VCS root dir
".hg" ; Mercurial VCS root dir
".fslckout" ; Fossil VCS root dir
"_FOSSIL_" ; Fossil VCS root DB on Windows
Expand Down Expand Up @@ -351,6 +350,7 @@ containing a root file."

(defcustom projectile-project-root-functions
'(projectile-root-local
projectile-root-marked
projectile-root-bottom-up
projectile-root-top-down
projectile-root-top-down-recurring)
Expand All @@ -361,9 +361,17 @@ algorithm."
:group 'projectile
:type '(repeat function))

(defcustom projectile-dirconfig-file
".projectile"
"The file which serves both as a project marker and configuration file.
This should _not_ be set via .dir-locals.el."
:group 'projectile
:type 'file
:package-version '(projectile . "2.7.0"))

(defcustom projectile-dirconfig-comment-prefix
nil
"Projectile config file (.projectile) comment start marker.
"`projectile-dirconfig-file` comment start marker.
If specified, starting a line in a project's .projectile file with this
character marks that line as a comment instead of a pattern.
Similar to '#' in .gitignore files."
Expand Down Expand Up @@ -1199,6 +1207,10 @@ Return the first (topmost) matched directory or nil if not found."
(cl-find-if (lambda (f) (projectile-file-exists-p (expand-file-name f dir)))
(or list projectile-project-root-files)))))

(defun projectile-root-marked (dir)
"Identify a project root in DIR by search for `projectile-dirconfig-file`."
(projectile-root-bottom-up dir (list projectile-dirconfig-file)))

(defun projectile-root-bottom-up (dir &optional list)
"Identify a project root in DIR by bottom-up search for files in LIST.
If LIST is nil, use `projectile-project-root-files-bottom-up' instead.
Expand Down Expand Up @@ -1946,7 +1958,7 @@ Unignored files/directories are not included."

(defun projectile-dirconfig-file ()
"Return the absolute path to the project's dirconfig file."
(expand-file-name ".projectile" (projectile-project-root)))
(expand-file-name projectile-dirconfig-file (projectile-project-root)))

(defun projectile-parse-dirconfig-file ()
"Parse project ignore file and return directories to ignore and keep.
Expand Down