aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.dev>2023-03-15 13:42:41 +0200
committerBozhidar Batsov <bozhidar@batsov.dev>2023-03-15 13:42:41 +0200
commitde9b4ecfa3fafc88c6193007ebc1128c85b32b6e (patch)
tree28e0ab657b4f3be0fd6f07b8f94f8e01b62dd8ee
parent77a5c36220b268b034dfe23ec579768a89a445b2 (diff)
[Fix #1831] Enable the project.el integration only when `projectile-mode` is active
-rw-r--r--CHANGELOG.md1
-rw-r--r--projectile.el70
2 files changed, 39 insertions, 32 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7571288..d2b4e05 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
### Changes
* [#1285](https://github.com/bbatsov/projectile/pull/1825): By default, use [fd](https://github.com/sharkdp/fd) in Git repositories instead of `git ls-files` when it is installed, in order to solve the problem where deleted files were still shown in `projectile-find-file` until their deletions were staged. The user-facing behavior should be the same, although potentially with different performance characteristics in large Git repositories. The old behavior can be reclaimed by setting `projectile-git-use-fd` to nil.
+* [#1831](https://github.com/bbatsov/projectile/issues/1831): Enable the project.el integration only when `projectile-mode` is active.
## 2.7.0 (2022-11-22)
diff --git a/projectile.el b/projectile.el
index 44cdba2..09f6d43 100644
--- a/projectile.el
+++ b/projectile.el
@@ -6081,6 +6081,42 @@ when opening new files."
(when (> (length project-buffers) projectile-max-file-buffer-count)
(kill-buffer (car (last project-buffers)))))))
+;;;; project.el integration
+;;
+;; Projectile will become the default provider for
+;; project.el project and project files lookup when
+;; projectile-mode is enabled.
+;;
+;; The integration can also be manually enabled like this:
+;;
+;; (add-hook 'project-find-functions #'project-projectile)
+;;
+;; See https://github.com/bbatsov/projectile/issues/1591 for
+;; more details.
+
+;; it's safe to require this directly, as it was added in Emacs 25.1
+(require 'project)
+
+(cl-defmethod project-root ((project (head projectile)))
+ (cdr project))
+
+(cl-defmethod project-files ((project (head projectile)) &optional _dirs)
+ (let ((root (project-root project)))
+ ;; Make paths absolute and ignore the optional dirs argument,
+ ;; see https://github.com/bbatsov/projectile/issues/1591#issuecomment-896423965
+ ;; That's needed because Projectile uses relative paths for project files
+ ;; and project.el expects them to be absolute.
+ ;; FIXME: That's probably going to be very slow in large projects.
+ (mapcar (lambda (f)
+ (concat root f))
+ (projectile-project-files root))))
+
+(defun project-projectile (dir)
+ "Return Projectile project of form ('projectile . root-dir) for DIR."
+ (let ((root (projectile-project-root dir)))
+ (when root
+ (cons 'projectile root))))
+
;;;###autoload
(define-minor-mode projectile-mode
"Minor mode to assist project management and navigation.
@@ -6117,12 +6153,14 @@ Otherwise behave as if called interactively.
(projectile--cleanup-known-projects)
(when projectile-auto-discover
(projectile-discover-projects-in-search-path))
+ (add-hook 'project-find-functions #'project-projectile)
(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)
(advice-add 'compilation-find-file :around #'compilation-find-file-projectile-find-compilation-buffer)
(advice-add 'delete-file :before #'delete-file-projectile-remove-from-cache))
(t
+ (remove-hook 'project-find-functions #'project-projectile)
(remove-hook 'find-file-hook #'projectile-find-file-hook-function)
(remove-hook 'dired-before-readin-hook #'projectile-track-known-projects-find-file-hook t)
(advice-remove 'compilation-find-file #'compilation-find-file-projectile-find-compilation-buffer)
@@ -6140,38 +6178,6 @@ Otherwise behave as if called interactively.
;;;###autoload
(define-obsolete-function-alias 'projectile-global-mode 'projectile-mode "1.0")
-;;;; project.el integration
-;;
-;; Projectile will become the default provider for
-;; project.el project and project files lookup.
-;; See https://github.com/bbatsov/projectile/issues/1591 for
-;; more details.
-
-;; it's safe to require this directly, as it was added in Emacs 25.1
-(require 'project)
-
-(cl-defmethod project-root ((project (head projectile)))
- (cdr project))
-
-(cl-defmethod project-files ((project (head projectile)) &optional _dirs)
- (let ((root (project-root project)))
- ;; Make paths absolute and ignore the optional dirs argument,
- ;; see https://github.com/bbatsov/projectile/issues/1591#issuecomment-896423965
- ;; That's needed because Projectile uses relative paths for project files
- ;; and project.el expects them to be absolute.
- ;; FIXME: That's probably going to be very slow in large projects.
- (mapcar (lambda (f)
- (concat root f))
- (projectile-project-files root))))
-
-(defun project-projectile (dir)
- "Return Projectile project of form ('projectile . root-dir) for DIR."
- (let ((root (projectile-project-root dir)))
- (when root
- (cons 'projectile root))))
-
-(add-hook 'project-find-functions #'project-projectile)
-
(provide 'projectile)
;;; projectile.el ends here