---
title: "#LLM: xref 정의 참조 검색 #이맥스"
url: "https://notes.junghanacs.com/notes/20250124T103402"
author: "Junghan Kim"
date: "2025-01-24T10:34:00+09:00"
lastmod: "2025-01-24T10:34:00+09:00"
description: "이맥스 xref가 정의와 참조 검색에서 어떻게 동작하는지 정리한 로그이다."
---

> [!abstract] 이 노트에 대하여
> 
> xref와 Doom의 lookup 설정을 함께 보며 정의 찾기와 참조 찾기 흐름이 어떻게 연결되는지 확인한다. Emacs 코드 탐색의 기본 메커니즘을 이해하는 데 도움이 되는 기술 노트다.

## #Related-Notes

-   

## BIBLIOGRAPHY

## 둠이맥스 - 키바인딩 참고

/home/junghan/doomemacs-git/modules/tools/lookup/config.el

```elisp
;;; xref

;; The lookup commands are superior, and will consult xref if there are no
;; better backends available.
(global-set-key [remap xref-find-definitions] #'+lookup/definition)
(global-set-key [remap xref-find-references]  #'+lookup/references)

(after! xref
  ;; We already have `projectile-find-tag' and `evil-jump-to-tag', no need for
  ;; xref to be one too.
  (remove-hook 'xref-backend-functions #'etags--xref-backend)
  ;; ...however, it breaks `projectile-find-tag', unless we put it back.
  (defadvice! +lookup--projectile-find-tag-a (fn)
    :around #'projectile-find-tag
    (let ((xref-backend-functions '(etags--xref-backend t)))
      (funcall fn)))

  ;; This integration is already built into evil
  (unless (modulep! :editor evil)
    ;; Use `better-jumper' instead of xref's marker stack
    (advice-add #'xref-push-marker-stack :around #'doom-set-jump-a))

  (use-package! ivy-xref
    :when (modulep! :completion ivy)
    :config
    (set-popup-rule! "^\\*xref\\*$" :ignore t)
    (setq xref-show-definitions-function #'ivy-xref-show-defs
          xref-show-xrefs-function       #'ivy-xref-show-xrefs)

    ;; HACK Fix #4386: `ivy-xref-show-xrefs' calls `fetcher' twice, which has
    ;; side effects that breaks in some cases (i.e. on `dired-do-find-regexp').
    (defadvice! +lookup--fix-ivy-xrefs (fn fetcher alist)
      :around #'ivy-xref-show-xrefs
      (when (functionp fetcher)
        (setf (alist-get 'fetched-xrefs alist)
              (funcall fetcher)))
      (funcall fn fetcher alist)))

  (use-package! helm-xref
    :when (modulep! :completion helm))

  (use-package! consult-xref
    :when (modulep! :completion vertico)
    :defer t
    :init
    (setq xref-show-xrefs-function       #'consult-xref
          xref-show-definitions-function #'consult-xref)))


;;
```

## [2025-01-24 W03](https://notes.junghanacs.com/journal/20250120T000000)

@user xref 는 이맥스에서 무엇인가?

@assistant Emacs에서 `xref` 는 **식별자** 의 정의와 참조를 빠르게 찾는 데 사용되는 플러그인 가능한 서브시스템입니다. 이는 다양한 백엔드를 지원하여, 식별자의 정의와 참조를 쉽게 탐색하고 이름을 변경할 수 있도록 도와줍니다[2]. `xref` 는 여러 백엔드와 함께 사용되어, 다양한 프로그래밍 언어에서 식별자를 처리할 수 있습니다.

@user
