unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#34343: [PATCH] Make project--find-regexp-in-files work with remote files
@ 2019-02-06  8:18 Felicián Németh
  2019-02-14  1:17 ` Dmitry Gutov
  0 siblings, 1 reply; 38+ messages in thread
From: Felicián Németh @ 2019-02-06  8:18 UTC (permalink / raw)
  To: 34343


[-- Attachment #1.1: Type: text/plain, Size: 306 bytes --]

Hi,

The attached patch enhances the remote file support of project.el. It also
has a new "require" statement, which might be problematic.  Additionally,
project--collect-matches will look very similar to xref-collect-matches
creating a chance to unify the two functions later.

Thanks,
Felicián

[-- Attachment #1.2: Type: text/html, Size: 389 bytes --]

[-- Attachment #2: 0001-Make-project-find-regexp-in-files-work-with-remote-f.patch --]
[-- Type: text/x-patch, Size: 3382 bytes --]

From 6f65ec9462eebfd405768e1b2c730fc3f4e65b4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= <felician.nemeth@gmail.com>
Date: Wed, 6 Feb 2019 08:59:34 +0100
Subject: [PATCH] Make project--find-regexp-in-files work with remote files

* project.el: Require seq.
(project--collect-matches): New function extracted
from project--find-regexp-in-files; handle remote files.
(project--find-regexp-in-files): Group files based on their
remote-id, call the new function on the groups.
---
 lisp/progmodes/project.el | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 815cc7cd3d..5833e6401b 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -88,6 +88,7 @@
 ;;; Code:
 
 (require 'cl-generic)
+(require 'seq)
 
 (defvar project-find-functions (list #'project-try-vc)
   "Special hook to find the project containing a given directory.
@@ -374,12 +375,29 @@ project-or-external-find-regexp
     (project--find-regexp-in-files regexp files)))
 
 (defun project--find-regexp-in-files (regexp files)
+  (let* ((xref-groups
+          (mapcar
+           (lambda (group)
+             (let* ((files (cdr group))
+                    (local-files (mapcar #'file-local-name files))
+                    (dir (file-name-directory (car files))))
+               (project--collect-matches regexp local-files dir)))
+           (seq-group-by #'file-remote-p files)))
+         (xrefs (apply #'append xref-groups)))
+    (unless xrefs
+      (user-error "No matches for: %s" regexp))
+    (xref--show-xrefs xrefs nil)))
+
+(defun project--collect-matches (regexp files dir)
+  "Collect matches for REGEXP inside FILES in DIR.
+FILES is a list of file names."
+  ;; Cf. `xref-collect-matches'.
   (pcase-let*
       ((output (get-buffer-create " *project grep output*"))
        (`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist))
        (status nil)
        (hits nil)
-       (xrefs nil)
+       (remote-id (file-remote-p dir))
        (command (format "xargs -0 grep %s -nHe %s"
                         (if (and case-fold-search
                                  (isearch-no-upper-case-p regexp t))
@@ -390,6 +408,7 @@ project--find-regexp-in-files
       (erase-buffer)
       (with-temp-buffer
         (insert (mapconcat #'identity files "\0"))
+        (setq default-directory dir)
         (setq status
               (project--process-file-region (point-min)
                                             (point-max)
@@ -407,13 +426,10 @@ project--find-regexp-in-files
                     (buffer-substring (point-min) (line-end-position))))
       (while (re-search-forward grep-re nil t)
         (push (list (string-to-number (match-string line-group))
-                    (match-string file-group)
+                    (concat remote-id (match-string file-group))
                     (buffer-substring-no-properties (point) (line-end-position)))
               hits)))
-    (setq xrefs (xref--convert-hits (nreverse hits) regexp))
-    (unless xrefs
-      (user-error "No matches for: %s" regexp))
-    (xref--show-xrefs xrefs nil)))
+    (xref--convert-hits (nreverse hits) regexp)))
 
 (defun project--process-file-region (start end program
                                      &optional buffer display
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2021-07-25  6:41 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-06  8:18 bug#34343: [PATCH] Make project--find-regexp-in-files work with remote files Felicián Németh
2019-02-14  1:17 ` Dmitry Gutov
2019-02-15 18:53   ` Felicián Németh
     [not found]     ` <a54e7498-4ead-dd6f-6a2e-3919ab035b23@yandex.ru>
2019-02-27  9:15       ` Michael Albinus
2019-03-06  7:47         ` Felicián Németh
2019-03-06 14:33           ` Dmitry Gutov
2019-03-06 14:44             ` Dmitry Gutov
2019-03-08  8:28               ` Felicián Németh
2019-12-26 14:04                 ` Dmitry Gutov
2019-12-27  8:24                   ` Michael Albinus
2019-12-27 14:18                     ` Dmitry Gutov
2019-12-27 17:57                       ` Michael Albinus
2019-12-28 10:21                         ` Michael Albinus
2019-12-28 14:48                           ` Dmitry Gutov
2019-12-28 18:56                             ` Michael Albinus
2019-12-28 14:46                         ` Dmitry Gutov
2019-12-28 18:46                           ` Michael Albinus
2019-12-29  0:15                             ` Dmitry Gutov
2019-12-29 12:34                               ` Michael Albinus
2019-12-29 13:14                                 ` Dmitry Gutov
2020-01-01 12:29                                   ` Michael Albinus
2020-01-02  1:22                                     ` Dmitry Gutov
2020-01-02 10:48                                       ` Michael Albinus
2020-01-03  0:52                                         ` Dmitry Gutov
2020-01-03  9:28                                           ` Michael Albinus
2020-01-06 14:33                                             ` Dmitry Gutov
2020-01-06 18:48                                               ` Michael Albinus
2020-01-07  3:23                                                 ` Dmitry Gutov
2020-01-07  9:19                                                   ` Michael Albinus
2020-01-07 13:40                                                     ` Dmitry Gutov
2020-01-07 14:29                                                       ` Michael Albinus
2020-01-07 14:34                                                         ` Dmitry Gutov
2021-07-22 13:00                                                           ` Lars Ingebrigtsen
2021-07-24 19:42                                                             ` Dmitry Gutov
2021-07-25  6:41                                                               ` Lars Ingebrigtsen
2020-01-03  0:57                                         ` Dmitry Gutov
2020-01-06 17:29                     ` Felician Nemeth
2020-01-07  3:23                       ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).