Sublime Text 2 で Docblockr の日本語入力問題を解決する方法

Sublime Text

Sublime Text 2 に DockBlockr というパッケージがあります。 これは PHP の「 PHPDoc 」など関数の説明コメントを記述するのをサポートするためのパッケージです。

このパッケージを入れてコメント内に日本語を書こうとすると Enter 入力時に未確定の日本語が消えてしまうという問題が発生します。 今回はこの解決方法について。

原因

Enter キーのキーコンフィグの設定が悪さをするようです。

対処方法

DocBlockr のデフォルトのキーコンフィグを編集します。 ユーザ用のキーコンフィグを設定することもできそうですが、デフォルトのものを編集する方が素早くかんたんに対応することができます。

具体的には DocBlockr ディレクトリ内の Default.sublime-keymap ファイルの以下の箇所をコメントアウトします。

1:

// // extend a docblock by adding an asterisk at the start
// { "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n${TM_CURRENT_LINE/^\\s*(\\*\\s*).*$/$1/}"},
//   "context": [
//     { "key": "setting.auto_indent",   "operator": "equal",          "operand": true,              "match_all": true },
//     { "key": "selector",              "operator": "equal",          "operand": "comment.block",   "match_all": true },
//     { "key": "auto_complete_visible", "operator": "equal",          "operand": false,             "match_all": true },
//     { "key": "preceding_text",        "operator": "regex_contains", "operand": "^\\s*\\*\\s*\\S", "match_all": true }
//   ]
// },

2:

// // extend a docblock by adding an asterisk at the start
// { "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n${TM_CURRENT_LINE/^\\s*(\\*\\s*).*$/$1/}"},
//   "context": [
//     { "key": "setting.auto_indent",   "operator": "equal",          "operand": true,            "match_all": true },
//     { "key": "selector",              "operator": "equal",          "operand": "comment.block", "match_all": true },
//     { "key": "auto_complete_visible", "operator": "equal",          "operand": false,           "match_all": true },
//     { "key": "preceding_text",        "operator": "regex_contains", "operand": "^\\s*\\*",      "match_all": true }
//   ]
// },

3:

// // extend line comments (// and #)
// { "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n${TM_CURRENT_LINE/^\\s*((?:#|\\/\\/[\\/!]?)\\s*).*/$1/}"},
//   "context": [
//     { "key": "setting.auto_indent",                "operator": "equal",          "operand": true,              "match_all": true },
//     { "key": "setting.jsdocs_extend_double_slash", "operator": "equal",          "operand": true,              "match_all": true },
//     { "key": "selector",                           "operator": "equal",          "operand": "comment.line",    "match_all": true },
//     { "key": "auto_complete_visible",              "operator": "equal",          "operand": false,             "match_all": true },
//     { "key": "preceding_text",                     "operator": "regex_contains", "operand": "^\\s*(\\/\\/[\\/!]?|#)", "match_all": true }
//   ]
// },

好みに応じて他の箇所もコメントアウトしてもよいかと思います。

この方法のデメリットとしては、「パッケージがアップデートされたら編集がリセットされてしまう」ことです。 アップデート頻度はあまり高くないので頻繁に設定をやり直す必要はありませんが、忘れた頃にアップデートされているので注意が必要です。 「いつの間にかまたデフォルトのキーコンフィグが悪さをしてるな」と感じたら再度編集するようにしましょう。

今回は以下のバージョンで確認を行いました。

  • Sublime Text 2 v2.0.2
  • DocBlockr v2.13.2, 30 Mar 2015

追記 20171113: Sublime Text 3 のパッケージについてまとめてみました。興味のある方はよろしければご覧になってみてください。

参考


アバター
後藤隼人 ( ごとうはやと )

ソフトウェア開発やマーケティング支援などをしています。詳しくはこちら