[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/project-files-pipe-grep 035da09 1/2: project-files
From: |
Dmitry Gutov |
Subject: |
[Emacs-diffs] scratch/project-files-pipe-grep 035da09 1/2: project-files-pipe-grep: Use process-call-region |
Date: |
Mon, 7 Jan 2019 18:15:50 -0500 (EST) |
branch: scratch/project-files-pipe-grep
commit 035da09b0e84e5c86a600f79d8c311be61be3084
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
project-files-pipe-grep: Use process-call-region
Instead of running an asynchronous process and managing input/output in
Lisp.
Improves performance and moves closer to find+grep based
project-find-regexp.
---
lisp/progmodes/project.el | 43 +++++++++++++++++++------------------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 8936f5a..55d683f 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -362,39 +362,34 @@ pattern to search for."
((files (project-files (project-current t)))
(output (get-buffer-create " *project grep output*"))
(`(,grep-re ,file-group ,line-group . ,_) (car grep-regexp-alist))
- (command `("xargs" "-0" "grep"
- ,@(when (and case-fold-search
- (isearch-no-upper-case-p regexp t))
- (list "-i"))
- "-nHe"
- ,(shell-quote-argument (xref--regexp-to-extended regexp))))
+ (status nil)
(hits nil)
(xrefs nil)
- (process nil)
- (process-connection-type nil))
+ (command (format "xargs -0 -P 1 grep %s -nHe %s"
+ (if (and case-fold-search
+ (isearch-no-upper-case-p regexp t))
+ "-i"
+ "")
+ (shell-quote-argument (xref--regexp-to-extended
regexp)))))
(with-current-buffer output
(erase-buffer)
- (setq process
- (apply
- #'start-process
- "project-files-pipe-to-grep"
- output
- command))
- (dolist (f files)
- (process-send-string process f)
- (process-send-string process "\0"))
- (process-send-eof process)
- (with-local-quit
- (while (process-live-p process)
- (accept-process-output process 1)))
- (when quit-flag
- (delete-process process))
+ (with-temp-buffer
+ (insert (mapconcat #'identity files "\0"))
+ (setq status
+ (call-process-region (point-min)
+ (point-max)
+ shell-file-name
+ nil
+ output
+ nil
+ shell-command-switch
+ command)))
(goto-char (point-min))
(when (and (/= (point-min) (point-max))
(not (looking-at grep-re))
;; TODO: Show these matches as well somehow?
(not (looking-at "Binary file .* matches")))
- (user-error "Search failed with status %d: %s" (process-exit-status
process)
+ (user-error "Search failed with status %d: %s" status
(buffer-substring (point-min) (line-end-position))))
(while (re-search-forward grep-re nil t)
(push (list (string-to-number (match-string line-group))