Flycheck 에러를 Eldoc 패키지로 표시

1 minute read

Emacs 하단에 있는 Echo Area에 간단한 문서를 즉시 볼 수 있게 해주는 Emacs 패키지다. 겸손한 알림이 가장 큰 장점이다. 관련된 정보가 있다면 슬그머니 Echo Area에 보여준다. 문서 작성을 방해하지 않는다.

ElDoc 기본 세팅

(after! eldoc
  ;; =M-x eldoc-doc-buffer= 함수 호출로 표시하는 buffer 크기 조절
  (set-popup-rule! "^\\*eldoc for" :size 0.2 :vslot -1)

  ;; eldoc을 여러 백엔드에서 수집해서 보여줄 수 있게 한다
  (setq eldoc-documentation-strategy 'eldoc-documentation-compose-eagerly
        ;; echo area에 최대 4줄까지 보여주게 함
        eldoc-echo-area-use-multiline-p 4))

Seamlessly Merge Multiple Documentation Sources with Eldoc - Mastering Emacs …’ 글을 참고했다. Use-package 패키지를 사용하는 코드를 Doom Emacs에서 제공하는 코드로 변경했다. 문서가 길면 잘라서 echo area에 보여준다. 문서 전체를 보고 싶으면 M-x eldoc-doc-buffer 함수를 실행해서 버퍼로 여러 전체 내용을 볼 수 있다. 1/5 영역을 하단에 보여주게 Popup 설정했다.

Flycheck 연동

Eldoc, the go-to Emacs package for on-the-fly documentation display, just got even better. Emacs 28 adds support for multiple documentation backends. Now you can read error messages from your linter or compiler and see code documentation at the same time.

Seamlessly Merge Multiple Documentation Sources with Eldoc - Mastering Emacs …

Eldoc에 여러 문서 백엔드를 추가할 수 있는 기능이 Emacs 28에 들어갔다. 이 기능을 사용해서 즉석(on-the-fly) 문법 체크 패키지인 Flycheck 에러를 eldoc으로 출력할 수 있다.

Doom Emacs 모듈이 추가한 flycheck-popup-tip 패키지를 비활성화한다. 툴팁으로 Flycheck 에러를 표시하는 패키지다.

(package! flycheck-popup-tip :disable t)

Flycheck error를 Eldoc 패키지로 출력한다. ’Seamlessly Merge Multiple Documentation Sources with Eldoc - Mastering Emacs …’ 글에서 코드를 가져와 Doom Emacs에 맞게 변경했다.

(use-package flycheck
  :preface

  (defun my/flycheck-eldoc (callback &rest _ignored)
    "Print flycheck messages at point by calling CALLBACK."
    (when-let ((flycheck-errors (and flycheck-mode (flycheck-overlay-errors-at (point)))))
      (mapc
       (lambda (err)
         (funcall callback
                  (format "%s: %s"
                          (let ((level (flycheck-error-level err)))
                            (pcase level
                              ('info (propertize "I" 'face 'flycheck-error-list-info))
                              ('error (propertize "E" 'face 'flycheck-error-list-error))
                              ('warning (propertize "W" 'face 'flycheck-error-list-warning))
                              (_ level)))
                          (flycheck-error-message err))
                  :thing (or (flycheck-error-id err)
                             (flycheck-error-group err))
                  :face 'font-lock-doc-face))
       flycheck-errors)))

  (defun mp-flycheck-prefer-eldoc ()
    (add-hook 'eldoc-documentation-functions #'mp-flycheck-eldoc nil t)
    (setq flycheck-display-errors-function nil)
    (setq flycheck-help-echo-function nil))

  :hook ((flycheck-mode . mp-flycheck-prefer-eldoc)))

이제 Flycheck 에러 메시지도 겸손하게 Eldoc 패키지가 echo area에 보여준다.

링크

C-x C-s C-x C-c