Last active
July 22, 2022 13:17
-
-
Save nenono/98f637f705cf96feddf9 to your computer and use it in GitHub Desktop.
keyhacの設定 ref http://www49.atwiki.jp/ntemacs/pages/25.html / redoの追加くらいしかしてないはず
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: python; coding: utf-8-dos -*- | |
## | |
## Windows の操作を emacs のキーバインドで行うための設定(keyhac版)ver.20151104_02 | |
## | |
# このスクリプトは、keyhac で動作します。 | |
# https://sites.google.com/site/craftware/keyhac | |
# スクリプトですので、使いやすいようにカスタマイズしてご利用ください。 | |
# | |
# この内容は、utf-8-dos の coding-system で config.py の名前でセーブして利用してください。 | |
# また、日本語キーボードか英語キーボードかの指定をスクリプトの最初の方にある is_japanese_keybord | |
# という変数の設定で行ってください。(初期値は、日本語キーボードとなっています。) | |
# | |
# emacs の挙動と明らかに違う動きの部分は以下のとおりです。 | |
# ・左の Ctrlキー と Altキー のみが、emacs用のキーとして認識される。 | |
# ・ESC の二回押下で、ESC を入力できる。 | |
# ・C-o または C-\ で、IME の切り替えが行われる。 | |
# ・C-c、C-z は、Windows の「コピー」、「取り消し」が機能するようにしている。 | |
# ・C-x C-y または A-y で、クリップボードリストを表示する。 | |
# (C-n で選択を移動し、Enter で確定する。C-s、C-r で検索も可能。) | |
# ・C-x o は、一つ前にフォーカスがあったウインドウに移動する。 | |
# NTEmacs から Windowsアプリケーションソフトを起動した際に戻るのに便利。 | |
# (Windows8 では動かないようです。http://jinblog.at.webry.info/201305/article_1.html) | |
# ・C-k を連続して実行しても、クリップボードへの削除文字列の蓄積は行われない。 | |
# C-u による行数指定をすると、削除行を一括してクリップボードに入れることができる。 | |
# ・C-l は、アプリケーションソフト個別対応とする。recenter 関数で個別に指定すること。 | |
# この設定では、Sakura Editor のみ対応している。 | |
# ・キーボードマクロは emacs の挙動と異なり、IME の変換キーも含めた入力したキー | |
# そのものを記録する。このため、キーボードマクロ記録時や再生時、IMEの状態に留意した | |
# 利用が必要。 | |
# ・[A-Z]キーを C-S- 付きで押した時は、S- をとったキー(C-[A-Z])が Windows に入力される。 | |
# (IME 独自設定のコントロールキーを利用する際に便利) | |
from time import sleep | |
from keyhac import * | |
def configure(keymap): | |
# 日本語キーボードかどうかを指定する(True: 日本語キーボード、False: 英語キーボード) | |
is_japanese_keybord = True | |
# emacs のキーバインドに"したくない"アプリケーションソフトを指定する(False を返す) | |
# keyhac のメニューから「内部ログ」を ON にすると processname や classname を確認することができます | |
def is_emacs_target(window): | |
if window.getProcessName() in ("cmd.exe", # cmd | |
"mintty.exe", # mintty | |
"emacs.exe", # Emacs | |
"runemacs.exe", # Emacs | |
"emacs-w32.exe", # Emacs | |
"gvim.exe", # GVim | |
# "eclipse.exe", # Eclipse | |
"firefox.exe", # firefox | |
"xyzzy.exe", # xyzzy | |
#"VirtualBox.exe", # VirtualBox | |
"XWin.exe", # Cygwin/X | |
"Xming.exe", # Xming | |
"putty.exe", # PuTTY | |
"ttermpro.exe", # TeraTerm | |
"MobaXterm.exe", # MobaXterm | |
"TurboVNC.exe", # TurboVNC | |
"vncviewer.exe"): # UltraVNC | |
return False | |
return True | |
# input method の切り替え"のみをしたい"アプリケーションソフトを指定する(True を返す) | |
# 指定できるアプリケーションソフトは、is_emacs_target で除外指定したものからのみとする | |
def is_im_target(window): | |
if window.getProcessName() in ("cmd.exe", # cmd | |
"mintty.exe", # mintty | |
"gvim.exe", # GVim | |
# "eclipse.exe", # Eclipse | |
# "firefox.exe", # firefox | |
"xyzzy.exe", # xyzzy | |
"putty.exe", # PuTTY | |
"ttermpro.exe", # TeraTerm | |
"MobaXterm.exe"): # MobaXterm | |
return True | |
return False | |
keymap_emacs = keymap.defineWindowKeymap(check_func=is_emacs_target) | |
keymap_im = keymap.defineWindowKeymap(check_func=is_im_target) | |
# mark がセットされると True になる | |
keymap_emacs.is_marked = False | |
# 検索が開始されると True になる | |
keymap_emacs.is_searching = False | |
# リストウィンドウで検索が開始されると True になる | |
keymap_emacs.is_searching_list_window = False | |
# キーボードマクロの play 中 は True になる | |
keymap_emacs.is_playing_kmacro = False | |
# universal-argument コマンドが実行されると True になる | |
keymap_emacs.is_universal_argument = False | |
# digit-argument コマンドが実行されると True になる | |
keymap_emacs.is_digit_argument = False | |
# コマンドのリピート回数を設定する | |
keymap_emacs.repeat_counter = 1 | |
######################################################################## | |
## IMEの切替え | |
######################################################################## | |
def toggle_input_method(): | |
keymap.command_InputKey("A-(25)")() | |
if 1: | |
if not keymap_emacs.is_playing_kmacro: | |
sleep(0.05) # delay | |
# IME の状態を取得する | |
if keymap.wnd.getImeStatus(): | |
message = "[あ]" | |
else: | |
message = "[A]" | |
# IMEの状態をバルーンヘルプで表示する | |
keymap.popBalloon("ime_status", message, 500) | |
######################################################################## | |
## ファイル操作 | |
######################################################################## | |
def find_file(): | |
keymap.command_InputKey("C-o")() | |
def save_buffer(): | |
keymap.command_InputKey("C-s")() | |
def write_file(): | |
keymap.command_InputKey("A-f", "A-a")() | |
######################################################################## | |
## カーソル移動 | |
######################################################################## | |
def backward_char(): | |
keymap.command_InputKey("Left")() | |
def forward_char(): | |
keymap.command_InputKey("Right")() | |
def backward_word(): | |
keymap.command_InputKey("C-Left")() | |
def forward_word(): | |
keymap.command_InputKey("C-Right")() | |
def previous_line(): | |
keymap.command_InputKey("Up")() | |
def next_line(): | |
keymap.command_InputKey("Down")() | |
def move_beginning_of_line(): | |
keymap.command_InputKey("Home")() | |
def move_end_of_line(): | |
keymap.command_InputKey("End")() | |
if keymap.getWindow().getClassName() == "_WwG": # Microsoft Word | |
if keymap_emacs.is_marked: | |
keymap.command_InputKey("Left")() | |
def beginning_of_buffer(): | |
keymap.command_InputKey("C-Home")() | |
def end_of_buffer(): | |
keymap.command_InputKey("C-End")() | |
def scroll_up(): | |
keymap.command_InputKey("PageUp")() | |
def scroll_down(): | |
keymap.command_InputKey("PageDown")() | |
def recenter(): | |
if keymap.getWindow().getClassName() == "EditorClient": # Sakura Editor | |
keymap.command_InputKey("C-h")() | |
######################################################################## | |
## カット / コピー / 削除 / アンドゥ | |
######################################################################## | |
def delete_backward_char(): | |
keymap.command_InputKey("Back")() | |
def delete_char(): | |
keymap.command_InputKey("Delete")() | |
def backward_kill_word(repeat=1): | |
keymap_emacs.is_marked = True | |
def move_beginning_of_region(): | |
for i in range(repeat): | |
backward_word() | |
mark(move_beginning_of_region)() | |
delay(kill_region)() | |
def kill_word(repeat=1): | |
keymap_emacs.is_marked = True | |
def move_end_of_region(): | |
for i in range(repeat): | |
forward_word() | |
mark(move_end_of_region)() | |
delay(kill_region)() | |
def kill_line(repeat=1): | |
keymap_emacs.is_marked = True | |
if repeat == 1: | |
mark(move_end_of_line)() | |
delay(keymap.command_InputKey("C-c", "Delete"))() # 改行を消せるようにするため C-x にはしていない | |
else: | |
def move_end_of_region(): | |
if keymap.getWindow().getClassName() == "_WwG": # Microsoft Word | |
for i in range(repeat): | |
next_line() | |
move_beginning_of_line() | |
else: | |
for i in range(repeat - 1): | |
next_line() | |
move_end_of_line() | |
forward_char() | |
mark(move_end_of_region)() | |
delay(kill_region)() | |
def kill_region(): | |
keymap.command_InputKey("C-x")() | |
def kill_ring_save(): | |
keymap.command_InputKey("C-c")() | |
if keymap.getWindow().getClassName() == "EditorClient": # Sakura Editor | |
# 選択されているリージョンのハイライトを解除するために Esc を発行する | |
keymap.command_InputKey("Esc")() | |
def windows_copy(): | |
keymap.command_InputKey("C-c")() | |
def yank(): | |
keymap.command_InputKey("C-v")() | |
def undo(): | |
keymap.command_InputKey("C-z")() | |
def redo(): | |
keymap.command_InputKey("C-y")() | |
def set_mark_command(): | |
if keymap_emacs.is_marked: | |
keymap_emacs.is_marked = False | |
else: | |
keymap_emacs.is_marked = True | |
def mark_whole_buffer(): | |
if keymap.getWindow().getClassName().startswith("EXCEL"): # Microsoft Excel | |
# Excel のセルの中でも機能するようにする対策 | |
keymap.command_InputKey("C-End", "C-S-Home")() | |
else: | |
keymap.command_InputKey("C-Home", "C-a")() | |
def mark_page(): | |
mark_whole_buffer() | |
def open_line(): | |
keymap.command_InputKey("Enter", "Up", "End")() | |
######################################################################## | |
## バッファ / ウインドウ操作 | |
######################################################################## | |
def kill_buffer(): | |
keymap.command_InputKey("C-F4")() | |
def other_window(): | |
keymap.command_InputKey("D-Alt")() | |
keymap.command_InputKey("Tab")() | |
sleep(0.01) # delay | |
keymap.command_InputKey("U-Alt")() | |
######################################################################## | |
## 文字列検索 / 置換 | |
######################################################################## | |
def isearch(direction): | |
if keymap.getWindow().getClassName() == "keyhacWindowClass": # keyhac リストウィンドウを想定 | |
if keymap_emacs.is_searching_list_window: | |
keymap.command_InputKey({"backward":"Up", "forward":"Down"}[direction])() | |
else: | |
keymap.command_InputKey("f")() | |
keymap_emacs.is_searching_list_window = True | |
else: | |
if keymap_emacs.is_searching: | |
if keymap.getWindow().getProcessName() == "EXCEL.EXE": # Microsoft Excel | |
if keymap.getWindow().getClassName() == "EDTBX": # 検索ウィンドウ | |
keymap.command_InputKey({"backward":"A-S-f", "forward":"A-f"}[direction])() | |
else: | |
keymap.command_InputKey("C-f")() | |
else: | |
keymap.command_InputKey({"backward":"S-F3", "forward":"F3"}[direction])() | |
else: | |
keymap.command_InputKey("C-f")() | |
keymap_emacs.is_searching = True | |
def isearch_backward(): | |
isearch("backward") | |
def isearch_forward(): | |
isearch("forward") | |
######################################################################## | |
## キーボードマクロ | |
######################################################################## | |
def kmacro_start_macro(): | |
keymap.command_RecordStart() | |
def kmacro_end_macro(): | |
keymap.command_RecordStop() | |
# キーボードマクロの終了キー C-x ) の C-x がマクロに記録されてしまうのを削除する | |
# キーボードマクロの終了キーの前提を C-x ) としていることについては、とりえず了承ください | |
if len(keymap.record_seq) >= 4: | |
if (((keymap.record_seq[len(keymap.record_seq) - 1] == (162, True) and # U-LCtrl | |
keymap.record_seq[len(keymap.record_seq) - 2] == ( 88, True)) or # U-X | |
(keymap.record_seq[len(keymap.record_seq) - 1] == ( 88, True) and # U-X | |
keymap.record_seq[len(keymap.record_seq) - 2] == (162, True))) and # U-LCtrl | |
keymap.record_seq[len(keymap.record_seq) - 3] == (88, False)): # D-X | |
keymap.record_seq.pop() | |
keymap.record_seq.pop() | |
keymap.record_seq.pop() | |
if keymap.record_seq[len(keymap.record_seq) - 1] == (162, False): # D-LCtrl | |
for i in range(len(keymap.record_seq) - 1, -1, -1): | |
if keymap.record_seq[i] == (162, False): # D-LCtrl | |
keymap.record_seq.pop() | |
else: | |
break | |
else: | |
# コントロール系の入力が連続して行われる場合があるための対処 | |
keymap.record_seq.append((162, True)) # U-LCtrl | |
def kmacro_end_and_call_macro(): | |
keymap_emacs.is_playing_kmacro = True | |
keymap.command_RecordPlay() | |
keymap_emacs.is_playing_kmacro = False | |
######################################################################## | |
## その他 | |
######################################################################## | |
def newline(): | |
keymap.command_InputKey("Enter")() | |
def newline_and_indent(): | |
keymap.command_InputKey("Enter", "Tab")() | |
def indent_for_tab_command(): | |
keymap.command_InputKey("Tab")() | |
def keybord_quit(): | |
if not keymap.getWindow().getClassName().startswith("EXCEL"): # Microsoft Excel 以外 | |
# 選択されているリージョンのハイライトを解除するために Esc を発行しているが、 | |
# アプリケーションソフトによっては効果なし | |
keymap.command_InputKey("Esc")() | |
keymap.command_RecordStop() | |
def kill_emacs(): | |
keymap.command_InputKey("A-F4")() | |
def universal_argument(): | |
if keymap_emacs.is_universal_argument: | |
if keymap_emacs.is_digit_argument == True: | |
keymap_emacs.is_universal_argument = False | |
else: | |
keymap_emacs.repeat_counter *= 4 | |
else: | |
keymap_emacs.is_universal_argument = True | |
keymap_emacs.repeat_counter *= 4 | |
def digit_argument(number): | |
if keymap_emacs.is_digit_argument: | |
keymap_emacs.repeat_counter = keymap_emacs.repeat_counter * 10 + number | |
else: | |
keymap_emacs.repeat_counter = number | |
keymap_emacs.is_digit_argument = True | |
def clipboard_list(): | |
keymap.command_ClipboardList() | |
######################################################################## | |
## 共通関数 | |
######################################################################## | |
def self_insert_command(key): | |
return keymap.command_InputKey(key) | |
def digit(number): | |
def _func(): | |
if keymap_emacs.is_universal_argument: | |
digit_argument(number) | |
else: | |
reset_counter(reset_mark(repeat(keymap.command_InputKey(str(number)))))() | |
return _func | |
def digit2(number): | |
def _func(): | |
keymap_emacs.is_universal_argument = True | |
digit_argument(number) | |
return _func | |
def delay(func, sec=0.01): | |
def _func(): | |
sleep(sec) # delay | |
func() | |
sleep(sec) # delay | |
return _func | |
def mark(func): | |
def _func(): | |
if keymap_emacs.is_marked: | |
# D-Shift だと、M-< や M-> 押下時に、D-Shift が解除されてしまう。その対策。 | |
keymap.command_InputKey("D-LShift", "D-RShift")() | |
delay(func)() | |
keymap.command_InputKey("U-LShift", "U-RShift")() | |
else: | |
func() | |
return _func | |
def reset_mark(func): | |
def _func(): | |
func() | |
keymap_emacs.is_marked = False | |
return _func | |
def reset_counter(func): | |
def _func(): | |
func() | |
keymap_emacs.is_universal_argument = False | |
keymap_emacs.is_digit_argument = False | |
keymap_emacs.repeat_counter = 1 | |
return _func | |
def reset_search(func): | |
def _func(): | |
func() | |
keymap_emacs.is_searching = False | |
return _func | |
def reset_lw_search(func): | |
def _func(): | |
func() | |
keymap_emacs.is_searching_list_window = False | |
return _func | |
def repeat(func): | |
def _func(): | |
# 以下の2行は、キーボードマクロの繰り返し実行の際に必要な設定 | |
repeat_counter = keymap_emacs.repeat_counter | |
keymap_emacs.repeat_counter = 1 | |
for i in range(repeat_counter): | |
func() | |
return _func | |
def repeat2(func): | |
def _func(): | |
if keymap_emacs.is_marked: | |
keymap_emacs.repeat_counter = 1 | |
repeat(func)() | |
return _func | |
def repeat3(func): | |
def _func(): | |
func(keymap_emacs.repeat_counter) | |
return _func | |
######################################################################## | |
## キーバインド | |
######################################################################## | |
# http://homepage3.nifty.com/ic/help/rmfunc/vkey.htm | |
# http://www.azaelia.net/factory/vk.html | |
# http://www.yoshidastyle.net/2007/10/windowswin32api.html | |
## マルチストロークキーの設定 | |
keymap_emacs["Esc"] = keymap.defineMultiStrokeKeymap("Esc") | |
keymap_emacs["LC-OpenBracket"] = keymap.defineMultiStrokeKeymap("C-OpenBracket") | |
keymap_emacs["LC-x"] = keymap.defineMultiStrokeKeymap("C-x") | |
keymap_emacs["LC-q"] = keymap.defineMultiStrokeKeymap("C-q") | |
## [0-9]キーの設定 | |
for key in range(10): | |
keymap_emacs[ str(key)] = digit(key) | |
keymap_emacs["LC-" + str(key)] = digit2(key) | |
keymap_emacs["LA-" + str(key)] = digit2(key) | |
keymap_emacs["Esc"][ str(key)] = digit2(key) | |
keymap_emacs["LC-OpenBracket"][str(key)] = digit2(key) | |
keymap_emacs["S-" + str(key)] = reset_counter(reset_mark(repeat(self_insert_command("S-" + str(key))))) | |
## SPACE, [A-Z]キーの設定 | |
for vkey in [32] + list(range(65, 90 + 1)): | |
keymap_emacs[ "(" + str(vkey) + ")"] = reset_counter(reset_mark(repeat(self_insert_command( "(" + str(vkey) + ")")))) | |
keymap_emacs["S-(" + str(vkey) + ")"] = reset_counter(reset_mark(repeat(self_insert_command("S-(" + str(vkey) + ")")))) | |
## 10key の特殊文字キーの設定 | |
for vkey in [106, 107, 109, 110, 111]: | |
keymap_emacs[ "(" + str(vkey) + ")"] = reset_counter(reset_mark(repeat(self_insert_command( "(" + str(vkey) + ")")))) | |
## 特殊文字キーの設定 | |
for vkey in list(range(186, 192 + 1)) + list(range(219, 222 + 1)) + [226]: | |
keymap_emacs[ "(" + str(vkey) + ")"] = reset_counter(reset_mark(repeat(self_insert_command( "(" + str(vkey) + ")")))) | |
keymap_emacs["S-(" + str(vkey) + ")"] = reset_counter(reset_mark(repeat(self_insert_command("S-(" + str(vkey) + ")")))) | |
## quoted-insertキーの設定 | |
for vkey in range(1, 255): | |
keymap_emacs["LC-q"][ "(" + str(vkey) + ")"] = reset_search(reset_counter(reset_mark(self_insert_command( "(" + str(vkey) + ")")))) | |
keymap_emacs["LC-q"]["S-(" + str(vkey) + ")"] = reset_search(reset_counter(reset_mark(self_insert_command("S-(" + str(vkey) + ")")))) | |
keymap_emacs["LC-q"]["C-(" + str(vkey) + ")"] = reset_search(reset_counter(reset_mark(self_insert_command("C-(" + str(vkey) + ")")))) | |
keymap_emacs["LC-q"]["C-S-(" + str(vkey) + ")"] = reset_search(reset_counter(reset_mark(self_insert_command("C-S-(" + str(vkey) + ")")))) | |
keymap_emacs["LC-q"]["A-(" + str(vkey) + ")"] = reset_search(reset_counter(reset_mark(self_insert_command("A-(" + str(vkey) + ")")))) | |
keymap_emacs["LC-q"]["A-S-(" + str(vkey) + ")"] = reset_search(reset_counter(reset_mark(self_insert_command("A-S-(" + str(vkey) + ")")))) | |
## LC-S-[A-Z] -> C-[A-Z] の置き換え設定 | |
for vkey in range(65, 90 + 1): | |
keymap_emacs["LC-S-(" + str(vkey) + ")"] = reset_search(reset_counter(reset_mark(self_insert_command("C-(" + str(vkey) + ")")))) | |
## Esc の二回押しを Esc とする設定 | |
keymap_emacs["Esc"]["Esc"] = reset_lw_search(reset_counter(self_insert_command("Esc"))) | |
keymap_emacs["LC-OpenBracket"]["C-OpenBracket"] = keymap_emacs["Esc"]["Esc"] | |
## universal-argumentキーの設定 | |
keymap_emacs["LC-u"] = universal_argument | |
## 「IMEの切替え」のキー設定 | |
keymap_emacs["(243)"] = toggle_input_method | |
keymap_emacs["(244)"] = toggle_input_method | |
keymap_emacs["LA-(25)"] = toggle_input_method | |
keymap_emacs["LC-Yen"] = toggle_input_method | |
keymap_emacs["LC-o"] = toggle_input_method # or open_line | |
keymap_im["(243)"] = toggle_input_method | |
keymap_im["(244)"] = toggle_input_method | |
keymap_im["LA-(25)"] = toggle_input_method | |
keymap_im["LC-Yen"] = toggle_input_method | |
keymap_im["LC-o"] = toggle_input_method | |
## 「ファイル操作」のキー設定 | |
keymap_emacs["LC-x"]["C-f"] = reset_search(reset_counter(reset_mark(find_file))) | |
keymap_emacs["LC-x"]["C-s"] = reset_search(reset_counter(reset_mark(save_buffer))) | |
keymap_emacs["LC-x"]["C-w"] = reset_search(reset_counter(reset_mark(write_file))) | |
## 「カーソル移動」のキー設定 | |
keymap_emacs["LC-b"] = reset_search(reset_counter(mark(repeat(backward_char)))) | |
keymap_emacs["LC-f"] = reset_search(reset_counter(mark(repeat(forward_char)))) | |
keymap_emacs["LA-b"] = reset_search(reset_counter(mark(repeat(backward_word)))) | |
keymap_emacs["Esc"]["b"] = keymap_emacs["LA-b"] | |
keymap_emacs["LC-OpenBracket"]["b"] = keymap_emacs["LA-b"] | |
keymap_emacs["LA-f"] = reset_search(reset_counter(mark(repeat(forward_word)))) | |
keymap_emacs["Esc"]["f"] = keymap_emacs["LA-f"] | |
keymap_emacs["LC-OpenBracket"]["f"] = keymap_emacs["LA-f"] | |
keymap_emacs["LC-p"] = reset_search(reset_counter(mark(repeat(previous_line)))) | |
keymap_emacs["LC-n"] = reset_search(reset_counter(mark(repeat(next_line)))) | |
keymap_emacs["LC-a"] = reset_search(reset_counter(mark(move_beginning_of_line))) | |
keymap_emacs["LC-e"] = reset_search(reset_counter(mark(move_end_of_line))) | |
keymap_emacs["LA-S-Comma"] = reset_search(reset_counter(mark(beginning_of_buffer))) | |
keymap_emacs["Esc"]["S-Comma"] = keymap_emacs["LA-S-Comma"] | |
keymap_emacs["LC-OpenBracket"]["S-Comma"] = keymap_emacs["LA-S-Comma"] | |
keymap_emacs["LA-S-Period"] = reset_search(reset_counter(mark(end_of_buffer))) | |
keymap_emacs["Esc"]["S-Period"] = keymap_emacs["LA-S-Period"] | |
keymap_emacs["LC-OpenBracket"]["S-Period"] = keymap_emacs["LA-S-Period"] | |
keymap_emacs["LA-v"] = reset_search(reset_counter(mark(scroll_up))) | |
keymap_emacs["Esc"]["v"] = keymap_emacs["LA-v"] | |
keymap_emacs["LC-OpenBracket"]["v"] = keymap_emacs["LA-v"] | |
keymap_emacs["LC-v"] = reset_search(reset_counter(mark(scroll_down))) | |
keymap_emacs["LC-l"] = reset_search(reset_counter(recenter)) | |
## 「カット / コピー / 削除 / アンドゥ」のキー設定 | |
keymap_emacs["LC-h"] = reset_search(reset_counter(reset_mark(repeat2(delete_backward_char)))) | |
keymap_emacs["LC-d"] = reset_search(reset_counter(reset_mark(repeat2(delete_char)))) | |
keymap_emacs["LC-Back"] = reset_search(reset_counter(reset_mark(repeat3(backward_kill_word)))) | |
keymap_emacs["LA-Delete"] = reset_search(reset_counter(reset_mark(repeat3(backward_kill_word)))) | |
keymap_emacs["Esc"]["Delete"] = keymap_emacs["LA-Delete"] | |
keymap_emacs["LC-OpenBracket"]["Delete"] = keymap_emacs["LA-Delete"] | |
keymap_emacs["LC-Delete"] = reset_search(reset_counter(reset_mark(repeat3(kill_word)))) | |
keymap_emacs["LA-d"] = reset_search(reset_counter(reset_mark(repeat3(kill_word)))) | |
keymap_emacs["Esc"]["d"] = keymap_emacs["LA-d"] | |
keymap_emacs["LC-OpenBracket"]["d"] = keymap_emacs["LA-d"] | |
keymap_emacs["LC-k"] = reset_search(reset_counter(reset_mark(repeat3(kill_line)))) | |
keymap_emacs["LC-w"] = reset_search(reset_counter(reset_mark(kill_region))) | |
keymap_emacs["LA-w"] = reset_search(reset_counter(reset_mark(kill_ring_save))) | |
keymap_emacs["Esc"]["w"] = keymap_emacs["LA-w"] | |
keymap_emacs["LC-OpenBracket"]["w"] = keymap_emacs["LA-w"] | |
keymap_emacs["LC-c"] = reset_search(reset_counter(reset_mark(windows_copy))) | |
keymap_emacs["LC-y"] = reset_search(reset_counter(reset_mark(yank))) | |
keymap_emacs["LC-z"] = reset_search(reset_counter(reset_mark(undo))) | |
keymap_emacs["LC-Slash"] = reset_search(reset_counter(reset_mark(undo))) | |
keymap_emacs["LC-x"]["u"] = reset_search(reset_counter(reset_mark(undo))) | |
# LC-Underscore を機能させるための設定 | |
if is_japanese_keybord: | |
keymap_emacs["LC-S-BackSlash"] = reset_search(reset_counter(reset_mark(redo))) | |
else: | |
keymap_emacs["LC-S-Minus"] = reset_search(reset_counter(reset_mark(undo))) | |
# LC-Atmark は日本語キーボードの場合のみ有効とする(英語キーボードの場合、LC-S-2 としても有効とならない) | |
# LC-Atmark だとうまく動かない方が居るようなので LC-(192) としている(http://bhby39.blogspot.jp/2015/02/windows-emacs.html) | |
if is_japanese_keybord: | |
keymap_emacs["LC-(192)"] = reset_search(reset_counter(set_mark_command)) | |
keymap_emacs["LC-Space"] = reset_search(reset_counter(set_mark_command)) | |
keymap_emacs["LC-x"]["h"] = reset_search(reset_counter(reset_mark(mark_whole_buffer))) | |
keymap_emacs["LC-x"]["C-p"] = reset_search(reset_counter(reset_mark(mark_page))) | |
## 「バッファ / ウインドウ操作」のキー設定 | |
keymap_emacs["LC-x"]["k"] = reset_search(reset_counter(reset_mark(kill_buffer))) | |
keymap_emacs["LC-x"]["o"] = reset_search(reset_counter(reset_mark(other_window))) | |
## 「文字列検索 / 置換」のキー設定 | |
keymap_emacs["LC-r"] = reset_counter(reset_mark(isearch_backward)) | |
keymap_emacs["LC-s"] = reset_counter(reset_mark(isearch_forward)) | |
## 「キーボードマクロ」のキー設定 | |
if is_japanese_keybord: | |
keymap_emacs["LC-x"]["S-8"] = kmacro_start_macro | |
keymap_emacs["LC-x"]["S-9"] = kmacro_end_macro | |
else: | |
keymap_emacs["LC-x"]["S-9"] = kmacro_start_macro | |
keymap_emacs["LC-x"]["S-0"] = kmacro_end_macro | |
keymap_emacs["LC-x"]["e"] = reset_search(reset_counter(repeat(kmacro_end_and_call_macro))) | |
## 「その他」のキー設定 | |
keymap_emacs["Enter"] = reset_lw_search(reset_counter(reset_mark(repeat(newline)))) | |
keymap_emacs["LC-m"] = keymap_emacs["Enter"] | |
keymap_emacs["LC-j"] = reset_lw_search(reset_counter(reset_mark(newline_and_indent))) | |
keymap_emacs["Tab"] = reset_counter(reset_mark(repeat(indent_for_tab_command))) | |
keymap_emacs["LC-i"] = keymap_emacs["Tab"] | |
keymap_emacs["LC-g"] = reset_lw_search(reset_search(reset_counter(reset_mark(keybord_quit)))) | |
keymap_emacs["LC-x"]["C-c"] = reset_search(reset_counter(reset_mark(kill_emacs))) | |
keymap_emacs["LC-x"]["C-y"] = reset_lw_search(reset_search(reset_counter(reset_mark(clipboard_list)))) | |
keymap_emacs["LA-y"] = reset_lw_search(reset_search(reset_counter(reset_mark(clipboard_list)))) | |
keymap_emacs["Esc"]["y"] = keymap_emacs["LA-y"] | |
keymap_emacs["LC-OpenBracket"]["y"] = keymap_emacs["LA-y"] | |
# 以下はオプションです。Excel を使う方は便利な設定かと思います。上記のスクリプト本体に追加して利用してください。 | |
## Excel の場合、^Enter に F2(セル編集モード移行)を割り当てる(オプション) | |
if 1: | |
keymap_excel = keymap.defineWindowKeymap(class_name='EXCEL*') | |
# C-Enter 押下で、「セル編集モード」に移行する | |
keymap_excel["LC-Enter"] = reset_search(reset_counter(reset_mark(self_insert_command("F2")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment