Last active
July 15, 2025 21:21
-
-
Save jdtsmith/57c9c94bc916b58c0e4ebfc01d300bf1 to your computer and use it in GitHub Desktop.
Redirect xref on elisp to the source-directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun my/elisp-xref-find-def-in-source (sym) | |
| "Find elisp files in the source directory." | |
| (let* ((elisp-xref-find-def-functions nil) ; recurses otherwise | |
| (records (elisp--xref-find-definitions sym))) | |
| (dolist (rec records) | |
| (when-let* ((file (xref-elisp-location-file (xref-item-location rec))) | |
| ( (and (stringp file) | |
| (string-match (rx ".el" (? ".gz") eos) file) | |
| (file-in-directory-p file lisp-directory))) | |
| (relname (file-relative-name file lisp-directory)) | |
| (src-name (file-name-concat | |
| source-directory "lisp" | |
| (string-trim-right relname "\\.gz"))) | |
| ( (file-exists-p src-name))) | |
| (setf (xref-elisp-location-file (xref-item-location rec)) src-name))) | |
| records)) | |
| (add-to-list 'elisp-xref-find-def-functions 'my/elisp-xref-find-def-in-source) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you compile your own emacs, you might prefer to have
xrefvisit elisp files in the original source directory, not in the install directory. This small function arranges for that to happen by translating file paths for (compressed) elisp files fromlisp-directorytosource-directory/lisp