>
> This works, for example:
>
> (defun xref--add-log-current-defun ()
> (if-let (item (xref--item-at-point))
> (xref-file-location-file (xref-match-item-location item))
> (xref--imenu-extract-index-name)))
>
> (setq-local add-log-current-defun-function #'xref--add-log-current-defun)
In fact, to respect the value of `xref-file-name-display' (which seems a good idea) a bit more complexity is required:
(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'."
(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))))
but that uncovers a different bug in xref--group-name-for-display:
(cl-ecase xref-file-name-display
(abs group)
(nondirectory
(if (string-match-p "\\`~?/" group)
(file-name-nondirectory group)
group))
that is, for the 'nondirectory case it tries to match against ~/filename or /filename, but (again) ignores absolute Windows paths with a drive letter.
That should be changed to
(cl-ecase xref-file-name-display
(abs group)
(nondirectory
- (if (string-match-p "\\`~?/" group)
+ (if (string-match-p "\\`\\(~\\|[A-Za-z]:\\)?/" group)
(file-name-nondirectory group)
group))
(project-relative
or something similar.