<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">

<book id="emacs-guide" lang="ja">
 <bookinfo>
  <title>Emacs 利用ガイド</title>
  <authorgroup>
   <author>
    <firstname>Munehiro</firstname>
    <surname>Yamamoto</surname>
   </author>
   <editor>
    <firstname>Masaharu</firstname>
    <surname>Iwai</surname>
   </editor>
  </authorgroup>

  <abstract>
   <para>
    Vine Linux 5 以降の Emacs（以下、Emacs は GNU Emacs を指す）環境は、
    Vine Linux 4.2 までのそれと比べて、大幅に変更されました。
   </para>
   <para>
    このドキュメントは、Vine Linux 5 以降に新しく搭載された 
    system-wide な設定および Vine Linux のデフォルト設定を中心に、
    Vine Linux 6 の Emacs 環境を解説します。
   </para>
  </abstract>
 </bookinfo>

 <chapter id="emacs-basic">
   <title>Emacs を始めよう！</title>
   <para>
     Emacs の起動画面を使いながら、Emacs の基本事項や基本操作を説明します。
   </para>

   <note>
     <para>
       とくに断りがないかぎり、本ガイドの Emacs は、
       Emacs-23.3 を用いているものとします。
       Emacs-24.0.93 を利用する場合には、適切に読み替えてください。
     </para>
   </note>

   <sect1 id="emacs-install">
     <title>Emacs をインストール</title>
     <para>
       Vine Linux 6 の Emacs は、
       Emacs-23.3 と Emacs-24.0.93 が用意されています。
       Emacs-23.3, Emacs-24.0.93 は、
       それぞれ emacs, emacs24 パッケージをインストールすることで、
       利用できます。
       <itemizedlist>
	 <listitem>
	   <para>
	     Emacs-23.3
	     <screen>$ sudo apt-get install emacs</screen>
	   </para>
	 </listitem>
	 <listitem>
	   <para>
	     Emacs-24.0.93
	     <screen>$ sudo apt-get install emacs24</screen>
	   </para>
	 </listitem>
       </itemizedlist>
     </para>
   </sect1>

   <sect1 id="emacs-startup-screenshot">
     <title>Emacs を起動</title>
     <para>
       ToDo: Emacs 23.X の起動画面をスクリーンショットする。
       メニューからバッファ、ミニバッファなどの説明を図説する。
     </para>

     <figure id="fig-emacs-splashscreen">
       <title>Emacsの起動画面</title>
       <graphic fileref="figures/emacs-splashscreen.png" />
     </figure>

   </sect1>
   
   <sect1 id="emacs-buffer">
     <title>バッファ</title>
     <para>Emacs では、編集中の文書はバッファと呼ばれるメモリ領域に読み込まれ、このバッファの内容に対して書き込みや修正を行います。ファイルに保存する命令を実行した時にはじめて、バッファの内容はディスク上のファイルに書き込まれます。</para>
     <para>バッファの内容はウィンドウに表示されます。ウィンドウは複数用意することができ、そこに複数のバッファの内容や、同じバッファの違う部分を表示して編集を行うことができます。</para>
     <para>バッファの編集状況等の情報は、ウィンドウの最下部のモードラインに表示されます。</para>
     
     <note><title>ウィンドウという言葉について</title>
     <para>一般的な「ウィンドウ」という言葉と、emacs での「ウィンドウ」は異なります。</para>
     <para>一般的なウィンドウは emacs ではフレームといい、一つのフレームの中を分割したものをウィンドウと呼びます。</para>
     <!--para>下の図では、フレームが一つで、ウィンドウが二つあります。</para>
	 
	 <figure id="emacs-frame-and-window">
	 <title>emacsのフレームとウィンドウ</title>
	 <graphic fileref="figures/emacs-window.png" />
	 </figure-->
     </note>
     
   </sect1>

   <sect1 id="emacs-entry">
     <title>文字入力</title>
     <para>
       ウィンドウにカーソルがある時、キーボードから入力した文字はカーソル位置に挿入され、カーソルが進みます。日本語を入力する時には、'C-\'で日本語切替えモードになります。 もう一度'C-\'を押すとアルファベットの入力モードに戻ります。
     </para>
     <para>
       日本語入力システムについては、<ulink url="ghelp:vine-desktop-guide">デスクトップユーザーズガイド</ulink>の<ulink url="ghelp:vine-desktop-guide?input-ja">GUI環境での日本語入力</ulink>を参照して下さい。
     </para>

     <para>
       TABキーを押すと行のインデントの調整となってしまい、TAB文字を入力出来ないことがあります。そのような時には、C-q TAB のように、C-q のあとでキーを押してください。
     </para>

     <para>
       また、C-q C-j とすると、改行記号を入力できます。Enter キーの代わりに利用することで、<xref linkend="emacs-search" /> などの時に改行を含んだ文字列を扱うことができます。
     </para>
   </sect1>

   <sect1 id="emacs-cursol">
     <title>カーソル移動</title>
     <para>
       編集中のカーソルの移動は矢印キーの他、以下のようなキーで移動できます。
     </para>
     <table id="keybind-for-move-cursor">
       <title>カーソル移動</title>
       <tgroup cols="2">
	 <thead>
	   <row><entry>キー操作</entry><entry>意味</entry></row>
	 </thead>
	 <tbody>
	   <row><entry>C-b または ←</entry><entry>一文字左へ </entry></row>
	   <row><entry>C-f または →</entry><entry>一文字右へ</entry></row>
	   <row><entry>C-p または ↑</entry><entry>一文字上へ</entry></row>
	   <row><entry>C-n または ↓</entry><entry>一文字下へ</entry></row>
	   <row><entry>C-v または PgDn</entry><entry>次の画面に進む</entry></row>
	   <row><entry>M-v または PgUp</entry><entry>前の画面に戻る</entry></row>
	   <row><entry>C-d</entry><entry>カーソル位置の文字を削除</entry></row>
	   <row><entry>C-k</entry><entry>カーソル位置から行末までの文字を削除</entry></row>
	   <row><entry>C-e</entry><entry>行の一番右へ</entry></row>
	   <row><entry>C-a</entry><entry>行の一番左へ</entry></row>
	   <row><entry>M-f</entry><entry>一単語右へ</entry></row>
	   <row><entry>M-b</entry><entry>一単語左へ</entry></row>
	   <!--row><entry>M-g &lt;行番号&gt;</entry><entry>指定行へ移動 (xemacsのみ)</entry></row-->
	   <row><entry>M-x goto-line</entry><entry>指定行へ移動</entry></row>
	   <row><entry>C-space または C-@</entry><entry>現在のカーソル位置にマークをつけ記憶させる</entry></row>
	   <row><entry>C-x C-x</entry><entry>現在のカーソル位置にマークをつけ、前回マークをつけた位置まで戻る(繰り返すと二点を交互に行き来します)</entry></row>
	 </tbody>
       </tgroup>
     </table>
   </sect1>

   <sect1 id="emacs-delete">
     <title>文字削除</title>
     <para>
       カーソル位置の文字の削除は C-d を用います。その他単語の削除や行末の削除等のキーもあります。
     </para>
     <table id="keybind-for-delete-characters">
       <title>文字削除</title>
       <tgroup cols="2">
	 <thead>
	   <row><entry>キー操作</entry><entry>意味</entry></row>
	 </thead>
	 <tbody>
	   <row><entry>C-d</entry><entry>カーソル位置の文字を削除</entry></row>
	   <row><entry>M-d</entry><entry>カーソル位置から一単語削除</entry></row>
	   <row><entry>C-k</entry><entry>カーソル位置から行末までの文字を削除</entry></row>
	   <row><entry>M-k</entry><entry>カーソル位置から文末までの文字を削除</entry></row>
	 </tbody>
       </tgroup>
     </table>
   </sect1>

   <sect1 id="emacs-search">
     <title>文字列検索・置換</title>
     <para>
       カーソル行以降の文字列検索には、C-s を用います。C-s を入力するとミニバッファに 
       <screen>I-search:</screen>
     と表示されるので、検索したい文字列を入力して下さい。検索の終了は C-g を押します。
     </para>
     <para>
       一度入力した文字列を続けて検索したい時には、C-s を続けて2回押します。C-s の代わりに C-r を用いるとカーソル位置より前にある検索文字列を表示します。日本語の文字列を検索する場合<footnote><para>migemoという便利なツールがあります。<xref linkend="dot.emacs.my.el" />を参照してください。</para></footnote>は、C-sの後にEnterを押してから、C-\;でかな漢字変換モードにしてから入力して下さい。
     </para>
     <para>
       確認付きの文字列の置換を行うには M-% を用います。M-% を入力すると
       <screen>Query-replace:</screen>
       とミニバッファに表示されますので、まず置換したい文字列を入力します。例えば, C言語プログラムでint を long にしたいときには、M-%の後に int と入力し、Enterキーを押します。ミニバッファの表示が以下のように代わるので、ここで long を入力し, Enterキーを押します。
     </para>
     <screen>Query-replace int with: long</screen>
     <para>
       置換する文字列 int があるとそこで、以下のように表示されます。
     </para>
     <screen>Query-replace int with long: (? for help)</screen>
     <para>
       ここで、スペースキーか'y'を押せば置換が行われ、'n'を押すと置換は行わず、次の候補に移動します。終了するときには、Enterキーか'q'を入力します。上に表示されている通り '?' を入力すればコマンドのリストが表示されます。
     </para>
     <para>
       文字列の置換を確認なしに一括して行いたいときには、まず一括置換を開始したい場所にカーソルを移動し、M-x を押します。このとき、ミニバッファの表示は以下のようになります。
     </para>
     <screen>M-x</screen>
     <para>
       ここで、<userinput>replace-string</userinput> と入力し、<keycap>Enter</keycap>キーを押します。
     </para>
     <screen>M-x replace-string</screen>
     <para>
       その後は、確認のある場合の文字列置換の場合と同様に、置換のための文字列を入力すれば、一括置換が行われます。
     </para>
     <para>
       emacs には replace-string の他、非常にたくさんのコマンドがあり、M-x は、このコマンドを入力するのに使われます。コマンドの名前はTabキーで補完しながら入力することができます。候補のコマンドが複数あるときには、候補一覧が表示されます。
     </para>
     <table id="keybind-for-search-and-replace">
       <title>文字列検索・置換</title>
       <tgroup cols="2">
	 <thead>
	   <row><entry>キー操作</entry><entry>意味</entry></row>
	 </thead>
	 <tbody>
	   <row><entry>C-s</entry><entry>文字検索 (カーソル行以降で検索)</entry></row>
	   <row><entry>C-r</entry><entry>文字検索 (カーソル行より前で検索)</entry></row>
	   <row><entry>M-%</entry><entry>文字列置換(確認あり)</entry></row>
	   <row><entry>M-x replace-string</entry><entry>文字列置換(確認なし)</entry></row>
	 </tbody>
       </tgroup>
     </table>
   </sect1>
   
   <sect1 id="emacs-undo">
     <title>アンドゥ (取消)</title>
     <para>実行したコマンドを取り消して、バッファを元の状態に戻すには、C-x u (または C-_ )を用います。連続して C-x u を用いると、実行した回数だけ前の状態に戻ります。</para>
     <table id="keybind-for-undo">
       <title>アンドゥ (取消)</title>
       <tgroup cols="2">
	 <thead>
	   <row><entry>キー操作</entry><entry>意味</entry></row>
	 </thead>
	 <tbody>
	   <row><entry>C-x u または C-_</entry><entry>アンドゥ(実行したコマンドの取消)</entry></row>
	 </tbody>
       </tgroup>
     </table>
   </sect1>

   <sect1 id="emacs-edit">
     <title>カット/コピー/ペースト</title>
     <para>編集中のバッファの一部分を別の場所にコピーするには以下のような手順で行います。</para>
     <orderedlist>
       <listitem><para>コピーしたい部分の先頭にカーソルを移動します。</para></listitem>
       <listitem><para>C-Space (または C-@)を入力します(これで現在のカーソルの位置が記憶されます)。</para></listitem>
       <listitem><para>コピーしたい部分の終りまたは始めにカーソルを移動します。</para></listitem>
       <listitem><para>M-w を押す(これで先頭位置(C-Spaceを押した位置)からこの終りの部分までが記憶されます。この部分をリージョン(region:領域)と呼びます。)</para></listitem>
       <listitem><para>コピー先にカーソルを移動します。</para></listitem>
       <listitem><para>C-y を入力します。これでペースト(Emacsではyank(ヤンク)といいます)完了です。</para></listitem>
     </orderedlist>
     <para>一部分を削除したい時には、上のコピーの手続きで、M-w を入力するかわりに、C-w を入力すれば、設定したリージョンは削除され、記憶されます。</para>
     <para>一部分を移動したい時には、上の手続きで削除を行った後、移動先へカーソルを持って行きコピーの場合と同様に C-y を入力すれば、記憶されているリージョンがそこに出力されます。</para>
     
     <table id="keybind-for-kill-and-yank">
       <title>カット/コピー/ペースト</title>
       <tgroup cols="2">
	 <thead>
	   <row><entry>キー操作</entry><entry>意味</entry></row>
	 </thead>
	 <tbody>
	   <row><entry>C-space または C-@</entry><entry>始点のマーク</entry></row>
	   <row><entry>M-w</entry><entry>始点から現在のカーソル位置までを記憶(コピー)</entry></row>
	   <row><entry>C-w</entry><entry>始点から現在のカーソル位置までを削除して記憶(カット)</entry></row>
	   <row><entry>C-y</entry><entry>記憶内容をカーソル位置に貼付け(ペースト)</entry></row>
	 </tbody>
       </tgroup>
     </table>
   </sect1>

   <sect1 id="emacs-window">
     <title>ウィンドウ操作</title>
     <para>複数のファイルを編集する場合には、ウィンドウを複数開いて、各ウィンドウに、同じバッファの異なる位置を表示したり、複数のバッファを表示したりして編集することができます。</para>
     <para>例えば C-x 2 を入力するとカーソルのあるウィンドウが上下2つに分割されます。もとの通り分割されたウィンドウを一つに戻すには、C-x 1 を入力すれば、カーソルのあるほうのウィンドウのみの表示になります。分割したウィンドウ間のカーソル移動には C-x o を用います。分割したウィンドウの境界はマウスでドラッグすれば移動することもできます。</para>
     <para>また、C-x 5 2 を入力すると、新しいフレーム(参照<xref linkend="emacs-buffer" />)がつくられます。複数のフレーム間のカーソル移動には C-x 5 o を用います。</para>
     <para>現在のウィンドウに表示するバッファを変更したい時には C-x b を入力すると, 以下のように表示されます。</para>
     <screen>Switch to buffer: (default test.txt)</screen>
     <para>ここで、ウィンドウに表示したいバッファ名を入力し、Enterキーを押せば表示バッファが切り替わります。ここで、候補のバッファの一つが上のように default の後ろに表示されます。この候補でよいときには単にEnterキーを押して下さい。</para>
     <table id="keybind-for-window-and-frame">
       <title>ウィンドウ操作</title>
       <tgroup cols="2">
	 <thead>
	   <row><entry>キー操作</entry><entry>意味</entry></row>
	 </thead>
	 <tbody>
	   <row><entry>C-x 2</entry><entry>ウィンドウを上下に分割</entry></row>
	   <row><entry>C-x 3</entry><entry>ウィンドウを左右に分割</entry></row>
	   <row><entry>C-x o</entry><entry>分割したウィンドウ間をカーソル移動</entry></row>
	   <row><entry>C-x 0</entry><entry>分割したウィンドウのうちカーソルのあるほうを閉じる</entry></row>
	   <row><entry>C-x 1</entry><entry>分割したウィンドウのうちカーソルの無いほうを閉じる</entry></row>
	   <row><entry>C-x +</entry><entry>分割したウィンドウの高さ、幅を均等にする</entry></row>
	   <row><entry>C-x 5 2</entry><entry>新しいフレームを開く</entry></row>
	   <row><entry>C-x 5 o</entry><entry>フレーム間でカーソル移動</entry></row>
	   <row><entry>C-x 5 0</entry><entry>カーソルのあるフレームを閉じる</entry></row>
	   <row><entry>C-x b</entry><entry>現在のウィンドウに表示するバッファを指定する</entry></row>
	 </tbody>
       </tgroup>
     </table>
   </sect1>

   <sect1 id="emacs-filelist">
     <title>ファイル一覧ウィンドウでの操作</title>
     <para>C-x C-b で編集中のバッファの一覧が表示されます。この一覧表示をしてるウィンドウに C-x o で移動すると、各バッファについていろいな操作を行えます。カーソルの移動は、編集時と同様に C-n, C-p なども使えますが、この一覧表示のバッファでは単に n や p でも移動できます。</para>
     <para>ウィンドウに表示したいバッファ名の位置にカーソルを移動し、1 を入力するとウィンドウにはそのバッファの内容が表示されます。その他、削除マークや保存マーク等をつけて、一括して削除や保存と言った作業も行えます。できる操作の一覧は「?」で表示されます。</para>
     <table id="keybind-for-buffer-menu">
       <title>ファイル一覧ウィンドウでの操作</title>
       <tgroup cols="2">
	 <thead>
	   <row><entry>キー操作</entry><entry>意味</entry></row>
	 </thead>
	 <tbody>
	   <row><entry>n</entry><entry>カーソルを次の行へ進める</entry></row>
	   <row><entry>p</entry><entry>カーソルを前の行へ戻す</entry></row>
	   <row><entry>1</entry><entry>カーソル行のバッファを現在のウィンドウいっぱいに表示する</entry></row>
	   <row><entry>f</entry><entry>カーソル行のバッファを現在のウィンドウに表示する</entry></row>
	   <row><entry>d</entry><entry>カーソル行のバッファに削除マークをつける</entry></row>
	   <row><entry>s</entry><entry>カーソル行のバッファに保存マークをつける</entry></row>
	   <row><entry>x</entry><entry>削除マークのあるバッファを削除し、保存マークのあるバッファをファイルに保存する</entry></row>
	   <row><entry>u</entry><entry>バッファについているマークを消します。</entry></row>
	 </tbody>
       </tgroup>
     </table>
   </sect1>

 </chapter>

 <chapter id="vine6-emacs">
   <title>Vine Linux 6 の Emacs 環境</title>
   <para>
     Vine Linux 6 の Emacs 環境は、
     Vine Linux 5 で一新された Emacs 環境から、
     さらに利便性の改善をはかりました。
     Vine Linux 4.2 以前の Emacs 環境（<xref linkend="vine4-emacs" />）では、
     システム全体での設定（<xref linkend="system-wide-configuration" />）を
     RPM パッケージに含まれている設定と異なるものにする場合、
     その RPM パッケージがアップデートされるたびに修正する必要がありました。
   </para>
   <para>
     Vine Linux 5 で導入された仕組みにより、
     個別の RPM パッケージに含まれている設定（<xref linkend="distribution-wide-configuration" />）と
     システム全体での設定（<xref linkend="system-wide-configuration" />）を別のファイルに記述するようになりました。
     システム全体での設定（<xref linkend="system-wide-configuration" />）を変更していた場合、
     RPM パッケージをアップデートしても内容をそのまま保持するようになっています。
   </para>
   <para>
     Vine Linux 6 では、次の順で設定が読み込まれます。
   </para>
   <orderedlist>
     <listitem>
       <para>
	 個別の RPM パッケージでの設定（<xref linkend="distribution-wide-configuration" />）
     </para>
     </listitem>
     <listitem>
       <para>
	 システム全体での設定（<xref linkend="system-wide-configuration" />）
       </para>
     </listitem>
     <listitem>
       <para>
	 <xref linkend="per-user-configuration" />
       </para>
     </listitem>
   </orderedlist>
   <para>
     同一の設定項目について、それぞれで設定している場合は、
     後から読み込まれる設定が有効となります。
     また、システム全体での設定（<xref linkend="system-wide-configuration" />）は、
     RPM パッケージのアップデートで置き換えられてしまうことがありません。
     そのため、個別の RPM パッケージでの設定（<xref linkend="distribution-wide-configuration" />）を
     <xref linkend="system-wide-configuration" /> で上書きできます。
   </para>

   <sect1 id="distribution-wide-configuration">
     <title>distribution-wide な設定</title>
     <para>
       <xref linkend="vine-default" /> の導入により、
       システム標準の設定を、
       個別の RPM パッケージごとに設定しています。
       これにより、ユーザは何も設定を記述しなくても、
       elisp アプリケーションがある程度、使えるようになっています。
       詳しくは、<xref linkend="vine-default-framework" /> を参照してください。
     </para>
   </sect1>

  <sect1 id="system-wide-configuration">
    <title>system-wide な設定</title>
    <para>
      Vine Linux 5 以降の Emacs では、
      従来よりもシステム全体の設定をより記述しやすくなりました。
    </para>  
    <para>
      system-wide な設定ファイルは、
      <filename>/etc/emacs/emacs23-local.el</filename>（<xref linkend="fig-emacs23-local-el" />）
      に配置されています。
      Emacs-23.3 を起動したとき、
      もし <filename>/etc/emacs/emacs23-local.el</filename> が存在すれば、
      <filename>site-start.el</filename> の一番最後に読み込まれます。
      したがって、<xref linkend="distribution-wide-configuration" /> よりも 
      <filename>emacs23-local.el</filename> が優先されます。

      <figure id="fig-emacs23-local-el">
	<title>/etc/emacs/emacs23-local.el</title>
	<screen>
