]> git.eshelyaron.com Git - emacs.git/commitdiff
xref-matches-in-files: Move sorting to Lisp
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 17 Sep 2021 12:39:23 +0000 (15:39 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 17 Sep 2021 12:39:36 +0000 (15:39 +0300)
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

index ab7e8f6e29ef6b0906baf96fd2ed53ed798cf258..69cabd0b5a587ceb171a6922c30b65a02d0c7e8b 100644 (file)
@@ -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