From: Dmitry Gutov Date: Sat, 18 May 2024 00:00:29 +0000 (+0300) Subject: xref--group-name-for-display: Undo most of the latest change X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2c4ca8744e6e87692a9d2d42d5673ab543913f2b;p=emacs.git xref--group-name-for-display: Undo most of the latest change * 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) --- diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index df95e517a40..f6f3729b47c 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -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))) diff --git a/test/lisp/progmodes/xref-tests.el b/test/lisp/progmodes/xref-tests.el index 39eab7c7fd1..89051256273 100644 --- a/test/lisp/progmodes/xref-tests.el +++ b/test/lisp/progmodes/xref-tests.el @@ -132,7 +132,6 @@ (lambda (loc) (xref--group-name-for-display (xref-location-group loc) - nil nil)) (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))) (list @@ -146,7 +145,6 @@ (lambda (loc) (xref--group-name-for-display (xref-location-group loc) - nil nil)) (xref-tests--locations-in-data-dir "\\(bar\\|foo\\)"))) (list @@ -163,8 +161,7 @@ (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"