;; 
;; GNU Emacs 23.3 local configuration file
;; 
;; This configuration is read at the end of site-start.el. 
;; Emacs configuration files are read
;;   - distribution wide from site-start.el 
;;   - system wide from this configuration file
;;   - per user from ~/.emacs.d/init.el, 
;; where per user settings override system wide settings, 
;; and system wide settings override site-start.el. 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Local Variables:
;; mode: emacs-lisp
;; End:
	</screen>
      </figure>
    </para>
  </sect1>

  <sect1 id="per-user-configuration">
    <title>ユーザごとの設定</title>
    <para>
      vine-default 設定ファイル
      <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
      および 
      ユーザ初期設定ファイル
      <filename>~/.emacs.d/init.el</filename>（<xref linkend="fig-init-el" />）
      から構成されます。
      詳しくは、<xref linkend="vine-default" /> を参照してください。
    </para>

    <sect2>
      <title>vine-default 設定ファイル</title>
      <para>
	vine-default 設定ファイルには、
	<xref linkend="distribution-wide-configuration" />
	により個別の RPM パッケージごとに設定された vine-default 
	を制御するための設定を記述できます。

	<figure id="fig-emacs23-vine-default-el">
	  <title>~/.emacs.d/emacs23-vine-default.el</title>
	  <screen>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  -*- coding: utf-8-unix -*-
