emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9ca737c: xref-matches-in-files: Move sorting to Lisp


From: Dmitry Gutov
Subject: master 9ca737c: xref-matches-in-files: Move sorting to Lisp
Date: Fri, 17 Sep 2021 08:40:01 -0400 (EDT)

branch: master
commit 9ca737c4198c5e7faef7a74de7b1e84b11e1dbeb
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    xref-matches-in-files: Move sorting to Lisp
    
    For better compatibility with different systems.
    Performance is unaffected, except in very pathological cases
    (~100000 matches), and even then the overhead of 'sort' is comparable.
    
    * lisp/progmodes/xref.el (xref-search-program-alist):
    Drop the piping through 'sort'.
    (xref-matches-in-files): Sort here instead.
    Do that to both searchers' output as well now.
---
 lisp/progmodes/xref.el | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index ab7e8f6..69cabd0 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1625,13 +1625,8 @@ IGNORES is a list of glob patterns for files to ignore."
      "xargs -0 grep <C> -snHE -e <R>")
     (ripgrep
      .
-     ;; Note: by default, ripgrep's output order is non-deterministic
-     ;; (https://github.com/BurntSushi/ripgrep/issues/152)
-     ;; because it does the search in parallel.  You can use the template
-     ;; without the '| sort ...' part if GNU sort is not available on
-     ;; your system and/or stable ordering is not important to you.
-     ;; Note#2: '!*/' is there to filter out dirs (e.g. submodules).
-     "xargs -0 rg <C> -nH --no-messages -g '!*/' -e <R> | sort -t: -k1,1 
-k2n,2"
+     ;; '!*/' is there to filter out dirs (e.g. submodules).
+     "xargs -0 rg <C> -nH --no-messages -g '!*/' -e <R>"
      ))
   "Associative list mapping program identifiers to command templates.
 
@@ -1723,7 +1718,16 @@ FILES must be a list of absolute file names."
                     (match-string file-group)
                     (buffer-substring-no-properties (point) 
(line-end-position)))
               hits)))
-    (xref--convert-hits (nreverse hits) regexp)))
+    ;; By default, ripgrep's output order is non-deterministic
+    ;; (https://github.com/BurntSushi/ripgrep/issues/152)
+    ;; because it does the search in parallel.
+    ;; Grep's output also comes out in seemingly arbitrary order,
+    ;; though stable one. Let's sort both for better UI.
+    (setq hits
+          (sort (nreverse hits)
+                (lambda (h1 h2)
+                  (string< (cadr h1) (cadr h2)))))
+    (xref--convert-hits hits regexp)))
 
 (defun xref--process-file-region ( start end program
                                    &optional buffer display



reply via email to

[Prev in Thread] Current Thread [Next in Thread]