M-x find-file, M-x goto-line の流れが面倒だったので作りました。
ongaeshi/jump-to-line · GitHub
行番号付きのテキストにカーソルを合わせて移動することが出来ます。ジャンプ前の位置に戻る事も可能です。
/path/to/a.txt:5 ; /path/to/a.txtの5行目にジャンプ (Ruby形式) ../a.txt:5 ; 相対パス a.txt ; ファイル名だけの場合は1行目に移動 a.txt(1,2) ; C#形式 a.txt, line 1 ; Python形式 a.txt line 1 ; Perl形式
何に使うの?
以下はrubyの'test/unit'のエラーメッセージです。
Process [cd /path/sample/test/ && (ruby -I../lib -I../test ./rake_test_loader.rb test_cli.rb)] exited abnormally : Run options: # Running tests: ....F...... Finished tests in 13.479544s, 0.8161 tests/s, 1.7805 assertions/s. 1) Failure: test_info(TestCLI) [/path/sample/test/test_cli.rb:38]: Expected /Nota registered/ to match "Not registered '/path/sample/test'.\n". 11 tests, 24 assertions, 1 failures, 0 errors, 0 skips
メッセージにはエラーの原因を特定するために大切な情報が含まれています。
- /path/sample/test/test_cli.rb:38
- エラーの起きた場所
- /path/sample/test
- テストを実行したフォルダ
- ./rake_test_loader.rb
- テスト実行時に読み込んだファイル
以下はgccの実行結果です。
$ gcc test.cpp test.cpp: In function ‘int main()’: test.cpp:3: error: ‘ff’ was not declared in this scope test.cpp:4: error: expected `;' before ‘return’
- test.cpp
- エラーが起きたファイル
- test.cpp:3
- 1つ目のエラーが起きた場所
- test.cpp:4
- 2つ目のエラーが起きた場所
プログラムはエラーを特定してもらうために位置付きの情報をたくさん出力しています。jump-to-lineを使うとそこへ簡単に移動することが出来るようになります。
インストール
MELPAに登録されているので package.el を使います。
package.elのインストール方法についてはコチラをどうぞ。
M-x package-list-packages
を実行後・・
jump-to-line
を選択します。
手動インストールも可能です。詳しくはREADMEをどうぞ。
.emacs.d/init.el
(require 'jump-to-line) (global-set-key (kbd "C-c C-j") 'jump-to-line) ; Jump (global-set-key (kbd "C-c b") 'jtl-back) ; Back
使い方
- C-c C-jで指定位置にジャンプ
- カーソル上にジャンプ可能テキストがある場合はそのままジャンプ
- ジャンプ可能テキストが無い場合はジャンプ先テキストを入力可能に
- C-u C-c C-jで別ウィンドウにジャンプ
- C-c bでジャンプ前の位置に戻る