aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob First <jacob.first@member.fsf.org>2020-05-23 15:42:19 -0400
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2020-06-15 23:18:06 +0300
commit10bd27d723764c39336ccb4d1e205b1c767ba4d9 (patch)
tree54bfce6fbd81338d1df32d61b73667642eb6b45c
parentd882b10322a2f0e2b673fa228f2468eef0ea7977 (diff)
Add a custom setting to control automatic project discovery
-rw-r--r--CHANGELOG.md1
-rw-r--r--projectile.el8
-rw-r--r--test/projectile-test.el17
3 files changed, 22 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f7dc17e..814602c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
* Optional support for comments in .projectile dirconfig files using `projectile-dirconfig-comment-prefix`.
* [#1497](https://github.com/bbatsov/projectile/pull/1497): New command `projectile-run-gdb` (<kbd>x g</kbd> in `projectile-command-map`).
* Add [Bazel](https://bazel.build) project type.
+* [#1539](https://github.com/bbatsov/projectile/pull/1539): New defcustom `projectile-auto-discover` controlling whether to automatically discover projects in the search path when `projectile-mode` activates.
### Bugs fixed
diff --git a/projectile.el b/projectile.el
index 3d90eec..44825bf 100644
--- a/projectile.el
+++ b/projectile.el
@@ -175,6 +175,11 @@ A value of nil means the cache never expires."
:type '(choice (const :tag "Disabled" nil)
(integer :tag "Seconds")))
+(defcustom projectile-auto-discover t
+ "Whether to discover projects when `projectile-mode' is activated."
+ :group 'projectile
+ :type 'boolean)
+
(defcustom projectile-auto-update-cache t
"Whether the cache should automatically be updated when files are opened or deleted."
:group 'projectile
@@ -4817,7 +4822,8 @@ Otherwise behave as if called interactively.
(projectile-load-known-projects)
;; update the list of known projects
(projectile--cleanup-known-projects)
- (projectile-discover-projects-in-search-path)
+ (when projectile-auto-discover
+ (projectile-discover-projects-in-search-path))
(add-hook 'find-file-hook 'projectile-find-file-hook-function)
(add-hook 'projectile-find-dir-hook #'projectile-track-known-projects-find-file-hook t)
(add-hook 'dired-before-readin-hook #'projectile-track-known-projects-find-file-hook t t)
diff --git a/test/projectile-test.el b/test/projectile-test.el
index bc9a5d6..6cafe79 100644
--- a/test/projectile-test.el
+++ b/test/projectile-test.el
@@ -310,13 +310,24 @@ You'd normally combine this with `projectile-test-with-sandbox'."
(expect (projectile-files-via-ext-command "" nil) :not :to-be-truthy)))
(describe "projectile-mode"
- (it "sets up hook functions"
+ (before-each
(spy-on 'projectile--cleanup-known-projects)
- (spy-on 'projectile-discover-projects-in-search-path)
+ (spy-on 'projectile-discover-projects-in-search-path))
+ (it "sets up hook functions"
(projectile-mode 1)
(expect (memq 'projectile-find-file-hook-function find-file-hook) :to-be-truthy)
(projectile-mode -1)
- (expect (memq 'projectile-find-file-hook-function find-file-hook) :not :to-be-truthy)))
+ (expect (memq 'projectile-find-file-hook-function find-file-hook) :not :to-be-truthy))
+ (it "respects projectile-auto-discover setting"
+ (unwind-protect
+ (progn
+ (let ((projectile-auto-discover nil))
+ (projectile-mode 1)
+ (expect 'projectile-discover-projects-in-search-path :not :to-have-been-called))
+ (let ((projectile-auto-discover t))
+ (projectile-mode 1)
+ (expect 'projectile-discover-projects-in-search-path :to-have-been-called)))
+ (projectile-mode -1))))
(describe "projectile-relevant-known-projects"
(it "returns a list of known projects"