]> git.eshelyaron.com Git - emacs.git/commitdiff
Hide the common parent directory, if any
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Dec 2020 00:36:04 +0000 (02:36 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Dec 2020 01:01:34 +0000 (03:01 +0200)
* lisp/progmodes/xref.el (xref--show-defs-minibuffer):
Hide the common parent directory, if any.

lisp/progmodes/xref.el

index 363d118cf7d7e0da27b3c31b98811d9d20ad3196..e304a7beae2ff98b2348ea65af3f39e46a2e0116 100644 (file)
@@ -935,7 +935,15 @@ local keymap that binds `RET' to `xref-quit-and-goto-xref'."
   (let* ((xrefs (funcall fetcher))
          (xref-alist (xref--analyze xrefs))
          xref-alist-with-line-info
-         xref)
+         xref
+         (group-prefix-length
+          ;; FIXME: Groups are not always file names, but they often
+          ;; are.  At least this shouldn't make the other kinds of
+          ;; groups look worse.
+          (let ((common-prefix (try-completion "" xref-alist)))
+            (if (> (length common-prefix) 0)
+                (length (file-name-directory common-prefix))
+              0))))
 
     (cl-loop for ((group . xrefs) . more1) on xref-alist
              do
@@ -944,10 +952,11 @@ local keymap that binds `RET' to `xref-quit-and-goto-xref'."
                         (with-slots (summary location) xref
                           (let* ((line (xref-location-line location))
                                  (line-fmt (if line (format "%s:" line) ""))
+                                 (group-fmt (substring group group-prefix-length))
                                  (candidate
                                   (if show-summary
-                                      (format "%s:%s%s" group line-fmt summary)
-                                    (format "%s" group))))
+                                      (format "%s:%s%s" group-fmt line-fmt summary)
+                                    (format "%s" group-fmt))))
                             (push (cons candidate xref) xref-alist-with-line-info))))))
 
     (setq xref (if (not (cdr xrefs))