Sublime Text 2 に、 EmacsKillRing パッケージをインストール

Sublime Text 2 にて、 emacs キーバインドを使おうと思い Sublemacspro をインストールしたが、 Ctrl+k の挙動が少し emacs と異なっていた。Ctrl+k は一行分しかバッファにたまらない模様。

そこで、EmacsKillRing パッケージをインストールして、Ctrl+k の挙動を emacs と同じにするようにした。

  • C:\Users\<ユーザ名>\AppData\Roaming\Sublime Text 2\Packages\User 以下に、EmacsKillRing.py を配置
  • C:\Users\<ユーザ名>\AppData\Roaming\Sublime Text 2\Packages\User\Default (Windows).sublime-keymap にて、以下を挿入
    // EmacsKillRing
    // https://github.com/stiang/EmacsKillRing
    {"keys": ["ctrl+w"], "command": "expand_selection", "args": {"to": "word"} },
    {"keys": ["ctrl+k"], "command": "emacs_kill_line" },
    {"keys": ["ctrl+y"], "command": "paste" },
    {"keys": ["ctrl+space"], "command": "emacs_set_mark" },
    {"keys": ["ctrl+w"], "command": "emacs_kill_to_mark" },
    {"keys": ["alt+w"], "command": "emacs_kill_ring_save" },
    //ctrl + g で、コマンドのキャンセルが効かなくなるため、以下はコメントアウト
    //{"keys": ["ctrl+g"], "command": "cancel_mark" }

Sublime Text 2 で、 emacs キーバインドを使う

    • View > Show Console を選択し、出てきた入力画面で以下を入力
import urllib2,os; pf='Package Control.sublime-package'; ipp = sublime.installed_packages_path(); os.makedirs( ipp ) if not os.path.exists(ipp) else None; urllib2.install_opener( urllib2.build_opener( urllib2.ProxyHandler( ))); open( os.path.join( ipp, pf), 'wb' ).write( urllib2.urlopen( 'http://sublime.wbond.net/' +pf.replace( ' ','%20' )).read()); print( 'Please restart Sublime Text to finish installation')
    • Sublime Text 2 を再起動する。
  • Sublemacspro をインストール
    • Tools > Command Palette を選択し、出てきた入力画面で install を入力
    • インストールするパッケージの検索画面が出てくるので、入力欄に emacs と入力し、候補に挙がってくる sublemacspro をインストール。
[
    {"keys": ["ctrl+m"], "command": "insert", "args": {"characters": "\n"}},
    {"keys": ["ctrl+shift+-"], "command": "redo"}
]
  • このほか、以下も入れたら便利だった
    • IMESupport for Sublime Text 2: 日本語をインライン入力できるようにする

Sublime Text 2 の設定ファイル

  • C:\Users\<ユーザ名>\AppData\Roaming\Sublime Text 2\Packages\User 以下の、Preferences.sublime-settings が設定ファイルとなる。
  • 自分は、以下のとおりに書き換えた。
{
    // タブをスペースに変換
    "translate_tabs_to_spaces": true,
    
    // () ,[]内のインデントを揃える
    "indent_to_bracket": true,
    
    // 空行のインデントは取り除かない
    "trim_automatic_white_space": false,
    
    // カーソルがある行をハイライトする
    "highlight_line": true,
    
    // スペースを表示する
    "draw_white_space": "all",
    
    // ファイルの最終行を、改行で終わらせる
    "ensure_newline_at_eof_on_save": true,
    
    // デフォルトの改行コード
    "default_line_ending": "unix",
    
    // タイトルバーにフルパスを表示しない
    "show_full_path": false
}

右クリックメニューに「Terapad で開く」を追加する

  1. 左下の「スタート」を押下、「プログラムとファイルの検索」に、regeditを入力。
  2. HKEY_CLASSES_ROOT > * > shell と進んでゆく。
    • WindowsXPの場合は、HKEY_CLASSES_ROOT > Folder > shell
  3. shell を右クリックし、 新規 > キー を選択。
  4. 新しく出来たキーの名前「新しいキー #1」を、「Terapad で開く」に変更。
    • ここに付ける名前は何でもよい。
    • WindowsXPの場合は、「Terapadで開く」をクリックし、右側に出てくる (規定) をダブルクリックして、値のデータに「Terapad で開く」を入力
  5. Terapad で開く」を右クリックし、 新規 > キー を選択。
  6. 新しく出来たキーの名前「新しいキー #1」を、「command」に変更。
  7. 「command」をクリックし、右側に出てくる (規定)を ダブルクリック。
  8. 値のデータに、以下を入力。
"C:\Program Files\TeraPad\TeraPad.exe" "%1"

Graphvis 使用例 その2

  • 以下の内容で、sample.dot を作成
graph {
    1 -- 6;
    1 -- 12;
    1 -- 15;
    1 -- 16;
    2 -- 3;
    2 -- 8;
    2 -- 10;
    3 -- 4;
    3 -- 6;
    3 -- 9;
    5 -- 6;
    7 -- 15;
    11 -- 16;
    13 -- 15;
    14 -- 15;
}
  • 以下のコマンドを入力
$ dot -Tpng sample.dot -o sample.png
  • 画像 sample.png が出力される

Graphvis 使用例

  • 以下の内容で、sample.dot を作成
digraph {
    rankdir=LR;
    
    0 [ shape = doublecircle, label = "0 \n generate=5" ];
    1 [ shape = doublecircle, label = "1 \n generate=2" ];
    3 [ shape = rect, label = "3 \n consume=2" ];
    4 [ shape = rect, label = "4 \n consume=1" ];
    5 [ shape = rect, label = "5 \n consume=4" ];
    
    0 -> 0 [ label = "1" ];
    0 -> 1 [ label = "2" ];
    0 -> 2 [ label = "5" ];
    1 -> 0 [ label = "1" ];
    1 -> 2 [ label = "8" ];
    2 -> 3 [ label = "1" ];
    2 -> 4 [ label = "7" ];
    3 -> 5 [ label = "2" ];
    3 -> 6 [ label = "5" ];
    4 -> 2 [ label = "7" ];
    4 -> 3 [ label = "5" ];
    4 -> 5 [ label = "1" ];
    6 -> 0 [ label = "5" ];
}
  • 以下のコマンドを入力
$ dot -Tpng sample.dot -o sample.png
  • 画像 sample.png が出力される

Graphviz インストール手順

Graphvis を使えば、データ構造としてのグラフの可視化を簡単に行える。まずはインストールするための手順をメモ。(※自分の環境: Windows7, Cygwin (8.15-1))

PATH="/usr/local/graphviz/bin:${PATH}"
  • .bash_profile を読み込みなおす。
$ source ~/.bash_profile
  • 動作確認。以下のコマンドを実行して、バージョンが表示されたらOK。
$ dot -v