LoginSignup
9
7

More than 5 years have passed since last update.

straight.elでEmacsをよりポータブルに!!

Last updated at Posted at 2019-04-08

Emacsは設定ファイルさえあれば環境移行が楽、
だと思って使っていましたがパッケージのインストールだけは手動でやる部分も多かった。。。
私の力不足なだけですが笑

しかしstraight.elを見つけて本当に自動で自分の環境を再現させることを知って感動しました。

=>=>=>straight.elのりぽじとり

私の環境

下記2環境で使えました

  • macOS Mojave 10.14.4
    • Emacs 26.1
  • Ubuntu 18.10
    • Emacs 25.2.2

導入

何を書けば良いのか、READMEにある通りに書きましょう

~/.emacs.d/init.el
;; straight.el setting by myself
(let ((bootstrap-file (concat user-emacs-directory "straight/repos/straight.el/bootstrap.el"))
      (bootstrap-version 3))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

;; use-package
(straight-use-package 'use-package)

;; use-packageをstraight.elにフォールバックする
(setq straight-use-package-by-default t)

;; init-loader
(use-package init-loader)
;;; ログはエラーが出た時のみ
(custom-set-variables
 '(init-loader-show-log-after-init 'error-only))

;; ~/.emacs.d/init配下のelファイルをすべてロードする
(init-loader-load "~/.emacs.d/init")

これだけ書けば終わり、あとは使いたいパッケージの設定をつらつらと書いていきます。

~/.emacs.d/init/00_volatile-highlights.el
;; volatile-highlights
(use-package volatile-highlights)
(volatile-highlights-mode t)

こんな感じでuse-packageで呼んであげて普通に設定していくだけです。
Emacsを起動すると.emacs.d/straight配下のパッケージを使って自身構築していき、パッケージがなかった場合はクーロンしてきて配置してくれます。

これで新しい環境に移ってもinit.elとinitだけあれば元の環境を再構築することができます。素晴らしいですね。

Tips

ただやっぱりいろんなパッケージをロードしていると毎回起動するには少し遅くなってしまいます。
なのでデーモンでバックグラウンドに常駐させといて、クライアントを呼べば高速に起動することができます。

;; デーモン起動
$ emacs --daemon
;; クライアント起動
$ emacsclient -t

emacsclient -tと毎回タイプするのはちょっと長すぎるので私はaliasを貼って使っています。

alias e='emacsclient -t'

これで

;; scratch
$ e

;; [filename] を開く
$ e filename

って感じで使えますね。

9
7
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
9
7