branch: elpa/projectile
commit 9ca36353567a020fec42e76ee03cd87fff3034a8
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Add compat dependency and adopt modern Emacs APIs
Add (compat "30") as a dependency, which backports newer Emacs
functions to older versions with zero overhead on modern Emacs.
Changes enabled by compat:
- Use string-replace instead of replace-regexp-in-string for literal
replacements (resolves TODO in projectile-complementary-dir)
Also simplified version-conditional code now safe with Emacs 27.1+:
- Remove redundant fboundp check for xref-references-in-directory
- Remove redundant fboundp check for xref-find-definitions
- Simplify auto tags backend to prefer ggtags then xref
---
CHANGELOG.md | 1 +
projectile.el | 17 ++++++-----------
2 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7cf63dcfbd..ebd73462a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,7 @@
### Changes
* **[Breaking]** Bump minimum required Emacs version from 26.1 to 27.1. This
removes ~30 lines of compatibility code (fileloop fallback, `time-convert`
fallback, `projectile-flatten` shim) and fixes the `tags-query-replace` FIXME
in `projectile-replace-regexp`.
+* Add `compat` as a dependency, enabling the use of modern Emacs APIs (e.g.
`string-replace`) on older Emacs versions.
* [#1958](https://github.com/bbatsov/projectile/issues/1958): Exclude
`.projectile-cache.eld` from search results (ripgrep/ag/grep) by default.
* [#1957](https://github.com/bbatsov/projectile/pull/1957): Add `:caller`
information to calls to `ivy-read` (used by packages like `ivy-rich`).
* [#1947](https://github.com/bbatsov/projectile/issues/1947):
`projectile-project-name` should be marked as safe.
diff --git a/projectile.el b/projectile.el
index 8f224433a5..db6bdbb78b 100644
--- a/projectile.el
+++ b/projectile.el
@@ -6,7 +6,7 @@
;; URL: https://github.com/bbatsov/projectile
;; Keywords: project, convenience
;; Version: 2.9.1
-;; Package-Requires: ((emacs "27.1"))
+;; Package-Requires: ((emacs "27.1") (compat "30"))
;; This file is NOT part of GNU Emacs.
@@ -36,6 +36,7 @@
;;; Code:
(require 'cl-lib)
+(require 'compat)
(require 'thingatpt)
(require 'ibuffer)
(require 'ibuf-ext)
@@ -3983,8 +3984,7 @@ Replace STRING in DIR-PATH with REPLACEMENT."
(let* ((project-root (projectile-project-root))
(relative-dir (file-name-directory (file-relative-name dir-path
project-root))))
(projectile-expand-root
- ;; TODO: Use string-replace once we target emacs 28
- (replace-regexp-in-string string replacement relative-dir t))))
+ (string-replace string replacement relative-dir))))
(defun projectile--create-directories-for (path)
"Create directories necessary for PATH."
@@ -4572,8 +4572,7 @@ installed to work."
A thin wrapper around `xref-references-in-directory'."
(interactive)
- (when (and (fboundp 'xref-references-in-directory)
- (fboundp 'xref--show-xrefs))
+ (when (fboundp 'xref--show-xrefs)
(let ((project-root (projectile-acquire-root))
(symbol (or symbol (read-from-minibuffer "Lookup in project: "
(projectile-symbol-at-point)))))
(xref--show-xrefs (xref-references-in-directory symbol project-root)
nil))))
@@ -4632,13 +4631,9 @@ A thin wrapper around `xref-references-in-directory'."
(cond
((fboundp 'ggtags-find-tag-dwim)
'ggtags-find-tag-dwim)
- ((fboundp 'xref-find-definitions)
- 'xref-find-definitions)
- ((fboundp 'etags-select-find-tag)
- 'etags-select-find-tag)))
+ (t 'xref-find-definitions)))
((eq projectile-tags-backend 'xref)
- (when (fboundp 'xref-find-definitions)
- 'xref-find-definitions))
+ 'xref-find-definitions)
((eq projectile-tags-backend 'ggtags)
(when (fboundp 'ggtags-find-tag-dwim)
'ggtags-find-tag-dwim))