さくらのレンタルサーバに最新のEmacsをインストールする

2013/05/13

さくらのレンタルサーバの Emacsのバージョンが低いので、

% /usr/local/bin/emacs --version
GNU Emacs 22.3.1
Copyright (C) 2008 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
%

rst.el をインストールして実行したら、init.elの読み込みでエラーがでてしまう。

Symbol's function definition is void: characterp

ネットで検索して調べたら Emacs のバージョンが古いのが原因らしい。なので、新しい Emacs をインストールすることにした。

現時点(2013/03/24)での最新バージョンは、
The current stable release is 24.3.

emacs-24.3.tar.gzを、これから作業で使うディレクトリ ~/work にダウンロードする。

% cd work
% wget http://core.ring.gr.jp/pub/GNU/emacs/emacs-24.3.tar.gz

解凍する。

% tar zxvf emacs-24.3.tar.gz

解凍したディレクトリに移動してコンフィグレーションを実行する。
ssh で接続して使うので、当然のことながら X は使わないし、グラフィック関係なども必要無い。
最小構成でビルドするので、オプションに –without-all –without-x を指定する。
また、インストール先は /home/bty/local とするので、 –prefix=/home/bty/local も指定する。
(btyは私のアカウント名なので、参考にするかたは自分のアカウント名に代えればOKのはず)

オプションの説明は解凍したファイルの中に INSTALL に記載されている。関連するところの抜粋。

Use --without-all if you want to build a small executable with the minimal
dependencies on external libraries, at the cost of disabling most of the
features that are normally enabled by default.  Using --without-all is
equivalent to --without-sound --without-dbus --without-libotf
--without-selinux --without-xft --without-gsettings --without-gnutls
--without-rsvg --without-xml2 --without-gconf --without-imagemagick
--without-m17n-flt --without-jpeg --without-tiff --without-gif
--without-png --without-gpm.  Note that --without-all leaves X support
enabled, and using the GTK2 or GTK3 toolkit creates a lot of library
dependencies.  So if you want to build a small executable with very basic
X support, use --without-all --with-x-toolkit=no.  For the smallest possible
executable without X, use --without-all --without-x.  If you want to build
with just a few features enabled, you can combine --without-all with
--with-FEATURE.  For example, you can use --without-all --with-dbus
to build with DBus support and nothing more.

The `--prefix=PREFIXDIR' option specifies where the installation process
should put emacs and its data files.  This defaults to `/usr/local'.
- Emacs (and the other utilities users run) go in PREFIXDIR/bin
  (unless the `--exec-prefix' option says otherwise).
- The architecture-independent files go in PREFIXDIR/share/emacs/VERSION
  (where VERSION is the version number of Emacs, like `23.2').
- The architecture-dependent files go in
  PREFIXDIR/libexec/emacs/VERSION/CONFIGURATION
  (where CONFIGURATION is the configuration name, like
  i686-pc-linux-gnu), unless the `--exec-prefix' option says otherwise.
% cd emacs-24.3
% ./configure --without-all --without-x --prefix=/home/bty/local
% make

ビルドした Emacs が起動するか確認する。

% src/emacs -Q

ちゃんと起動した。バージョンが 24.3 なのを確認した。
インストールする。

% make install

どこにインストールされたかを確認する。


% find ~/ -name emacs

/home/bty/local/bin/emacs
/home/bty/local/share/emacs
/home/bty/local/libexec/emacs
/home/bty/local/var/games/emacs

オプションで指定したとおり、/home/bty/local 配下にインストールされている。
解凍したソースファイルなどを削除するには次のコマンドを実行する。

% make clean

/home/bty/localにパスが通っていれば emacs と打ち込めば、新しくインストールした Emacsが起動してくるはずだ。パスを通すには、 ~/.cshrc ファイルに設定を追記する。下記は $HOME/bin と $HOME/local/bin にパスを追加した例。 Emacsの実行ファイル(link)は /home/bty/local/bin にあるのでフルパスで打ち込まなくても、これを実行してくれる。

setenv PATH $HOME/bin:$HOME/local/bin:$PATH

さてさて、やっとのことで、rst.elの設定にたどり着いた。
rst.el を ~/.emacs.d/elisp ディレクトリにダウンロードする。

% cd ~/.emacs.d
% mkdir elisp
% cd elisp
% wget http://docutils.sourceforge.net/tools/editors/emacs/rst.el

Emacsの設定は ~/.emacs.d ディレクトリの init.el ファイルに記載する。

(setq load-path (cons "~/.emacs.d/elisp" load-path))

;;; for rst.el
(require 'rst)
(setq auto-mode-alist
    (append '(("\\.rst\\'" . rst-mode)
              ("\\.rest\\'" . rst-mode)) auto-mode-alist))

Emacs で rstモードが使えるようになってうれしい。