]> git.eshelyaron.com Git - emacs.git/commitdiff
Add quoted filename support to 'project-find-regexp' (Bug#47799).
authorPhilipp Stephani <phst@google.com>
Sun, 18 Apr 2021 19:47:53 +0000 (21:47 +0200)
committerPhilipp Stephani <phst@google.com>
Sun, 18 Apr 2021 19:59:25 +0000 (21:59 +0200)
This is only a band-aid; it would be better to fix xref.el to work
with quoted filenames as well.

* lisp/progmodes/project.el (project--find-regexp-in-files): Unquote
filenames before passing them to 'xref-matches-in-files'.
* test/lisp/progmodes/project-tests.el (project/quoted-directory):
Also test 'project-find-regexp'.

lisp/progmodes/project.el
test/lisp/progmodes/project-tests.el

index 1023b75e6686ff1b5139fab89e9aa06cca530159..1d0d1bc58a4c24e0165aa0f89b03696d2ea084fd 100644 (file)
@@ -787,7 +787,11 @@ pattern to search for."
 (defun project--find-regexp-in-files (regexp files)
   (unless files
     (user-error "Empty file list"))
-  (let ((xrefs (xref-matches-in-files regexp files)))
+  (let ((xrefs (xref-matches-in-files
+                regexp
+                ;; FIXME: `xref-matches-in-files' should work with
+                ;; quoted filenames.
+                (mapcar #'file-name-unquote files))))
     (unless xrefs
       (user-error "No matches for: %s" regexp))
     xrefs))
index 829f52adeccd0365549b36bf9890f7a88353ead2..bb58f80d1811b12b67f0757bb9ccc83d2df0071d 100644 (file)
 (require 'project)
 
 (require 'ert)
+(require 'grep)
+(require 'xref)
 
 (ert-deftest project/quoted-directory ()
-  "Check that `project-files' deals with quoted directory
-names (Bug#47799)."
+  "Check that `project-files' and `project-find-regexp' deal with
+quoted directory names (Bug#47799)."
   (skip-unless (executable-find find-program))
+  (skip-unless (executable-find "xargs"))
+  (skip-unless (executable-find "grep"))
   (let ((directory (make-temp-file "project-tests-" :directory)))
     (unwind-protect
         (let ((default-directory directory)
@@ -42,11 +46,30 @@ names (Bug#47799)."
                (expand-file-name "projects" directory))
               (project (cons 'transient (file-name-quote directory)))
               (file (expand-file-name "file" directory)))
-          (make-empty-file file)
           (add-hook 'project-find-functions (lambda (_dir) project))
           (should (eq (project-current) project))
+          (write-region "contents" nil file nil nil nil 'excl)
           (should (equal (project-files project)
-                         (list (file-name-quote file)))))
+                         (list (file-name-quote file))))
+          (let* ((references nil)
+                 (xref-search-program 'grep)
+                 (xref-show-xrefs-function
+                  (lambda (fetcher _display)
+                    (push (funcall fetcher) references))))
+            (project-find-regexp "tent")
+            (pcase references
+              (`((,item))
+               (should
+                ;; FIXME: Shouldn't `xref-match-item' be a subclass of
+                ;; `xref-item'?
+                (cl-typep item '(or xref-item xref-match-item)))
+               (should
+                (file-equal-p
+                 (xref-location-group (xref-item-location item))
+                 file)))
+              (otherwise
+               (ert-fail (format-message "Unexpected references: %S"
+                                         otherwise))))))
       (delete-directory directory :recursive))))
 
 ;;; project-tests.el ends here