LoginSignup
15
8

More than 1 year has passed since last update.

Doom Emacs 入門

Last updated at Posted at 2021-03-09

背景

これまでVSCode、Vim、Spacemacs、Emacsを使用してきましたが、Doom Emacsのスター数が1万を突破したとのことで早速インストールしてみました。

インストール

こちらを参考にEmacs、Doom Emacsをインストールします。
Emacsのバーションは26.3以上が要求されます。
※26.3も今後サポートされなくなるそうなので、27以降が推奨です。

$ git clone https://github.com/hlissner/doom-emacs ~/.emacs.d

.emacs.dをダウンロード後に下記のコマンドを実行します。

$ ~/.emacs.d/bin/doom install

これでDoom Emacsが起動するようになります。

設定

Doom Emacsの設定は.doom.dフォルダ内の

  • init.el
  • package.el
  • config.el

を編集して設定します。

Doom Emacs起動中は、SPC f pを入力することで、
設定ファイルを開くことが出来ます。

init.el

Module Indexを参考に必要なモジュールを導入する事が出来ます。
コメントアウトを外したり、オプションを追加することで導入していきます。
下記は実際に追加したり、修正したモジュールです。

init.el
(doom! :input
       japanese

       :emacs
       (undo +tree)              ; persistent, smarter undo for your inevitable mistakes

       :term
       eshell            ; the elisp shell that works everywhere

       :lang
       (rust +lsp)              ; Fe2O3.unwrap().unwrap().unwrap().unwrap()

       :tools
       lsp
       )

package.el

Module Indexに無いパッケージを導入する場合はこのファイルに記述していきます。

package.el
(package! tr-ime)
(package! mozc)

(package! fussy)
(package! fuz-bin :recipe (:host github :repo "jcs-elpa/fuz-bin" :files (:defaults "bin")))

config.el

こちらのファイルはパッケージが読み込まれた後に呼ばれるファイルで、各パッケージの設定などを行います。

config.el
;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default:
(setq doom-theme 'doom-solarized-light)

;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/org/")

;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t)


;; Here are some additional functions/macros that could help you configure Doom:
;;
;; - `load!' for loading external *.el files relative to this one
;; - `use-package!' for configuring packages
;; - `after!' for running code after a package has loaded
;; - `add-load-path!' for adding directories to the `load-path', relative to
;;   this file. Emacs searches the `load-path' when you load packages with
;;   `require' or `use-package'.
;; - `map!' for binding new keys
;;
;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k').
;; This will open documentation for it, including demos of how they are used.
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.

(use-package tr-ime
  :if IS-WINDOWS
  :init
  (setq default-input-method "W32-IME")
  :config
  (tr-ime-standard-install)
  (w32-ime-initialize))

(use-package mozc
  :if IS-LINUX
  :init
  (setq default-input-method "japanese-mozc"))

(use-package fussy
  :after company vertico
  :init
  (add-to-list 'completion-styles 'fussy t)
  (add-to-list '+vertico-company-completion-styles 'fussy t)

  (setq completion-category-defaults nil
        completion-category-overrides nil
        fussy-filter-fn #'fussy-filter-default)

  (use-package fuz-bin
    :init
    (setq fussy-score-fn #'fussy-fuz-bin-score)
    (fuz-bin-load-dyn))

  (with-eval-after-load 'company
    (defun j-company-capf (f &rest args)
      "Manage `completion-styles'."
      (let ((completion-styles '(fussy))
            (+vertico-company-completion-styles '(fussy))
            (fussy-max-candidate-limit 5000)
            (fussy-default-regex-fn #'fussy-pattern-first-letter)
            (fussy-prefer-prefix nil))
        (apply f args)))

    (advice-add 'company-capf :around 'j-company-capf)))

フォントの設定

フォントを設定せずに使用すると正しく日本語が表示されない場合があります。
下記のようにフォントを設定すると解消しました。

config.el
(cond (IS-WINDOWS
       (setq doom-font (font-spec :family "BIZ UDゴシック" :size 14)
             doom-variable-pitch-font (font-spec :family "BIZ UDPゴシック")
             doom-unicode-font (font-spec :family "BIZ UDゴシック")
             doom-big-font (font-spec :family "BIZ UDゴシック" :size 22)))
      (IS-LINUX
       (setq doom-font (font-spec :family "VLゴシック" :size 12)
             doom-variable-pitch-font (font-spec :family "VLPゴシック")
             doom-unicode-font (font-spec :family "VLゴシック")
             doom-big-font (font-spec :family "VLゴシック" :size 20))))

大文字小文字を区別しない

company等の入力で大文字小文字を区別して欲しくない場合、下記のように設定します。

config.el
(setq completion-ignore-case t)

スクロール

Doomはデフォルトでスムーススクロールのような挙動をしますが、Emacsデフォルトのスクロールが好きな場合は下記を設定します。

config.el
(setq scroll-conservatively 0)

【Windows向け】Windowsロゴキーを使用しない

私は職場等でWindowsキー + lのロック画面を時々使用しますが、これをするとDoomの挙動がおかしくなります。
下記でWindowsキーをスーパーキーとして使用しないよう設定します。

config.el
(when IS-WINDOWS
  (setq w32-rwindow-modifier nil
        w32-lwindow-modifier nil))

【Windows向け】文字コードの設定

文字コードの設定方法は色々ありますが、私は下記のように設定しています。

config.el
(when IS-WINDOWS
  (set-language-environment "Japanese")
  (set-coding-system-priority 'utf-8
                              'euc-jp
                              'iso-2022-jp
                              'cp932))

デーモン起動する

最近デフォルトでEmacsclientが起動しない為、下記の設定を追加して利用できるようにします。

config.el
(server-mode +1)

現在の関数名等を表示

カーソル上の関数名をモードライン上に表示してくれます。便利です。

config.el
(which-function-mode +1)

【Windows向け】プライベート設定ファイルのキーバインド修正

SPC fpでプライベート設定ファイルを開く事が出来ますが、私のWindows環境では上手くいかいないので、
下記のようにしています。

config.el
(when IS-WINDOWS
  (global-set-key [remap doom/find-file-in-private-config] #'doom/open-private-config))

設定の反映

Doom Emacs上で
SPC ;を入力後、doom/reloadを選択するか、

$ ~/.emacs.d/bin/doom sync

を実行し、SPC q rを入力すると設定内容が反映されます。

Doom本体とパッケージの更新

Doom Emacs上で
SPC ;を入力後、doom/upgradeを選択するか、

$ ~/.emacs.d/bin/doom upgrade

を実行するとDoom本体とパッケージが更新されます。
パッケージの更新に失敗した場合、~/.emacs.d/.local/straight/reposから該当のパッケージを削除すると解消することが多いです。

所感

これまでSpacemacsやEmacs+evilを使用していましたが、Doom Emacsは完成度が高く、作り込みが丁寧な印象を受けました。
日本語の記事が少ないですが、とても気に入りましたので今後も使っていきます。

参考URL

15
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
8