1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Google ColabとJupyter-LabでEmacsキーバインドを使う【完結編】

Last updated at Posted at 2021-04-29

はじめに

長年悩んでいた課題がついに解決したので共有したい。

環境

環境は以下の通り

  • Windows10

対応方法

早速対応方法を記載していく。

1. AutoHotKey のインストール

https://www.autohotkey.com/ などからAutoHotKeyをインストールする。
AutoHotKeyについては、色々情報があるので参考文献を見てほしい。

2. AutoHotKey のスクリプトを作成し実行

emacs.ahkからソースをダウンロードし、is_target関数を以下の通り変更する。そして、そのスクリプトをダブルクリックで実行さればOKだ。

is_target()
{
  IfWinActive,ahk_exe chrome.exe
  {
	WinGetTitle, Title
	If InStr( Title , ".ipynb") > 0 ;
		;MsgBox, The active window is "%Title%".
		Return 0
	If InStr( Title , "JupyterLab") > 0 ;
		;MsgBox, The active window is "%Title%".
		Return 0

  }
  Return 1
}

ソースの解説をしよう。
まず、emacs.ahkは、Emacsのキーバインドを設定したAutoHotKeyのスクリプトになっており、is_target関数に条件がマッチした場合(Return=0)の場合のみ、Emacsキーバインドに変更する。
どういったキーバインドが設定されているかは、githubのぺージを見てほしい。
で、この is_target 関数を、ブラウザがChromeでブラウザのウィンドウタイトルに ".ipynb" が含まれる場合 (Google Colab に対応) もしくは、"JupyterLab" が含まれている場合 (JupyterLab に対応)に、Emacs のキーバインドになるように条件を変更したものが上のソースである。
ブラウザを変更したり、条件を変更したい場合は、AutoHotkeyJpを参考に条件を変更してみるといいだろう。

感想

長年悩んでいたことが立ったこれだけで解決してしまって感動している。
これが所にPyCharmやVSCodeで書いていたが、Jupyterでもガンガンスクリプトが書けそうだ。

ついでに上のis_target関数にQiitaの条件も入れて、このQiitaの記事をEmacsキーバインドで書いている!!。
おそろしく快適である!
皆さんも色々カスタマイズし、色々なアプリケーションでEmacsキーバインドを楽しんでほしい。

参考

1
5
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
1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?