Skip to content

Commit

Permalink
[Fix #1591] Add project.el integration
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Oct 27, 2022
1 parent c8eee21 commit a0105e7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New features

* [#1591](https://github.com/bbatsov/projectile/issues/1591): Add `project.el` integration that will make Projectile the default provider for project lookup.

## 2.6.0 (2022-10-25)

### New features
Expand Down
14 changes: 14 additions & 0 deletions doc/modules/ROOT/pages/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,17 @@ You can add additional commands to the commander like this:
----

Place such snippets after ``projectile-mode``'s init code.

== Using Projectile with project.el

Starting with version 2.7 Projectile bundles some integration with
`project.el` that makes `project.el` use by default Projectile's
project lookup function (`projectile-project-root`) and project file
lookup function (`projectile-project-files`).

That's useful as some packages (e.g. `eglot`) support natively only
`project.el`'s API for project discovery. Fortunately, `project.el`
makes it easy to install additional project lookup functions and that's
exactly what Projectile does.

TIP: You can read more about the integration https://github.com/bbatsov/projectile/issues/1591[here].
32 changes: 32 additions & 0 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -5987,6 +5987,38 @@ 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 f root))
(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

0 comments on commit a0105e7

Please sign in to comment.