3 minute read

Emacs를 설치하고 Doom Emacs 세팅한 후 실행하면 뭔가 비주얼이 이상하다. 필요한 폰트를 설치 안 했구나. Mermaid 같을 걸 실행하면 실패한다. 필요한 프로그램을 설치 안 했구나. 이런 걸 미리 편하게 검사할 수 있지 않을까? 설치하는 김에 한 번에 설치를 다 하게 말이다. 설치 스크립트로 다 안 되는 것도 있으니깐 검사만 해도 괜찮다.

Doom Emacs Configuration - tecosaur.github.io’ 글에서 개인 설정에 대한 doctor.el 파일을 구현한 걸 봤다. 맞네. doom doctor 를 사용하면 손쉽게 구현할 수 있겠다.

doom doctor?

doom doctor to diagnose common issues with your system and config.

doomemacs/doomemacs - github.com

doom doctor 는 시스템과 설정을 진단한다. 모듈에 doctor.el 파일만 정의하면 doom doctor 명령어를 실행할 때, 같이 실행해 준다. 개인 설정은 어떻게 doom emacs에 로드될까? 모듈로 로드된다. 즉, 개인 설정 디렉터리에 doctor.el 파일을 정의하면 개인 설정에도 doom doctor 명령어를 사용할 수 있다.

Your system, your rules. You know better. At least, Doom hopes so! It won’t automatically install system dependencies (and will force plugins not to either). Rely on doom doctor to tell you what’s missing.

나만의 시스템, 나만의 규칙. 잘 알잖아요. 적어도 Doom은 그러길 바랍니다! 시스템 종속성을 자동으로 설치하지 않으며 플러그인 역시 설치하지 않습니다. 무엇이 누락되었는지 doom doctor가 알려줄 것입니다.

doomemacs/doomemacs - github.com

doom doctor 명령은 사용자의 시스템과 룰을 존중하는 데서 시작한다. 자동으로 설치하지 않고 무엇이 누락되었는지를 알려준다. 바로 doom doctor 가 하는 일이다.

폰트 설치 검증

fc-list 프로그램으로 폰트 설치 유무를 검사한다. 먼저 이 프로그램이 설치됐는지 확인해야 한다. Windows에서는 ’Git for windows SDK’ 패키지에서 제공하는 Bash를 셸로 사용하고 있다. fc-list 프로그램을 자동으로 설치하지 않기에 프로그램이 있는지 검사한다.

config.el 설정 파일이 있는 디렉터리에 doctor.el 파일을 만든다.

;;; doctor.el -*- lexical-binding: t; no-byte-compile: t; -*-

(unless (executable-find "fc-list")
  (error! "Couldn't find fc-list executable.")
  (pcase doom-system
    ('windows (error! "Need to install packages
pacman -S mingw64/mingw-w64-x86_64-gettext
pacman -S mingw64/mingw-w64-x86_64-fontconfig
"))
    ('macos   (error! "TODO Description of the `fc-list` program installation instructions"))
    ('linux   (error! "TODO Description of the `fc-list' program installation instructions"))))

필요한 외부 프로그램 검사 후 error!, warn! 함수 등을 사용해서 메시지를 적으면 doom doctor가 다 알아서 해준다.

$ doom doctor
The doctor will see you now...

  > Checking your enabled modules...
    > :user nil
      x Need to install packages
        pacman -S mingw64/mingw-w64-x86_64-gettext
        pacman -S mingw64/mingw-w64-x86_64-fontconfig

      x Couldn't find fc-list executable.

설치 방법까지 알려주다니 친절하다. 이 정도면 됐다. 이제 폰트를 검사할 차례다.

required-fonts 심볼에 사용할 폰트 이름을 리스트로 정의한다. fc-list 프로그램을 실행해서 현재 설치된 폰트 리스트를 구한다. 설치된 폰트 리스트에 사용할 폰트가 다 있는지 확인한다.

;; Make sure required fonts are installed
;; ref: https://tecosaur.github.io/emacs-config/config.html
(let (required-fonts available-fonts missing-fonts)
  (setq required-fonts '("Consolas" "D2Coding"))

  (setq available-fonts
        (delete-dups
         (or (font-family-list)
             (and (executable-find "fc-list")
                  (with-temp-buffer
                    (call-process "fc-list" nil t nil ":" "family")
                    (split-string (buffer-string) "[,\n]"))))))

  (setq missing-fonts
        (delq nil (mapcar
                   (lambda (font)
                     (unless (delq nil (mapcar (lambda (f)
                                                 (string-match-p (format "^%s$" font) f))
                                               available-fonts))
                       font))
                   required-fonts)))

  (if available-fonts
      (dolist (font missing-fonts)
        (error! (format "Missing font: %s" font)))
    (error! "Unable to check for missing fonts, is fc-list installed?")))

폰트를 설치하기 전 doom doctor 를 실행하면 아래와 같은 진단 메시지가 뜬다.

$ doom doctor
  > Checking your enabled modules...
    > :user nil
      x Missing font: D2Coding
      x Missing font: Consolas

실행 파일 검증

외부 프로그램 중에 dotfiles 스크립트로 설치하기 애매한 프로그램을 검증하는 코드를 doctor.el 파일에 추가한다.

(defun my-doctor--executable! (path install-guide)
  (unless (executable-find path)
    (warn! "Couldn't find '%s'.\ninstallation guide\n%s" path install-guide)))

(when (featurep :system 'windows)
  (my-doctor--executable! mermaid-mmdc-location
                          "cd ~/bin.local;mkdir mermaid-cli;cd mermaid-cli;npm install @mermaid-js/mermaid-cli")
  (my-doctor--executable! ob-mermaid-cli-path
                          "cd ~/bin.local;mkdir mermaid-cli;cd mermaid-cli;npm install @mermaid-js/mermaid-cli")
  (my-doctor--executable! "es"
                          "winget install --id=voidtools.Everything.Cli -e"))

mermaid-cli 는 dotfiles 설치 스크립트로 설치하기 애매하다. WinGet으로 설치하는 건 dotfiles 설치 스크립트에 넣을까 생각 중이다. 이제 웬만한 Windows 프로그램은 WinGet으로 설치가 가능하다. Homebrew 안 부럽다.

마치며

디자인이 좋다. 모듈에 doctor를 구현한다. 개인 설정을 모듈로 빌드한다. 개인 설정에도 doctor를 사용할 수 있다.

어떤 걸 dotfiles 설치 스크립트로 설치해야 할까? 어떤 건 설치까지는 하지 말고 doom doctor 명령어로 검사만 하고 설치 방법을 알려줘야 할까? doom doctor 라는 좋은 옵션이 생기니 선택에 대한 고민이 따라온다. 설치 방법이 명료하고 필요한 건 dotfiles 설치 스크립트에 넣는다. 설치가 커맨드라인으로 매끄럽지 않고 상황마다 다를 것 같다. 꼭 해야 하는 건 아니고 설치를 안 해도 되긴 된다. 이런 건 doom doctor 명령어로 검사하게 할 생각이다.

길고 자세한 매뉴얼도 좋지만 doom doctor 명령어처럼 실행 가능한 검증 프로그램이 더 편하다. doom doctor 만 실행해서 경고와 에러를 잡아가면 최적의 실행 환경이 되는 것이다.

링크

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