LoginSignup
81
79

More than 5 years have passed since last update.

Emacs24.3の導入とundo-tree.elの紹介

Last updated at Posted at 2013-03-23

概要

Emacs24.3がリリースされたのでインストールしてみた。使ってみたらredo+.elが動かないっぽいのでundo-tree.elに乗り換えた。
undo-tree.elについて知りたい人はインストール部分は飛ばしたらいいと思う。

インストール

先日Emacs24.3がリリースされました
http://www.gnu.org/software/emacs/

で、以前↓の記事を読んで、同じ悩みを持っていたのでコンパイルオプションぱくって、ちょっといじってインストールした。
emacs のコンパイルオプションを設定したら幸せが訪れた - willnet.in

wget http://core.ring.gr.jp/pub/GNU/emacs/emacs-24.3.tar.gz
tar xzvf emacs-24.3.tar.gz
cd emacs-24.3
./configure --without-toolkit-scroll-bars --without-xaw3d --without-compress-info --without-sound --without-pop --without-xpm --without-tiff --without-rsvg --without-gconf --without-gsettings --without-selinux --without-gpm --without-makeinfo --without-all --with-x-toolkit=no
make
sudo make install

ただ、mark setしたあとC-gでキャンセル出来ないことがある、という悩みは解決しなかった(´・ω・`)

redo+.elからundo-tree.elへ

で、起動してみるとエラーが出る。

Warning (initialization): An error occurred while loading `/home/****/.emacs.d/init.el':

error: Attempt to modify read-only object

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

言われたとおりに--debug-initして起動してみると、どうやらredo+.elがおかしい。で、そこをコメントアウトしたら動いた。そこで、undo-tree.elという拡張を導入することにした。melpaに登録してあるのでM-x list-packagesしてundo-treeのところでi押してxでインストール。(packageの使い方はぐぐればいっぱい出てくると思う。最初にmelpaをリポジトリに登録する必要がある。)

で次の設定をinit.elに書いた。

init.el
(require 'undo-tree)
(global-undo-tree-mode t)
(global-set-key (kbd "M-/") 'undo-tree-redo)

これでM-/でredo出来るようになった。

せっかくなのでundo-treeをもうちょっと使いこなしてみる

undo-treeの持つ機能はredoが出来るようになるだけではない。一言で言うとテンポラリなバージョン管理システムだ。
具体的に例を示すと、ファイルを編集・保存をしたあとにC-x uしてみると以下の様な画面が現れると思う

   x
   |
  / \
 o   o
 |
 |
 x

これが今編集してるファイルの変更履歴だ。今xの場所にいる。で、dを押してみるとその時の変更のdiffが以下のように見れる。

@@ -297,8 +297,8 @@
 (setq undo-limit 600000)
(setq undo-strong-limit 900000)
-;; (require 'undo-tree)
-;; (global-set-key (kbd "M-/") 'undo-tree-redo)
+(require 'undo-tree)
+(global-set-key (kbd "M-/") 'undo-tree-redo)
(defun toggle-truncate-lines ()
   "折り返し表示をトグル"

もう一度dを押すとdiff表示をoffに出来る。
で、tree上でC-pするとtreeの上に移動する。同時にファイルがその時の状態に戻る。

   o
   |
  / \
 x   o
 |
 |
 s

上のtreeでsはsaveされているところ。xが自分がいるところ。もう一度C-pで更に上に遡る。

   x
   |
  / \
 o   o
 |
 |
 s

次に右下に行きたい時はC-fでtreeのルートが切り替わるので、次にC-nで右下のoに行ける。

   o
   |
  / \
 o   x
 |
 |
 s

この状態から編集を再開したければ、C-gを押す。するとtreeのバッファが消えて、この状態からファイルを編集することが出来る。

81
79
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
81
79