LoginSignup
2
5

More than 1 year has passed since last update.

[備忘録]新品MacBookにHomebrew Caskを使ってemacsmacport(Emacs26.3)をインストール

Last updated at Posted at 2020-04-11

1. はじめに

1.1 筆者はEmacsに関してズブの素人である

今使っているEmacs環境は何年も前に試行錯誤で構築したものだ.ディレクトリの構造を十分に把握しないままEmacsをインストールできてしまい,何年も時間が経ったことで,その記憶はほとんどない.そのため,OSをアップグレードしたらEmacsの設定等が吹っ飛んで使えなくなるのではないかという素人的な不安があり,OSのアップグレードを保留し続けるという弊害が生じている.

今後もこのような愚かな過ちを繰り返すのは是非とも避けたい.そこで,Emacsを簡単かつ安全に(アン)インストールやバージョンのアップデートを行う方法でEmacs環境を実装したい.そのためにEmacsのディレクトリ構造等に詳しくなるというアプローチを取るのではなく,そのような知識がなくても問題ないアプローチを採用するのが長い目で見て最適であると考えた.具体的には,Homebrewというパッケージ管理システムを使ってEmacsを実装する方法を採用する.1

1.2 目的

以上を踏まえて,この記事の目的を真っ新のMacBookにHomebrewを使ってEmacsをインストールする手順を整理することと設定する.

ただし,Emacsは公式のものではなく,山本光晴氏のEmacsへのパッチであるEmacs Mac PortXin Xu(railwaycat)氏がHomebrewでインストールできるようにしたemacsmacportを使う.これは公式のEmacsではNS版(何それ?)で日本語入力をする際に日本語がちらつく問題があるらしいから.2

1.3 環境

利用するバージョンは次の通り.

  • macOS: Catalina 10.15.4
  • Xcode: 11.4
  • Homebrew: 2.2.12
  • emacsmacport: Emacs 26.3

1.4 記事の構成

以下の流れでインストールの手順を整理する.

  1. Xcodeのインストール
  2. Homebrewのインストール
  3. emacsmacportのインストール

emacsmacportはHomebrewでインストールする.HomebrewのインストールにはCommand Line Toolsが必要.Command Line ToolsはXcodeをインストールすることで対応する.3

1.5 関連記事

2. Xcodeのインストール

Step 1: App StoreからXcodeをダウンロードし,指示に従ってインストールする.

3. Homebrewのインストール

Step 1: Homebrewのサイト・トップのInstall Homebrewにあるコマンドをターミナルに貼り付けて実行する.

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

(注) インストール途中,システム環境設定のソフトウェア・アップデートがポップアップ表示され,Command Line Toolsのアップデートが要求された.この場合,GUIでのCommand Line ToolsのインストールとターミナルでのHomebrewのインストールが連携しながら,インストールが進む.

4. emacsmacportのインストール

4.1 手順

Step 1: tapでリポジトリemacsmacportをパッケージ(formula)として追加する.

$ brew tap railwaycat/emacsmacport

Step 2: caskを使ってパッケージをインストールする.

$ brew cask install emacs-mac

(注)こちらの手順は http://keisanbutsuriya.hateblo.jp/entry/2016/04/10/115945 を参考にした.

4.2 結果

4.2.1 インストールされる場所

この結果,/Applications/下にEmacs.appが作成される.他方で,brew install ...を使った場合にパッケージがインストールされるディレクトリ/usr/local/Cellar/に変化はない.

$ emacsを実行すると,GUIのEmacsが起動する.これは/usr/local/binにシンボリックリンクが作成され,上記/Applications/Emacs.app内のファイルを参照しているため.

$ which emacs
/usr/local/bin/emacs

$ ls -l
lrwxr-xr-x  1 ...  admin  47  4 11 21:57 emacs -> /Applications/Emacs.app/Contents/MacOS/Emacs.sh (...はファイルのオーナー名で,ここでは省略)

4.2.2 Emacs Lispソースコードの場所

Emacsの基礎となっているコマンドのEmacs Lisp言語を用いたソースコードは/Applications/Emacs.app/Contents/Resources/lisp/下に保存されている.

