設定ファイルしたい(~/.emacs.d/init.el)
;;; init.el --- straight + use-package minimal setup
;; --------------------------------
;; straight.el bootstrap
;; --------------------------------
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name
"straight/repos/straight.el/bootstrap.el"
user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;; --------------------------------
;; straight + use-package
;; --------------------------------
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
(setq straight-vc-git-default-clone-depth 1)
;; --------------------------------
;; 基本設定
;; --------------------------------
(use-package emacs
:custom
(inhibit-startup-screen t)
(make-backup-files nil)
(auto-save-default nil)
(create-lockfiles nil)
:init
(set-locale-environment "en_US.UTF-8")
(show-paren-mode)
:bind
(("C-h" . delete-backward-char))
)
;; --------------------------------
;; 標準パッケージ
;; --------------------------------
;; savehist
(use-package savehist
:init
(savehist-mode 1)
)
;; recentf
(use-package recentf
:init
(recentf-mode 1)
:custom
(recentf-max-saved-items 200)
(recentf-auto-cleanup 'mode)
;; :bind -- consultでバインドを設定
;; (("C-x C-r" . recentf-open-files))
)
;; --------------------------------
;; 拡張パッケージ
;; --------------------------------
;; 検索ルール
;; orderless
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides
'((file (styles partial-completion)))
)
)
;; UI強化
;; vertico
(use-package vertico
:init
(vertico-mode)
:custom
(vertico-cycle t)
)
;; marginalia
(use-package marginalia
:init
(marginalia-mode)
)
;; which-key
(use-package which-key
:init
(which-key-mode)
)
;; バッファー操作
;; consult
(use-package consult
:bind
(("C-x C-r" . consult-recent-file))
)
;; embark
(use-package embark
:bind
(("C-." . embark-act))
)
(use-package embark-consult
:after (embark consult)
)
;; 入力補完
;; corfu
(use-package corfu
:init
(global-corfu-mode)
:custom
(corfu-cycle t)
(corfu-auto t)
)
;;; init.el ends here
init.elは、Emacsの起動時に読み込まれる設定ファイルです。
上記はstraightとuse-packageを使ってパッケージを管理する設定サンプルです。
初期設定としてオススメのパッケージも追加してあります。
~/.emacs.d/
|-- init.el
|-- early-init.el
|-- custom/
|--
注釈
正しくは~/.emacs.elもしくは~/.emacs.d/init.elが、起動時に読み込まれるファイルです。
設定内容が競合するため、どちらか片方のみ作成してください。
現在は後者を作成することが多いです。
early-initしたい(~/.emacs.d/early-init.el)
;; early-init.el --- early settings
;; パッケージの自動初期化を無効化
(setq package-enable-at-startup nil)
;; GCを一時的に大きくする
(setq gc-cons-threshold (* 50 1000 1000))
;; init.elで大きさを戻す
;; (setq gc-cons-threshold (* 2 1000 1000))
;; UIを非表示
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; フレーム設定
(setq frame-inhibit-implied-resize t)
early-init.elは、起動直後(通常のinit.elよりも前)に読み込まれる設定ファイルです。
Emacs27以降に導入された機能で、初期化の挙動を制御して、起動を速くできます。
上記のサンプルでは、パッケージの自動初期化を無効にしたり、 ガベージコレクション(GC)のサイズを一時的に大きくしたりして、 高速に起動できるようにしています。
注釈
このファイルは軽く書くのが基本です。 重たい処理やパッケージの設定は書きません。
XDG準拠したい(~/.config/emacs/init.el)
1export XDG_CONFIG_HOME="HOME/.config"
XDG_CONFIG_HOMEが設定されていると
~/.config/emacs/にある設定が読み込まれるようになります。
注釈
最近のモダンなツールは設定ファイルを~/.config/{ツール名}に配置する傾向があります。
上記の環境変数を設定すれば、Emacsでも利用できます。
ただし、まだまだ~/.emacs.d/を使うほうが一般的なようです。
~/.emacs.elのときと同じですが、~/.emacs.d/と~/.config/emacs/も併用できません。