]> git.eshelyaron.com Git - emacs.git/commitdiff
xref--group-name-for-display: Undo most of the latest change
authorDmitry Gutov <dmitry@gutov.dev>
Sat, 18 May 2024 00:00:29 +0000 (03:00 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 18 May 2024 18:52:40 +0000 (20:52 +0200)
* lisp/progmodes/xref.el (xref--group-name-for-display):
Remove the DD-SUFFIX parameter, returning the function more like
to how it was (bug#69233).
(xref--analyze, xref--add-log-current-defun):
Revert the previous change accordingly.

* test/lisp/progmodes/xref-tests.el: Undo the last change.

(cherry picked from commit 646b8da4a5ec8b4b4a8e461683ff0786a95d1f85)

lisp/progmodes/xref.el
test/lisp/progmodes/xref-tests.el

index df95e517a4027ebe0da3861652b65eaf8c5f03fb..f6f3729b47cc2522fe2beb5759057f97880ddbdc 100644 (file)
@@ -1148,15 +1148,11 @@ beginning of the line."
 (defun xref--add-log-current-defun ()
   "Return the string used to group a set of locations.
 This function is used as a value for `add-log-current-defun-function'."
-  (let ((project-root (xref--project-root (project-current))))
-    (xref--group-name-for-display
-     (if-let (item (xref--item-at-point))
-         (xref-location-group (xref-match-item-location item))
-       (xref--imenu-extract-index-name))
-     project-root
-     (and
-      (string-prefix-p project-root default-directory)
-      (substring default-directory (length project-root))))))
+  (xref--group-name-for-display
+   (if-let (item (xref--item-at-point))
+       (xref-location-group (xref-match-item-location item))
+     (xref--imenu-extract-index-name))
+   (xref--project-root (project-current))))
 
 (defun xref--next-error-function (n reset?)
   (when reset?
@@ -1288,15 +1284,12 @@ GROUP is a string for decoration purposes and XREF is an
       (xref--apply-truncation)))
   (run-hooks 'xref-after-update-hook))
 
-(defun xref--group-name-for-display (group project-root dd-suffix)
+(defun xref--group-name-for-display (group project-root)
   "Return GROUP formatted in the preferred style.
 
 The style is determined by the value of `xref-file-name-display'.
 If GROUP looks like a file name, its value is formatted according
-to that style.  Otherwise it is returned unchanged.
-
-PROJECT-ROOT is the root of the current project, if any.  DD-SUFFIX is
-the relative name of `default-directory' relative to the project root."
+to that style.  Otherwise it is returned unchanged."
   ;; XXX: The way we verify that it's indeed a file name and not some
   ;; other kind of string, e.g. Java package name or TITLE from
   ;; `tags-apropos-additional-actions', is pretty lax.  But we don't
@@ -1310,15 +1303,10 @@ the relative name of `default-directory' relative to the project root."
     (nondirectory
      (file-name-nondirectory group))
     (project-relative
-     (cond
-      ((not (file-name-absolute-p group))
-       (concat dd-suffix group))
-      ((and project-root
-            (string-prefix-p project-root group))
-       (substring group (length project-root)))
-      ;; Default to absolute when there's not project around.
-      (t
-       (expand-file-name group))))))
+     (if (and project-root
+              (string-prefix-p project-root group))
+         (substring group (length project-root))
+       group))))
 
 (defun xref--analyze (xrefs)
   "Find common groups in XREFS and format group names.
@@ -1331,13 +1319,10 @@ Return an alist of the form ((GROUP . (XREF ...)) ...)."
                    (eq xref-file-name-display 'project-relative)
                    (project-current)))
          (project-root (and project
-                            (expand-file-name (xref--project-root project))))
-         (dd-suffix (and project-root
-                         (string-prefix-p project-root default-directory)
-                         (substring default-directory (length project-root)))))
+                            (expand-file-name (xref--project-root project)))))
     (mapcar
      (lambda (pair)
-       (cons (xref--group-name-for-display (car pair) project-root dd-suffix)
+       (cons (xref--group-name-for-display (car pair) project-root)
              (cdr pair)))
      alist)))
 
index 39eab7c7fd1669b850d02eec2b0d75cd84da2dae..8905125627331b3d352867c85cb7c78af9c2757c 100644 (file)
                (lambda (loc)
                  (xref--group-name-for-display
                   (xref-location-group loc)
-                  nil
                   nil))
                (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)")))
              (list
                      (lambda (loc)
                        (xref--group-name-for-display
                         (xref-location-group loc)
-                        nil
                         nil))
                      (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)")))
                    (list
                (lambda (loc)
                  (xref--group-name-for-display
                   (xref-location-group loc)
-                  data-parent-dir
-                  nil))
+                  data-parent-dir))
                (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)")))
              (list
               "xref-resources/file1.txt"