/Applications/Emacs.app/Contents/Resources/lisp/README
This directory contains source code for the parts of Emacs that are
written in Emacs Lisp.  *.el files are Emacs Lisp source, and the
corresponding *.elc files are byte-compiled versions.  Byte-compiled
files are architecture-independent.

The term subdirectory contains Lisp files that customize Emacs for
certain terminal types.  When Emacs starts, it checks the TERM
environment variable to get the terminal type and loads
'term/${TERM}.el' if it exists.

The other subdirectories hold Lisp packages grouped by their general
purpose.

4.3 caskを使ったインストールについて

caskはhomebrewの拡張機能で,リンクを貼ったり,GUIのアプリをインストールしたりする一連の作業をコマンド一行でやってくれるありがたいもの.

Homebrew Cask extends Homebrew and brings its elegance, simplicity, and speed to the installation and management of GUI macOS applications such as Atom and Google Chrome. (homebrew-cask/README.mdより引用)

上記Step 2brew cask install emacs-mac,アンインストールするためのbrew cask uninstall emacs-macをターミナルで実行した後の動作はhomebrew-cask/README.mdの資料が参考になる.

althomebrew-cask/README.mdより引用)

5. おわりに

このように整理してみれば,真っ新なMacBookにEmacsをインストールするのは非常に簡単な作業だ.今後新しい端末を購入してEmacsをインストールする場合,ここでの方法を是非参照したい.

もちろん,これでEmacs環境が整備されたとは言えない.次に必要な作業は~/.emacs.d/init.elを自分好みに用意すること.その際,use-packageを使った表現があるらしい.これらについては別の記事で整理したい.

A. 付録

A.1 ターミナル出力

A.1.1 Emacs(26.3)のアンインストール(2021年7月24日加筆)

% brew uninstall emacs-mac --cask
==> Uninstalling Cask emacs-mac
==> Backing App 'Emacs.app' up to '/usr/local/Caskroom/emacs-mac/emacs-26.3-z-mac-7.9/Emacs.app'
==> Removing App '/Applications/Emacs.app'
==> Unlinking Binary '/usr/local/bin/emacs'
==> Unlinking Binary '/usr/local/bin/ebrowse'
==> Unlinking Binary '/usr/local/bin/emacsclient'
==> Unlinking Binary '/usr/local/bin/etags'
==> Purging files for version emacs-26.3-z-mac-7.9 of Cask emacs-mac
  • brew cask uninstall emacs-macではなく,brew uninstall emacs-mac --caskとしている点に注意.

A.1.2 Emacs(27.2)のインストール(2021年7月24日加筆)

% brew install --cask emacs-mac
==> Downloading https://github.com/railwaycat/homebrew-emacsmacport/releases/download/emacs-27.2-mac-8.2/emacs-27.2-mac-8.2-10.14.6.zip
==> Downloading from https://github-releases.githubusercontent.com/8411796/66cc2300-8fe1-11eb-810e-9c714f83fefc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AK
######################################################################## 100.0%
==> Installing Cask emacs-mac
==> Moving App 'Emacs.app' to '/Applications/Emacs.app'
==> Linking Binary 'Emacs.sh' to '/usr/local/bin/emacs'
==> Linking Binary 'ebrowse' to '/usr/local/bin/ebrowse'
==> Linking Binary 'emacsclient' to '/usr/local/bin/emacsclient'
==> Linking Binary 'emacs-module.h' to '/usr/local/include/emacs-module.h'
==> Linking Binary 'subdirs.el' to '/usr/local/share/emacs/site-lisp/subdirs.el'
==> Linking Binary 'etags' to '/usr/local/bin/etags'
🍺  emacs-mac was successfully installed!
  • Emacs26.3をアンインストールした後に, brew update により,tap railwaycat/emacsmacport の情報をアップデート.

  1. これはHomebrewのパッケージ(formula)にEmacsが提供され続けることを前提とする. 

  2. https://tsuu32.hatenablog.com/entry/2019/12/23/112106 

  3. Xcodeのバージョンが6.1以降ならCommand Line ToolsはXcodeと合わせて自動でインストールされるらしい(https://style.potepan.com/articles/9093.html ). 

2
5
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
2
5