Last active
November 16, 2021 09:37
-
-
Save ser1zw/1209817 to your computer and use it in GitHub Desktop.
AutoHotKey Emacs keybind script
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
;; AutoHotKey_LでEmacsキーバインドにするスクリプト | |
;; | |
;; 使い方 | |
;; ・AutoHotKey_L(http://l.autohotkey.net/)をインストール | |
;; ・Emacs.ahkをAutoHotkeyをインストールしたフォルダ(デフォルトならC:\Program Files\AutoHotkey)に保存 | |
;; ・タスクバーにあるAutoHotkeyのアイコン([H])を右クリックし、"Edit This Script"を選択 | |
;; ・メモ帳でAutoHotkey.ahkが開くので、最後に以下の行を追加 | |
;; #include Emacs.ahk | |
;; ・AutoHotkeyアイコンを右クリックして"Reload This Script"を選択してリロード | |
;; | |
;; WindowsでEmacs風キーバインド - Usipedia | |
;; http://usi3.com/index.php?title=Windows%E3%81%A7Emacs%E9%A2%A8%E3%82%AD%E3%83%BC%E3%83%90%E3%82%A4%E3%83%B3%E3%83%89 | |
;; | |
;; AutoHotkeyでemacs風キーバインド - torutkの日記 | |
;; http://d.hatena.ne.jp/torutk/20101009/p2 | |
;; | |
;; AutoHotkeyJp | |
;; https://sites.google.com/site/autohotkeyjp/ | |
;; | |
#InstallKeybdHook | |
#UseHook | |
; C-x が押されると1になる | |
is_x_pressed = 0 | |
; C-Space が押されると1になる | |
is_space_pressed = 0 | |
;; Emacsキーバインドを有効にするウィンドウ | |
is_target() | |
{ | |
SetTitleMatchMode, 2 ; 中間一致 | |
IfWinActive, - Microsoft Visual | |
Return 1 | |
Return 0 | |
} | |
delete_char() | |
{ | |
Send {Del} | |
global is_space_pressed = 0 | |
Return | |
} | |
delete_backward_char() | |
{ | |
Send {BS} | |
global is_space_pressed = 0 | |
Return | |
} | |
kill_line() | |
{ | |
Send {ShiftDown}{END}{SHIFTUP} | |
Sleep 10 ;[ms] | |
Send ^x | |
global is_space_pressed = 0 | |
Return | |
} | |
open_line() | |
{ | |
Send {END}{Enter}{Up} | |
global is_space_pressed = 0 | |
Return | |
} | |
quit() | |
{ | |
Send {ESC} | |
global is_space_pressed = 0 | |
Return | |
} | |
newline() | |
{ | |
Send {Enter} | |
global is_space_pressed = 0 | |
Return | |
} | |
indent_for_tab_command() | |
{ | |
Send {Tab} | |
global is_space_pressed = 0 | |
Return | |
} | |
newline_and_indent() | |
{ | |
Send {Enter}{Tab} | |
global is_space_pressed = 0 | |
Return | |
} | |
isearch_forward() | |
{ | |
Send ^f | |
global is_space_pressed = 0 | |
Return | |
} | |
isearch_backward() | |
{ | |
Send ^f | |
global is_space_pressed = 0 | |
Return | |
} | |
kill_region() | |
{ | |
Send ^x | |
global is_space_pressed = 0 | |
Return | |
} | |
kill_ring_save() | |
{ | |
Send ^c | |
global is_space_pressed = 0 | |
Return | |
} | |
yank() | |
{ | |
Send ^v | |
global is_space_pressed = 0 | |
Return | |
} | |
undo() | |
{ | |
Send ^z | |
global is_space_pressed = 0 | |
Return | |
} | |
find_file() | |
{ | |
Send ^o | |
global is_x_pressed = 0 | |
Return | |
} | |
save_buffer() | |
{ | |
Send, ^s | |
global is_x_pressed = 0 | |
Return | |
} | |
kill_emacs() | |
{ | |
Send !{F4} | |
global is_x_pressed = 0 | |
Return | |
} | |
beginning_of_line() | |
{ | |
global | |
if is_space_pressed | |
Send +{HOME} | |
Else | |
Send {HOME} | |
Return | |
} | |
end_of_line() | |
{ | |
global | |
if is_space_pressed | |
Send +{END} | |
Else | |
Send {END} | |
Return | |
} | |
previous_line() | |
{ | |
global | |
if is_space_pressed | |
Send +{Up} | |
Else | |
Send {Up} | |
Return | |
} | |
next_line() | |
{ | |
global | |
if is_space_pressed | |
Send +{Down} | |
Else | |
Send {Down} | |
Return | |
} | |
forward_char() | |
{ | |
global | |
if is_space_pressed | |
Send +{Right} | |
Else | |
Send {Right} | |
Return | |
} | |
backward_char() | |
{ | |
global | |
if is_space_pressed | |
Send +{Left} | |
Else | |
Send {Left} | |
Return | |
} | |
scroll_up() | |
{ | |
global | |
if is_space_pressed | |
Send +{PgUp} | |
Else | |
Send {PgUp} | |
Return | |
} | |
scroll_down() | |
{ | |
global | |
if is_space_pressed | |
Send +{PgDn} | |
Else | |
Send {PgDn} | |
Return | |
} | |
mark_whole_buffer() | |
{ | |
Send ^a | |
Return | |
} | |
beginning_of_buffer() | |
{ | |
Send ^{HOME} | |
Return | |
} | |
end_of_buffer() | |
{ | |
Send ^{END} | |
Return | |
} | |
forward_word() | |
{ | |
Send ^{Right} | |
Return | |
} | |
backward_word() | |
{ | |
Send ^{Left} | |
Return | |
} | |
toggle_input_method() | |
{ | |
Send {vkF3sc029} | |
} | |
^x:: | |
If is_target() | |
is_x_pressed = 1 | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^f:: | |
If is_target() { | |
If is_x_pressed | |
find_file() | |
Else | |
forward_char() | |
} | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^c:: | |
If is_target() && is_x_pressed { | |
kill_emacs() | |
} | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^d:: | |
If is_target() | |
delete_char() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^h:: | |
If is_target() | |
delete_backward_char() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^k:: | |
If is_target() | |
kill_line() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^o:: | |
If is_target() | |
toggle_input_method() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^g:: | |
If is_target() | |
quit() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^j:: | |
If is_target() | |
newline_and_indent() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^m:: | |
If is_target() | |
newline() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^i:: | |
If is_target() | |
indent_for_tab_command() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^s:: | |
If is_target() { | |
If is_x_pressed | |
save_buffer() | |
Else | |
isearch_forward() | |
} | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^r:: | |
If is_target() | |
isearch_backward() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^w:: | |
If is_target() | |
kill_region() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
!w:: | |
If is_target() | |
kill_ring_save() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^y:: | |
If is_target() | |
yank() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^/:: | |
If is_target() | |
undo() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^vk20sc039:: | |
If is_target() { | |
If is_space_pressed | |
is_space_pressed = 0 | |
Else | |
is_space_pressed = 1 | |
} | |
Else | |
Send {CtrlDown}{Space}{CtrlUp} | |
Return | |
^@:: | |
If is_target() { | |
If is_space_pressed | |
is_space_pressed = 0 | |
Else | |
is_space_pressed = 1 | |
} | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^a:: | |
If is_target() | |
beginning_of_line() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^e:: | |
If is_target() | |
end_of_line() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^p:: | |
If is_target() | |
previous_line() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^n:: | |
If is_target() | |
next_line() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^b:: | |
If is_target() | |
backward_char() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
^v:: | |
If is_target() | |
scroll_down() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
!v:: | |
If is_target() | |
scroll_up() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
#k:: | |
MsgBox, 4,, スクリプトを終了しますか?, | |
IfMsgBox, Yes | |
ExitApp | |
Return | |
^_:: | |
If is_target() | |
undo() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
h:: | |
If is_target() && is_x_pressed { | |
mark_whole_buffer() | |
is_x_pressed = 0 | |
} | |
Else | |
Send %A_ThisHotkey% | |
Return | |
!<:: | |
If is_target() | |
beginning_of_buffer() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
!>:: | |
If is_target() | |
end_of_buffer() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
!f:: | |
If is_target() | |
forward_word() | |
Else | |
Send %A_ThisHotkey% | |
Return | |
!b:: | |
If is_target() | |
backward_word() | |
Else | |
Send %A_ThisHotkey% | |
Return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment