LoginSignup
18
23

More than 5 years have passed since last update.

Raspberry PiでEmacs 24.5とCaskを使う

Last updated at Posted at 2015-04-21

 Raspberry Pi (Model B)は非力なので開発環境には向いていませんがデバイスを操作するPythonを書いているとEmacsが欲しくなります。apt-getでEmacs 24がインストールできないようなので、これも不向きですがRaspberry Pi上でEmacsをビルドして使うことにします。

更新履歴

Emacs 24.5.1

apt-getでインストールできるEmacsは23.4でした。

$ sudo apt-get update
$ apt-cache show emacs23
Package: emacs23
Version: 23.4+1-4
...

仕方がないのでEmacsの最新版をRaspberry Pi上でビルドすることにします。

必要なパッケージ

Emacsのビルドに必要なパッケージをインストールします。

$ sudo apt-get update
$ sudo apt-get install build-essential automake texinfo libncurses5-dev

インストール

24.5の最新のソースコードをダウンロードしてビルドします。ターミナル接続が主でGUIは不要のため--without-xフラグを付けてconfigureします。

$ mkdir ~/src
$ cd !$
$ wget http://ftp.gnu.org/pub/gnu/emacs/emacs-24.5.tar.xz
$ tar -Jxvf emacs-24.5.tar.xz
$ cd emacs-24.5
$ ./configure --without-x
$ make
$ sudo make install

ビルドとインストールに1時間30分くらいかかります。気長に待ちます。

$ which emacs
/usr/local/bin/emacs
$ emacs --version
GNU Emacs 24.5.1

Cask

Emacsのパッケージ管理はCaskを使います。

インストール

$ curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python
Cloning into '/home/pi/.cask'...
...
Successfully installed Cask!  Now, add the cask binary to your $PATH:
  export PATH="/home/pi/.cask/bin:$PATH"
$ echo 'export PATH="/home/pi/.cask/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc
$ cask --version
0.7.3

設定

~/.emacs.dディレクトリに移動してcaskの初期処理を行います。

$ cd ~/.emacs.d/
$ cask init

自動生成されたCaskファイルを修正してとりあえず不要なパッケージは削除します。

~/.emacs.d/Cask
(source gnu)
(source melpa)

(depends-on "init-loader")
(depends-on "multi-term")

init-loaderを使うためinit.elのrequireは少なくなります。

~/.emacs.d/init.el
(require 'cask "~/.cask/cask.el")
(cask-initialize)

(require 'init-loader)
(setq init-loader-show-log-after-init nil)
(init-loader-load "~/.emacs.d/inits")

cask installコマンドを実行して、Caskファイルに定義したパッケージをインストールします。

$ cask install

init-loader

Emacsの設定ファイルの管理はinit-loaderを使います。設定ファイルを配置するディレクトリを作成します。

$ mkdir -p ~/.emacs.d/inits
$ cd !$

最低限必要な基本的な設定ファイルを作成します。

$ tree -L 2
.
├── Cask
├── init.el
└── inits
    ├── 00-keybindings.el
    ├── 01-menu.el
    ├── 02-files.el
    └── 03-multi-term.el

00-keybindings.el

削除キーとヘルプだけキーバインドを変更します。

~/.emacs.d/inits/00-keybindings.el
(define-key global-map "\C-h" 'delete-backward-char)
(define-key global-map "\M-?" 'help-for-help)
  • C-hでbackspaceする
  • M-?でヘルプを表示する

01-menu.el

GUIは使わないのでメニューを非表示にします。

~/.emacs.d/inits/01-menu.el
(menu-bar-mode 0)

02-files.el

ファイルの操作もバックアップファイルを作らないなど基本的な項目です。

~/.emacs.d/inits/02-files.el
(when (boundp 'show-trailing-whitespace)
    (setq-default show-trailing-whitespace t))

(add-hook 'before-save-hook 'delete-trailing-whitespace)

(setq backup-inhibited t)
(setq next-line-add-newlines nil)
(setq-default tab-width 4 indent-tabs-mode nil)
  • 行末のスペースはマークして、ファイル保存時に削除する
  • バックアップファイルを作らない
  • バッファの最後でnewlineで新規行を追加するのを禁止する
  • 4タブのスペース変換

03-multi-term.el

USB-TTLシリアル変換モジュールを経由してホストマシンからscreenで接続しているためウィンドウが1つしか開きません。Multi Termを使い、Emacs上でコーディングをプログラムの実行をできるようにします。

~/.emacs.d/inits/03-multi-term.el
(dolist (dir (list
              "/sbin"
              "/usr/sbin"
              "/bin"
              "/usr/bin"
              "/usr/local/bin"
              (expand-file-name "~/bin")
              (expand-file-name "~/.emacs.d/bin")
              ))
 (when (and (file-exists-p dir) (not (member dir exec-path)))
   (setenv "PATH" (concat dir ":" (getenv "PATH")))
   (setq exec-path (append (list dir) exec-path))))

(require 'multi-term)
(setq multi-term-program shell-file-name)
18
23
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
18
23