branch: externals/urgrep
commit 78e8e8c2e808c038b317cca981825dd2f81258f4
Author: Jim Porter <jporterb...@gmail.com>
Commit: Jim Porter <jporterb...@gmail.com>

    Use the compat package to handle forward-compatibility shims; resolves #4
---
 .github/workflows/build.yml |  3 +++
 .gitignore                  |  1 +
 Makefile                    | 26 ++++++++++++++++++++++++--
 urgrep-tests.el             |  4 +---
 urgrep.el                   | 26 +++++---------------------
 5 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index d66f5863cb..d0a582890b 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -19,6 +19,9 @@ jobs:
       - uses: purcell/setup-emacs@master
         with:
           version: ${{ matrix.emacs-version }}
+      - name: Install dependencies
+        run: |
+          make install-deps
       - name: Run tests
         run: |
           make check
diff --git a/.gitignore b/.gitignore
index c531d9867f..ebf8ad55c6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
+/.deps
 *.elc
diff --git a/Makefile b/Makefile
index c176bced3f..5bde538680 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,28 @@
 EMACS ?= emacs
+export DEPS_DIR = $(shell realpath .deps)
+
+define INSTALL_SCRIPT
+(progn
+  (setq package-user-dir (getenv "DEPS_DIR"))
+  (package-refresh-contents)
+  (if-let ((reqs (package-desc-reqs (package-buffer-info)))
+           (transaction (package-compute-transaction nil reqs)))
+      (progn
+        (message "Installing %s..."
+                 (mapconcat (quote package-desc-full-name) transaction ", "))
+        (package-download-transaction transaction))
+    (message "Nothing to install")))
+endef
+export INSTALL_SCRIPT
+
+.PHONY: install-deps
+install-deps:
+       @$(EMACS) -Q --batch urgrep.el --eval "$$INSTALL_SCRIPT"
 
 .PHONY: check
 check:
-       $(EMACS) -Q --batch -L . -l urgrep -l urgrep-tests \
-       --eval '(ert-run-tests-batch-and-exit t)'
+       $(EMACS) -Q --batch \
+         --eval '(setq package-user-dir (getenv "DEPS_DIR"))' \
+         --eval '(package-activate-all)' \
+         -L . -l urgrep -l urgrep-tests \
+         --eval '(ert-run-tests-batch-and-exit t)'
diff --git a/urgrep-tests.el b/urgrep-tests.el
index 1aa59184c5..c4c776c39b 100644
--- a/urgrep-tests.el
+++ b/urgrep-tests.el
@@ -27,6 +27,7 @@
 
 ;;; Code:
 
+(require 'compat)
 (require 'ert)
 (require 'tramp)
 
@@ -36,9 +37,6 @@
   (when (< emacs-major-version 29)
     (setenv "HOME" orig-home)))
 
-(unless (fboundp 'always)
-  (defun always (&rest _) t))
-
 (defun urgrep-tests/remote-accessible-p ()
   "Return whether a test involving remote files can proceed."
   (let ((inhibit-message t))
diff --git a/urgrep.el b/urgrep.el
index 620973c4d3..930396441f 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -6,7 +6,7 @@
 ;; URL: https://github.com/jimporter/urgrep
 ;; Version: 0.1-git
 ;; Keywords: grep, search
-;; Package-Requires: ((emacs "27.1") (project "0.2.0"))
+;; Package-Requires: ((emacs "27.1") (compat "29.1.0.1") (project "0.3.0"))
 
 ;; This file is NOT part of GNU Emacs.
 
@@ -32,6 +32,7 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'compat)
 (require 'compile)
 (require 'esh-opt)
 (require 'generator)
@@ -113,23 +114,6 @@ The currently-used tool can be inspected from the hook via
 
 ;; Urgrep utility functions
 
-;; `format-prompt' was added in Emacs 28.1.
-(defalias 'urgrep--format-prompt
-  (if (fboundp 'format-prompt)
-      #'format-prompt
-    (lambda (prompt default &rest format-args)
-      (concat
-       (apply #'format prompt format-args)
-       (when default
-         (format " (default %s)" default))
-       ": "))))
-
-;; `project-root' was added in project.el 0.3.0 (Emacs 28.1).
-(defalias 'urgrep--project-root
-  (if (fboundp 'project-root)
-      #'project-root
-    (lambda (project) (car (project-roots project)))))
-
 (defun urgrep--convert-regexp (expr from-syntax to-syntax)
   "Convert the regexp EXPR from FROM-SYNTAX to TO-SYNTAX."
   (cond ((and (not (eq from-syntax to-syntax))
@@ -472,7 +456,7 @@ This caches the default tool per-host in 
`urgrep--host-defaults'."
             (when-let (((and tool-vc-backend (not vc-backend-name)))
                        (proj (project-current)))
               (setq vc-backend-name (vc-responsible-backend
-                                     (urgrep--project-root proj))))
+                                     (project-root proj))))
             ;; If we find the executable (and it's for the right VC
             ;; backend, if relevant), cache it and then return it.
             (when (and (executable-find tool-executable t)
@@ -956,7 +940,7 @@ point."
   "Return the prompt to use when asking for the search query.
 This depends on the current values of various urgrep options.  DEFAULT
 indicates the default query, if any."
-  (urgrep--format-prompt
+  (format-prompt
    (concat
     "Search "
     (if urgrep-search-regexp "regexp" "string")
@@ -1110,7 +1094,7 @@ value is 4, return the current directory.  Otherwise, 
prompt for the
 directory."
   (cond
    ((not arg) (let ((proj (project-current)))
-                (if proj (urgrep--project-root proj) default-directory)))
+                (if proj (project-root proj) default-directory)))
    ((= (prefix-numeric-value arg) 4) default-directory)
    (t (read-directory-name "In directory: " nil nil t))))
 

Reply via email to