;;  FSF Emacs 23 用 vine-default 設定ファイル
;;    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Vine Linux のデフォルト設定を無効にしたい場合は、
;; 以下を有効にしてください。
;; (setq vine-default nil)

;; 環境変数 EMACS_IME と異なる IME を使いたい場合は、
;; 以下を有効にして設定することができます。
;; (setq emacs-ime "atokx3");; anthy-el atokx3 ibus-el mozc tamago scim scim-bridge skk wnn7egg

;; マクロサーチパスの追加
;; 例えば、~/.emacs.d/local 以下にユーザ用の *.el, *.elc を置けます。
;; (add-to-list 'load-path "~/.emacs.d/local")
;; (add-to-list 'load-path "~/lib/emacs")
;; (add-to-list 'load-path "~/.emacs.d/auto-install")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Local Variables:
;; mode: emacs-lisp
;; End:
	  </screen>
	</figure>

      </para>
    </sect2>

    <sect2>
      <title>ユーザ初期設定ファイル</title>
      <para>
	ユーザ初期設定ファイルには、
	Emacs に関わる設定を自由に記述できます。

	<figure id="fig-init-el">
	  <title>~/.emacs.d/init.el</title>
	  <screen>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  -*- coding: utf-8-unix -*-
;;  FSF Emacs 初期設定ファイル
;;    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Local Variables:
;; mode: emacs-lisp
;; End:
	  </screen>
	</figure>

	<important>
	  <title>デフォルトのユーザ初期設定ファイルを変更しました！</title>
	  <para>
	    Vine Linux 6 では、デフォルトのユーザ初期設定ファイルとして、
	    <filename>${HOME}/.emacs.d/init.el</filename> を推奨します。
	  </para>
	  <para>
	    Emacs は通常、
	    <filename>~/.emacs</filename>, 
	    <filename>~/.emacs.el</filename>, 
	    <filename>~/.emacs.d/init.el</filename> の順番に探し、
	    一番最初に見つけたファイルを
	    「デフォルトのユーザ初期設定ファイル」とする挙動をします。
	    したがいまして、Vine Linux 6 の Emacs においても、
	    従来の <filename>~/.emacs.el</filename> を
	    「デフォルトのユーザ初期設定ファイル」として利用することもできますが、
	    推奨しません。
	  </para>
	</important>

      </para>

    </sect2>

  </sect1>

 </chapter>

 <chapter id="vine-default">
   <title>Vine Linux のデフォルト設定：vine-default</title>
   <para>
     Vine Linux の Emacs では、
     Emacs 上で動作するアプリケーションの 
     RPM パッケージに初期設定が含まれています（<xref linkend="distribution-wide-configuration" />）。
     そのため、
     ユーザ初期設定ファイル
     <filename>~/.emacs.d/init.el</filename>（<xref linkend="fig-init-el" />）
     に何も設定を記述しなくても、
     elisp アプリケーションがある程度使えるようになっています。
     この Emacs における Vine Linux のデフォルト設定を 
     <emphasis>vine-default</emphasis> と呼んでいます。
   </para>

   <sect1 id="vine-default-usage">
     <title>使い方</title>
     <para>
       vine-default は、
       /usr/share/emacs-23.3/site-lisp 以下に格納されています。
       <itemizedlist>
	 <listitem>
	   <para>
	     vine-default-base.el：Emacs の基本的な設定
	   </para>
	 </listitem>
	 <listitem>
	   <para>
	     vine-default-faces.el：Emacs のフォントやカラーの設定
	   </para>
	 </listitem>
	 <listitem>
	   <para>
	     <emphasis>package</emphasis>/vine-default-<emphasis>package</emphasis>.el：<emphasis>package</emphasis> の設定 
	   </para>
	 </listitem>
       </itemizedlist>
     </para>

   <para>
    Emacs を起動すると、
    デフォルトで vine-default の boolean が t になっているので、
    vine-default を読み込みます。
   </para>

   <sect2>
     <title>vine-default をすべて無効にする</title>
     <para>
       もし vine-default をすべて無効にしたい場合は、
       <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
       に
       <screen>(setq vine-default nil)</screen>
       を設定します。
       この場合は、メニューバーと言語ロケール以外は何も設定されていません。
     </para>
   </sect2>

   <sect2>
     <title>一部の vine-default を無効にする</title>
     <para>
       vine-default のうち、いくつかの設定を無効にすることができます。
       各 vine-default は、vine-default-<emphasis>name</emphasis> の 
       boolean が定義されていて、
       デフォルトでは t になっています。
     </para>

     <para>
       例えば、
       vine-default-base, 
       vine-default-faces, 
       vine-default-yatex, 
       vine-default-mew 
       を無効にしたい場合は、
       <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
       に
       <screen>
(setq vine-default-base nil
      vine-default-faces nil
      vine-default-yatex nil
      vine-default-mew nil
    )
       </screen>
       を設定します。
     </para>
   </sect2>

   <sect2>
     <title>一部の vine-default だけを有効にする</title>
     <para>
       いくつかの Emacs Lisp パッケージのみを有効にしたいときは、
       一旦すべての vine-default を無効にした上で、
       いくつかの vine-default を有効にしてください。
     </para>

     <para>
       例えば、
       vine-default.yatex, 
       vine-default-tamago 
       のみを有効にしたい場合は、
       まず、
       <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
       に
       <screen>(setq vine-default nil)</screen>
       を設定します。つぎに、
       <filename>~/.emacs.d/init.el</filename>（<xref linkend="fig-init-el" />）
       の然るべきところに
       <screen>(require 'vine-default-yatex)</screen>
       と
       <screen>(require 'vine-default-tamago)</screen>
       を設定します。
     </para>
   </sect2>

   </sect1>

  <sect1 id="show-vine-default">
   <title>インストールされている vine-default の設定を閲覧</title>

   <para>
    Emacs 上からインストールされている 
    elisp パッケージにあらかじめ設定されている 
    vine-default の設定を閲覧できます。
   </para>

   <para>
    Emacs 上で
    <screen>M-x show-vine-default</screen>
    を実行すると、
    起動している Emacs のバージョンに対応した 
    vine-default の設定を閲覧できます。
   </para>

   <note>
     <para>
       <command>M-x show-vine-default</command> 
       で表示される vine-default の設定は、
       インストールされている vine-default の設定をすべて表示します。
       したがいまして、
       ある vine-default-<emphasis>package</emphasis> 
       の設定を無効にしていたとしても、
       その設定は、
       <command>M-x show-vine-default</command> 
       で表示される設定の中にも現れます。
     </para>
   </note>

  </sect1>
  
  <sect1 id="emacs-ime">
    <title>IME</title>
    <para>
      Emacs 上におけるデフォルトの IME は、
      X 上におけるそれと連動して、
      <command>setime</command> 
      コマンドなどで設定される環境変数 EMACS_IME で決定されます<footnote>
      <para>
	Vine Linux 6 の初期設定では、各ユーザのホームディレクトリに作成される
	<filename>~/.Xresources</filename> で 
	<varname>Emacs*useXIM</varname> の値として
	<literal>false</literal>が設定されているため、XIMは使われません。
      </para>
      </footnote><footnote>
      <para>
	Vine Linux 5 での初期設定では、
	tamago パッケージがインストールされている場合は
	tamago の Anthy インタフェースが使われます。
	tamago パッケージをインストールしていない場合は 
	emacs パッケージに同梱されている
	LEIM (Library of Emacs Input Method) が使われます。
	LEIM では Vine Linux 5 標準のかな漢字変換システム Anthy を使いませんので、
	変換効率が低くなってしまいます。
      </para>
      </footnote>。
   </para>

   <para>
     環境変数 <varname>EMACS_IME</varname> と異なる IME を使いたい場合は、
     <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
     で <varname>emacs-ime</varname> の値に指定してください。
     anthy-el パッケージに含まれる
     <filename>anthy.el</filename> を使うときは、次のように設定します<footnote>
     <para>
       指定する値は<xref linkend="emacs-ime-list"/>を参照してください。
     </para>
     </footnote>。
     <screen>(setq emacs-ime "anthy-el")</screen>
   </para>
  </sect1>

  <sect1 id="vine-default-framework">
    <title>vine-default の仕組み</title>
    <para>
      vine-default は、以下のようにして 
      Vine Linux のデフォルト設定が読み込まれます。
      
      <orderedlist>
	<listitem>
	  <para>
	    それぞれの elisp アプリケーションの初期設定ファイル
	    <filename>/etc/emacs-23.3/site-start.d/*-init.el</filename> 
	    を然るべき順序で読み込む
	  </para>
	</listitem>
	<listitem>
	  <para>
	    vine-default-setup-hook に、
	    各 elisp アプリケーションの 
	    vine-default-<emphasis>package</emphasis> 
	    を然るべき順序でひっかけておく
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	    を参照して、それぞれの 
	    vine-default-<emphasis>package</emphasis> 
	    の挙動がきまる
	  </para>
	</listitem>
	<listitem>
	  <para>
	    vine-default-setup を実行することで、
	    vine-default-setup-hook にひっかけていた
	    vine-default-<emphasis>package</emphasis> が
	    <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	    に応じて、読み込まれる。
	  </para>
	</listitem>
      </orderedlist>

      実際に、以下のような順序で vine-default に関するファイルを読み込み、
      vine-default を実行します。
      <orderedlist>
	<listitem>
	  <para>
	    <filename>/usr/share/emacs-23.3/site-lisp/site-start.el</filename>
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <filename>/etc/emacs-23.3/site-start.d/XXpackage-init.el</filename> (X ∈ {0, 1, 2,..., 9})
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <filename>/etc/emacs/emacs23-local.el</filename>
	  </para>
	</listitem>
	<listitem>
	  <para>
	    vine-default 用設定ファイル
	    <filename>${HOME}/.emacs.d/emacs23-vine-default.el</filename>
	  </para>
	</listitem>
	<listitem>
	  <para>
	    <command>vine-default-setup</command> を実行：
	    <filename>/usr/share/emacs-23.3/site-lisp/</filename> 以下の
	    <itemizedlist>
	      <listitem>
		<para>
		  <filename>vine-default-base.el</filename>, 
		  <filename>vine-default-faces.el</filename>
		</para>
	      </listitem>
	      <listitem>
		<para>
		  <filename>package/vine-default-package.el</filename>
		</para>
	      </listitem>
	    </itemizedlist>
	  </para>
	</listitem>
	<listitem>
	  <para>
	    デフォルトのユーザ初期設定ファイル
	    <filename>${HOME}/.emacs.d/init.el</filename>
	  </para>
	</listitem>
      </orderedlist>

      <important id="vine-default-framework-diff-vine5-vine6">
	<title>Vine Linux 5 から Vine Linux 6 への変更</title>
	<para>
	  Vine Linux 6 の vine-default の仕組みは、
	  Vine Linux 5 の vine-default からいくつか改良しました。
	  主な変更点は、以下のようになります。
	  <itemizedlist>
	    <listitem>
	      <para>
		vine-default を呼ぶタイミングを改善するときに、
		vine-default 設定ファイル
		<filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
		を設けました。
		これにより、ユーザ自身の Emacs に関する設定から 
		vine-default に関する設定のみを分離できます。
	      </para>
	    </listitem>
	    <listitem>
	      <para>
		vine-default を呼ぶタイミングを改善したことにより、
		after-vine-default-setup-hook を廃止しました。
		これにより、vine-default に関する設定が、
		ユーザ初期設定ファイル
		<filename>~/.emacs.d/init.el</filename>（<xref linkend="fig-init-el" />）
		に混在しません。
	      </para>
	    </listitem>
	    <listitem>
	      <para>
		システム全体での設定（<xref linkend="system-wide-configuration" />）を担う設定ファイル名が 
		<filename>/etc/emacs/emacs-23-local.el</filename> 
		から 
		<filename>/etc/emacs/emacs23-local.el</filename> 
		へ変更
	      </para>
	    </listitem>
	  </itemizedlist>
	</para>
      </important>
      
    </para>

    <sect2 id="vine-default-framework-site-start-el">
      <title>vine-default に関する関数とフック</title>
      <para>
	具体的には、
	<filename>/usr/share/emacs-23.3/site-lisp/site-start.el</filename> 
	に、以下のような関数とフックを定義しています。
	<screen>
(defcustom vine-default t
  "A boolean for all Vine Linux default settings"
  :type 'boolean)
(if (equal (getenv "LOGNAME") "root") 
    (setq vine-default nil))

(defcustom vine-default-base t
  "A boolean for vine-default-base"
  :type 'boolean)

(defcustom vine-default-faces t
  "A boolean for vine-default-faces"
  :type 'boolean)

(defvar vine-default-setup-hook nil
  "List of functions to be called at vine-default-setup")

(defun vine-default-setup ()
  "A function for setup to default configurations of Vine Linux"
  (when vine-default
    (message "Starting vine-default-setup ...")
    (when vine-default-base 
      (message "Loading vine-default-base ...")
      (require 'vine-default-base))
    (when vine-default-faces 
      (message "Loading vine-default-faces ...")
      (require 'vine-default-faces))
    (run-hooks 'vine-default-setup-hook)
    ;; (run-hooks 'after-vine-default-setup-hook); obsolete
    )
  )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; run functions from the /etc/emacs-23.3/site-start.d directory
;;; Files in this directory ending with ".el" are run on startup
(mapc 'load (directory-files "/etc/emacs-23.3/site-start.d" t "\\.el\\'"))

;;; load local configuration
(if (file-exists-p (expand-file-name "/etc/emacs/emacs23-local.el"))
    (load (expand-file-name "/etc/emacs/emacs23-local.el")))

;;; load vine-default configuration per user before vine-default-setup
(if (file-exists-p (expand-file-name "~/.emacs.d/emacs23-vine-default.el"))
    (load (expand-file-name "~/.emacs.d/emacs23-vine-default.el")))

;;; run vine-default-setup
(vine-default-setup)
	</screen>
      </para>
    </sect2>

    <sect2 id="vine-default-framework-package-init-el">
      <title>各 elisp アプリケーションの vine-default-<emphasis>package</emphasis></title>
      <para>
	例えば、ibus-el の場合は
	<filename>/etc/emacs-23.3/site-start.d/95ibus-el-init.el</filename> 
	に以下のような設定をしています。
	<screen>
(defcustom vine-default-ibus-el t
  "A boolean for vine-default-ibus-el"
  :type 'boolean)

(add-hook 'vine-default-setup-hook
          (lambda()
            (when vine-default-ibus-el
	      (message "Loading vine-default-ibus-el ...")
	      (require 'vine-default-ibus-el))))
	</screen>
	
	<filename>/usr/share/emacs-23.3/site-lisp/ibus-el/vine-default-ibus-el.el</filename> には、
	ibus-el に関するデフォルト設定を記述して、
	(provide 'vine-default-ibus-el) を提供しています。
      </para>
    </sect2>
    
  </sect1>

  <sect1 id="vine-default-customize">
    <title>カスタマイズ</title>
    <para>
      vine-default に関するカスタマイズの例を紹介します。
    </para>

    <sect2 id="vine-default-customize-system-wide-vine-default">
      <title>/etc/emacs/emacs23-local.el を用いた vine-default の変更</title>
      <para>
	システム全体で vine-default をすべて無効にしたい場合は、
	<filename>/etc/emacs/emacs23-local.el</filename>（<xref linkend="fig-emacs23-local-el" />）
	に
	<screen>(setq vine-default nil)</screen>
	を設定するのもよいでしょう。
	この設定を施したシステムにおいて、
	あるユーザが vine-default をすべて有効にしたい場合は、
	<filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	に
	<screen>(setq vine-default t)</screen>
	を設定します。
      </para>
    </sect2>

    <sect2 id="vine-default-customize-add-to-list-load-path">
      <title>マクロサーチパスの追加</title>
      <para>
	<filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	に、ユーザのマクロサーチパスのディレクトリをまとめて設定しておくと、
	便利でしょう。
      </para>
      <para>
	例えば、<filename>~/.emacs.d/local</filename> を追加したい場合、
	<filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	に
	<screen>(add-to-list 'load-path "~/.emacs.d/local")</screen>
	を設定します。

	<note>
	  <para>
	    Vine Linux 6 の Emacs 環境では、
	    従来、ユーザのマクロサーチパスのディレクトリであった
	    <filename>~/lib/emacs</filename> を設けていません。
	    必要であれば、
	    <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	    に
	    <screen>(add-to-list 'load-path "~/lib/emacs")</screen>
	    を設定します。
	  </para>
	</note>

      </para>
    </sect2>

    <sect2 id="vine-default-customize-confliction-wl-wl-beta">
      <title>wl-2.14.0 と wl-beta-2.15.9 との共存</title>
      <para>
	Wanderlust の安定版 2.14.0、開発版 2.15.9 は、
	それぞれ wl, wl-beta パッケージにより提供されます。
	しかしながら、
	<command>M-x wl</command> を実行して起動できるバージョンは、
	どちらか一方のみです。
	そこで wl-beta を常用したい場合は、
	<filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	に
	<screen>
(setq vine-default-wl nil)
	</screen>
	を設定します。
      </para>
    </sect2>

    <sect2 id="vine-default-customize-confliction-auctex-yatex">
      <title>AUCTeX と YaTeX の共存</title>
      <para>
	AUCTeX, YaTeX は、それぞれ auctex, yatex パッケージにより提供されます。
	どちらも TeX 入力支援環境ですが、
	TeX 関連ファイルに依存するために同一環境でどちらのユーザも存在する場合に、
	ファイル関連で衝突してしまいます。
      </para>

      <sect3 id="vine-default-customize-confliction-auctex-yatex-system-wide">
	<title>システム全体での設定で対応</title>
	<para>
	  システム全体での設定（<xref linkend="system-wide-configuration" />）で対応する場合は、以下のような方法が考えられます。
	  <itemizedlist>
	    <listitem>
	      <para>システム全体での設定で AUCTeX と YaTeX に関するデフォルト設定を無効にする</para>
	    </listitem>
	    <listitem>
	      <para>ユーザごとに AUCTeX または YaTeX の設定をする</para>
	    </listitem>
	  </itemizedlist>
	</para>
	<para>
	  まず、<filename>/etc/emacs/emacs23-local.el</filename>（<xref linkend="fig-emacs23-local-el" />）に
	<screen>
(setq vine-default-auctex nil
      vine-default-preview-latex nil
      vine-default-yatex nil
      vine-default-yahtml nil
    )
	</screen>
	を設定します。
	</para>
	<para>
	  つぎに、ユーザ初期設定ファイル
	  <filename>~/.emacs.d/init.el</filename>（<xref linkend="fig-init-el" />）以降に、
	  AUCTeX または YaTeX の設定を記述します。
	  例えば、やてふの設定は、
	  Vine Linux のデフォルト設定のまま使いたい場合、
	  <screen>(require 'vine-default-yatex)</screen>
	  を記述します。
	</para>
      </sect3>

      <sect3 id="vine-default-customize-confliction-auctex-yatex-per-user">
	<title>ユーザごとの設定で対応</title>
	<para>
	  YaTeX ユーザは、
	  <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	  に
	  <screen>
(setq vine-default-auctex nil
      vine-default-preview-latex nil
    )
	  </screen>
	  を設定します。
	</para>
	<para>
	  AUCTeX ユーザは、
	  <filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	  に
	  <screen>
(setq vine-default-yatex nil
      vine-default-yahtml nil
    )
	  </screen>
	  を設定します。
	</para>
      </sect3>
    </sect2>

    <sect2 id="vine-default-customize-YaTeX-inhibit-prefix-letter">
      <title>YaTeX のデフォルトプレフィックスを従来のものに戻す</title>
      <para>
	YaTeX 製作者の推奨により、
	YaTeX のデフォルトプレフィックスを vine-default-yatex で変更しています。
	しかしながら、従来のデフォルトプレフィックスに戻したい場合は、
	<filename>~/.emacs.d/emacs23-vine-default.el</filename>（<xref linkend="fig-emacs23-vine-default-el" />）
	に
	<screen>
;; [推奨] デフォルトプレフィックスの変更 [yatex:04567]
;; だけど、頑なにデフォルトのままにする
(setq YaTeX-inhibit-prefix-letter nil)
	</screen>
	を設定します。

      </para>
    </sect2>

    <!-- <sect2 id="vine-default-customize-"> -->
    <!--   <title></title> -->
    <!--   <para> -->
    <!--   </para> -->
    <!-- </sect2> -->

  </sect1>

</chapter>

 <chapter id="emacs-customize">
   <title>Emacs のカスタマイズ</title>

   <para>
     Emacs をカスタマイズしていくには、
     <itemizedlist>
       <listitem>
	 <para>
	   Emacs が持っているカスタマイズの仕組みを利用する
	 </para>
       </listitem>
       <listitem>
	 <para>
	   自分で設定ファイルに設定や関数などを書いていく
	 </para>
       </listitem>
     </itemizedlist>
     という二つの方法があります。
   </para>

   <sect1 id="emacs-customize-saving-customizations">
     <title>設定ファイル</title>
     <para>
       ユーザ初期設定ファイル
       <filename>~/.emacs.d/init.el</filename>（<xref linkend="fig-init-el" />）
       は、<xref linkend="vine-default" /> 以外の設定を自由に記述できます。
     </para>
     <para>
       カスタマイズの仕組みを利用して設定した設定は、
       デフォルトでユーザ初期設定ファイル
       <filename>~/.emacs.d/init.el</filename>
       の末尾に追記されます。
       これらの設定を別のファイルにまとめたい場合は、あらかじめ
       <filename>~/.emacs.d/init.el</filename>
       にカスタムファイルを設定します。
       例えば、以下のようにカスタムファイルを設定すると、
       カスタマイズの仕組みを利用して設定した設定は、     
       <filename>~/.emacs.d/custom.el</filename>
       に保存されます。
       <screen>
;; カスタムファイルの指定
(setq custom-file "~/.emacs.d/custom.el")
(if (file-exists-p (expand-file-name custom-file))
    (load-file (expand-file-name custom-file)))
       </screen>
     </para>
   </sect1>

   <sect1 id="emacs-customize-from-menu-bar-options">
     <title>メニューバーのオプションを利用する</title>
     <para>
       Emacs の外観に関する基本的な設定は、
       メニューバーの [オプション] から設定できます。
       いくつか設定を変更した後、
       メニューバーの [オプション] → [オプションの保存] をすると、
       カスタマイズの仕組みを利用して設定としてが保存されます。
       例えば、
       <itemizedlist>
	 <listitem><para>検索で大文字・小文字を区別しない</para></listitem>
	 <listitem><para>[表示/非表示] -> [ツールバー] のチェックをはずす</para></listitem>
	 <listitem><para>[標準フォントを設定...] から Ricty Regular 12pt を指定する</para></listitem>
       </itemizedlist>
       のような変更をすると、以下のように
       デフォルトで <filename>~/.emacs.d/init.el</filename> の末尾に、
       追記されます。
       <screen>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  -*- coding: utf-8-unix -*-
;;  FSF Emacs 初期設定ファイル
;;    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(case-fold-search nil)
 '(tool-bar-mode nil))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 120 :width normal :foundry "unknown" :family "Ricty")))))
;; Local Variables:
;; mode: emacs-lisp
;; End:
       </screen>
     </para>
   </sect1>

   <sect1 id="utils-1-10-3">
     <title>カスタマイズの仕組みを利用する</title>
     <para>
       メニューバーの
       [オプション] → [カスタマイズ] → [トップレベルグループ] 
       を選択する、または、
       <command>M-x customize</command> を実行すると、
       <xref linkend="fig-emacs-M-x-customize" /> 
       のようなカスタマイズの画面になります。
     </para>
     
     <para>
       TAB キーを押すことで、
       アンダーラインのある部分、
       ボタンになっている部分（<guibutton>Set for current session</guibutton> など）、
       文字の入力が可能な部分にカーソルが移動します。
       Shift+TAB でカーソルが逆方向（上）に移動します。
       Enter キーで選択、確定です。
       <guibutton>Exit</guibutton> を選択すると、閉じます。

       <figure id="fig-emacs-M-x-customize">
	 <title>カスタマイズの画面</title>
	 <graphic fileref="figures/emacs-M-x-customize.png" />
       </figure>

       ここで操作して設定した内容は、
       デフォルトで <filename>~/.emacs.d/init.el</filename> の末尾に、
       追記されます。
     </para>

     <para>
       なお、customize は、細分化されていて、
       <command>M-x customize</command>	の他に、
       <command>M-x customize-face</command>, 
       <command>M-x customize-group</command>, 
       <command>M-x customize-variable</command> 
       などとさまざまなものがあります。
       メニューバーの [オプション] → [カスタマイズ] 内の項目を見る、
       または、
       <command>M-x customize</command> 
       と入力して TAB キーを押して補完候補を見るとよいでしょう。
     </para>

     <example id="customize-variable">
       <title>TAB の幅を設定する</title>
       <para>
	 ここでは、<command>M-x customize-variable</command> を利用して、
	 TAB の幅 を設定してみます。
	 <command>M-x customize-variable</command> 
	 と入力し Enterキーを押します<footnote>
	   <para>
	   TAB キーで補完ができます。
	   <command>M-x cus</command> くらいまで入力したら、
	   TAB キーをおしてみてください。
	   <command>M-x customize</command> となるはずです。
	   さらに -v と入力して TAB キーを押すと、
	   <command>M-x customize-variable</command> と補完されます。
	   </para>
	 </footnote>。
	 画面最下部のミニバッファに 
	 Customize variable: と表示されたら、
	 tab-width と入力し Enter キーを押します<footnote>
	   <para>
	     これも TAB キーで補完が出来ます。
	   </para>
	 </footnote>。
       </para>
  
       <para>
	 <xref linkend="emacs-M-x-customize-variable" />
	 のように画面が切り替わります。
  
	 <figure id="emacs-M-x-customize-variable">
	   <title>emacsの customize-variable の画面</title>
	   <graphic fileref="figures/emacs-M-x-customize-variable.png" />
	 </figure>

	 TAB キーを押して、
	 8 という数字が表示されているところまでカーソルを移動し、
	 C-d で 8 という文字を削除し、数字を入力します。
	 例えば、4 とすると、TAB の幅が元の幅の半分になります。
       </para>

       <para>
	 <guibutton>Set for current session</guibutton> 
	 というボタンのところまで移動し、Enter キーを押すと、
	 一時的に設定を有効にした状態になります。
	 数値は保存されないので、次回起動時には元の値 8 にもどります。
       </para>
       <para>
	 <guibutton>Save for future sessions</guibutton> のボタンで 
	 Enter キーを押すと、この数値が、
	 設定ファイルに書き込まれて保存され、
	 次回 Emacs を起動した時に利用できるようになります。
       </para>
       <para>
	 <guibutton>Undo edits</guibutton> のボタンで、
	 入力した数値が元にもどります。
       </para>
       <para>
         <guibutton>Reset to saved</guibutton> のボタンで、
	 前回保存した時の値にもどります。
       </para>
       <para>
         <guibutton>Erase customizations</guibutton> のボタンで、
         設定した数値が取り消され、設定ファイルにあった記述も削除されます。
       </para>
       <para>
	 数値を入力し、
	 <guibutton>Set for current session</guibutton> 
	 のボタンを押してテストして、
	 適当な値になるまで customize を行うという作業を繰り返して、
	 それから <guibutton>Save for future sessions</guibutton> 
	 で保存するという作業をします。
       </para>
  
       <para>
	 ここでは、<guibutton>Save for future sessions</guibutton> 
	 で保存してしまっていいと思います。
       </para>
  
       <para>
	 保存したら、<guibutton>Exit</guibutton> のボタンをクリックします。
	 M-&lt; でページの先頭まで戻ると早いです。
       </para>
  
       <para>
         <guibutton>Save for future sessions</guibutton> で保存すると、
	 以下のように
	 デフォルトで <filename>~/.emacs.d/init.el</filename> の末尾に、
	 追記されます。
       </para>
  
       <screen>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(tab-width 4))
       </screen>

       <para>
         この設定値を変更する時には、直接編集するのではなく 
         <command>M-x customize</command> 
	 などを使って再度設定するようにしてください。
       </para>
     </example>

     <note>
       <para>
         ユーザ初期設定ファイル 
         <filename>~/.emacs.d/init.el</filename> 
         などに書かれている項目を設定する場合は、
         設定ファイルを直接編集するのが無難です。
       </para>
     </note>

   </sect1>
   <sect1 id="emacs-customize-managing-multiple-versions">
     <title>複数バージョンの管理</title>
     <para>
       Emacs-23.3 と Emacs-24.0.93 とのユーザ初期設定ファイルを管理するためには、
       <filename>~/.emacs.d/init.el</filename> を 
       Emacs バージョン分岐用ファイルにする必要があります。
       この節では、複数バージョンの管理に関する一例を紹介します。
     </para>

     <example id="emacs-customize-managing-multiple-versions-init-el">
       <title>複数バージョン分岐用ファイル ~/.emacs.d/init.el</title>
       <para>
	 以下のような <filename>~/.emacs.d/init.el</filename> に変更すると、
	 Emacs-23.3, Emacs-24.0.93 のユーザ初期設定ファイルは、それぞれ
	 <filename>~/.emacs.d/emacs23-init.el</filename>, 
	 <filename>~/.emacs.d/emacs24-init.el</filename>
	 になります。
	 また、必要であれば、以下のようにカスタマイズによる設定を、
	 別ファイルに保存してもよいでしょう。
	 Emacs-23.3, Emacs-24.0.93 のカスタムファイルは、それぞれ
	 <filename>~/.emacs.d/emacs23-custom.el</filename>, 
	 <filename>~/.emacs.d/emacs24-custom.el</filename>
	 になります。
	 <screen>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;  -*- coding: utf-8-unix -*-
;;  FSF Emacs バージョン分岐用ファイル
;;    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; ユーザ初期設定ファイルの指定
(setq user-init-file 
      (concat "~/.emacs.d/emacs" (number-to-string emacs-major-version) 
	      "-init.el"))

;; ;; カスタムファイルの指定
;; (setq custom-file 
;;   (concat "~/.emacs.d/emacs" (number-to-string emacs-major-version) 
;; 	  "-custom.el"))

(if (file-exists-p (expand-file-name user-init-file))
    (load-file (expand-file-name user-init-file)))
;; (if (file-exists-p (expand-file-name custom-file))
;;     (load-file (expand-file-name custom-file)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Local Variables:
;; mode: emacs-lisp
;; End:
	 </screen>
       </para>
       
       <para>
	 Emacs バージョンによらずに、
	 共通な設定をまとめて記述しておきたい場合は、
	 <filename>~/.emacs.d/init.el</filename> 
	 に直接記述するか、以下の例の 
	 <filename>~/.emacs.d/emacs-common.el</filename> 
	 のようなファイルを設けてもよいでしょう。
	 <screen>
;; 個人的な設定ファイル: Emacs バージョン共通
(setq my-emacs-common-file "~/.emacs.d/emacs-common.el")
(if (file-exists-p (expand-file-name my-emacs-common-file))
    (load-file (expand-file-name my-emacs-common-file)))
	 </screen>
       </para>
     </example>

   </sect1>
   
 </chapter>

 <appendix id="vine4-emacs">
   <title>Vine Linux 4.2 の Emacs 環境</title>

   <sect1 id="vine4-emacs-system-wide-configuration">
     <title>「システム全体での設定」の課題</title>
     <para>
       Vine Linux 4.2 以前の Emacs では、 
       Emacs Lisp の RPM パッケージに含まれていた 
       <filename>site-start.el</filename> に 
       Emacs Lisp の設定を記述していました。
       つまり、Vine Linux 5 以降でいう
       「個別の RPM パッケージに含まれている設定（<xref linkend="distribution-wide-configuration" />）」
       と
       「システム全体での設定（<xref linkend="system-wide-configuration" />）」
       が分離されていませんでした。
       そのため、RPM パッケージで設定されている内容を変更するために
       <filename>site-start.el</filename> ファイルを編集した場合、
       RPM パッケージがアップデートされると再び設定を実施する必要がありました。
     </para>
     <para>
      Vine Linux 5 以降では、
      「<xref linkend="distribution-wide-configuration" />」
      と
      「<xref linkend="system-wide-configuration" />」
      を分離することにより、この問題を解決しています。
     </para>
   </sect1>

   <sect1 id="vine4-emacs-my-el">
     <title>Vine Linux 4.2 以前の ~/.emacs.my.el</title>
     <para>
       Vine Linux 4.2 以前におけるユーザ初期設定ファイル
       <filename>~/.emacs.el</filename> には、
       ユーザ用初期化ファイル <filename>~/.emacs.my.el</filename>
       <footnote>
	 <para>
	   個人用設定を書くためのファイルでした。
	 </para>
       </footnote>
       があれば、
       それを読み込む仕組みがありました。
       Vine Linux 5 以降では、<xref linkend="vine-default" /> に移行したため、
       <filename>~/.emacs.my.el</filename> を読み込む仕組みは廃止しました。
     </para>
     <para>
       もし過去の <filename>~/.emacs.my.el</filename> を流用したい場合は、
       以下のようにして
       <filename>~/.emacs.my.el</filename> 
       を読み込ませることができます。
       <screen>
(if (file-exists-p (expand-file-name "~/.emacs.my.el"))
    (load (expand-file-name "~/.emacs.my.el") nil t nil))
       </screen>
       ただし、Emacs-23.3 と Emacs-22 以前は随分仕様が変わっているので、
       Vine Linux 4 の Emacs-22 などで使っていた 
       <filename>~/.emacs.my.el</filename> 
       をそのまま流用できるとはかぎりません。
       Vine Linux 6 では、
       いままでの <filename>~/.emacs.my.el</filename> の設定を改めて、
       <filename>~/.emacs.d/init.el</filename>（<xref linkend="fig-init-el" />）以下に設定することを推奨します。
     </para>
   </sect1>

 </appendix>

 <appendix id="emacs-ime-list">
   <title>emacs-ime に設定できる値の一覧</title>
   <para>
     Vine Linux 5 で emacs-ime に設定できる値は次の通りです。
     ただし、現在はよく使われるもののみを記載しています。
   </para>

   <table frame="all">
     <title>emacs-ime に設定できる値の一覧 (抜粋)</title>
     <tgroup cols="3">
       <thead>
	 <row>
	   <entry>使うIME</entry>
	   <entry>emacs-ime に設定する値</entry>
	   <entry>Vine Linux 5 でのパッケージ名</entry>
	 </row>
       </thead>
       <tbody>
	 <row>
	   <entry>Anthy (japanese-egg-anthy) <footnote id="emacs-ime-list-leim"><para>LEIMを使用。</para></footnote></entry>
	   <entry>scim、SCIM、anthy、Anthy、egg-anthy、tamago-anthy</entry>
	   <entry>tamago パッケージ</entry>
	 </row>
	 <row>
	   <entry>Anthy (anthy-el)</entry>
	   <entry>anthy-el、Anthy-el</entry>
	   <entry>anthy-el パッケージ</entry>
	 </row>
	 <row>
	   <entry>SCIM</entry>
	   <entry>scim-bridge、scim-bridge-el</entry>
	   <entry>scim-bridge-el パッケージ</entry>
	 </row>
	 <row>
	   <entry>UIM</entry>
	   <entry>uim、uim-el</entry>
	   <entry morerows="1">uim-el パッケージ</entry>
	 </row>
	 <row>
	   <entry>UIM (japanese-anthy-utf8-uim)<footnoteref linkend="emacs-ime-list-leim"/></entry>
	   <entry>uim-leim</entry>
	 </row>
	 <row>
	   <entry>ibus</entry>
	   <entry>ibus-el、IBus-el</entry>
	   <entry>ibus-el パッケージ</entry>
	 </row>
	 <row>
	   <entry>Mozc (japanese-mozc)<footnoteref linkend="emacs-ime-list-leim"/></entry>
	   <entry>mozc、mozc-el</entry>
	   <entry>mozc-el パッケージ</entry>
	 </row>
	 <row>
	   <entry>SKK (Daredevil SKK)</entry>
	   <entry>skk</entry>
	   <entry>skk パッケージ</entry>
	 </row>
	 <row>
	   <entry>T-Code (tc2)</entry>
	   <entry>tc2、tc-el</entry>
	   <entry>tc-el パッケージ</entry>
	 </row>
	 <row>
	   <entry>ATOK</entry>
	   <entry>iiimecf、IIIMECF、atokx、atokx2、atokx3</entry>
	   <entry>IIIMECF パッケージ</entry>
	 </row>
	 <row>
	   <entry>Wnn、FreeWnn (japanese-egg-wnn)<footnoteref linkend="emacs-ime-list-leim"/></entry>
	   <entry>wnn、Wnn、wnn6、Wnn6、wnn8、Wnn8</entry>
	   <entry>tamago パッケージ</entry>
	 </row>
	 <row>
	   <entry>wnn ななたまご (Wnn7egg)</entry>
	   <entry>wnn7egg、wnn7、Wnn7</entry>
	   <entry>wnn7egg パッケージ</entry>
	 </row>
       </tbody>
     </tgroup>
   </table>
 </appendix>
 
</book>
