diff --git a/emacs.ahk b/emacs.ahk index e56fe4d8..d82d9c0b 100644 --- a/emacs.ahk +++ b/emacs.ahk @@ -1,149 +1,149 @@ ;; ;; An autohotkey script that provides emacs-like keybinding on Windows ;; -#InstallKeybdHook +InstallKeybdHook #UseHook ; The following line is a contribution of NTEmacs wiki http://www49.atwiki.jp/ntemacs/pages/20.html SetKeyDelay 0 ; turns to be 1 when ctrl-x is pressed -is_pre_x = 0 +is_pre_x := 0 ; turns to be 1 when ctrl-space is pressed -is_pre_spc = 0 +is_pre_spc := 0 ; Applications you want to disable emacs-like keybindings ; (Please comment out applications you don't use) is_target() { - IfWinActive,ahk_class ConsoleWindowClass ; Cygwin + If WinActive("ahk_class ConsoleWindowClass") ; Cygwin Return 1 - IfWinActive,ahk_class MEADOW ; Meadow + if WinActive("ahk_class MEADOW") ; Meadow Return 1 - IfWinActive,ahk_class cygwin/x X rl-xterm-XTerm-0 + if WinActive("ahk_class cygwin/x X rl-xterm-XTerm-0") Return 1 - IfWinActive,ahk_class MozillaUIWindowClass ; keysnail on Firefox + if WinActive("ahk_class MozillaUIWindowClass") ; keysnail on Firefox Return 1 ; Avoid VMwareUnity with AutoHotkey - IfWinActive,ahk_class VMwareUnityHostWndClass + if WinActive("ahk_class VMwareUnityHostWndClass") Return 1 - IfWinActive,ahk_class Vim ; GVIM - Return 1 -; IfWinActive,ahk_class SWT_Window0 ; Eclipse +; if WinActive("ahk_class Vim") ; GVIM +; Return 1 +; if WinActive("ahk_class SWT_Window0") ; Eclipse ; Return 1 -; IfWinActive,ahk_class Xming X +; if WinActive("ahk_class Xming X") ; Return 1 -; IfWinActive,ahk_class SunAwtFrame +; if WinActive("ahk_class SunAwtFrame") ; Return 1 -; IfWinActive,ahk_class Emacs ; NTEmacs +; if WinActive("ahk_class Emacs") ; NTEmacs ; Return 1 -; IfWinActive,ahk_class XEmacs ; XEmacs on Cygwin +; if WinActive("ahk_class XEmacs") ; XEmacs on Cygwin ; Return 1 Return 0 } delete_char() { - Send {Del} - global is_pre_spc = 0 + Send "{Del}" + global is_pre_spc := 0 Return } delete_backward_char() { - Send {BS} - global is_pre_spc = 0 + Send "{BS}" + global is_pre_spc := 0 Return } kill_line() { - Send {ShiftDown}{END}{SHIFTUP} + Send "{ShiftDown}{END}{SHIFTUP}" Sleep 50 ;[ms] this value depends on your environment - Send ^x - global is_pre_spc = 0 + Send "^x" + global is_pre_spc := 0 Return } open_line() { - Send {END}{Enter}{Up} - global is_pre_spc = 0 + Send "{END}{Enter}{Up}" + global is_pre_spc := 0 Return } quit() { - Send {ESC} - global is_pre_spc = 0 + Send "{ESC}" + global is_pre_spc := 0 Return } newline() { - Send {Enter} - global is_pre_spc = 0 + Send "{Enter}" + global is_pre_spc := 0 Return } indent_for_tab_command() { - Send {Tab} - global is_pre_spc = 0 + Send "{Tab}" + global is_pre_spc := 0 Return } newline_and_indent() { - Send {Enter}{Tab} - global is_pre_spc = 0 + Send "{Enter}{Tab}" + global is_pre_spc := 0 Return } isearch_forward() { - Send ^f - global is_pre_spc = 0 + Send "^f" + global is_pre_spc := 0 Return } isearch_backward() { - Send ^f - global is_pre_spc = 0 + Send "^f" + global is_pre_spc := 0 Return } kill_region() { - Send ^x - global is_pre_spc = 0 + Send "^x" + global is_pre_spc := 0 Return } kill_ring_save() { - Send ^c - global is_pre_spc = 0 + Send "^c" + global is_pre_spc := 0 Return } yank() { - Send ^v - global is_pre_spc = 0 + Send "^v" + global is_pre_spc := 0 Return } undo() { - Send ^z - global is_pre_spc = 0 + Send "^z" + global is_pre_spc := 0 Return } find_file() { - Send ^o - global is_pre_x = 0 + Send "^o" + global is_pre_x := 0 Return } save_buffer() { - Send, ^s - global is_pre_x = 0 + Send "^s" + global is_pre_x := 0 Return } kill_emacs() { - Send !{F4} - global is_pre_x = 0 + Send "!{F4}" + global is_pre_x := 0 Return } @@ -151,256 +151,307 @@ move_beginning_of_line() { global if is_pre_spc - Send +{HOME} + Send "+{HOME}" Else - Send {HOME} + Send "{HOME}" Return } move_end_of_line() { global if is_pre_spc - Send +{END} + Send "+{END}" Else - Send {END} + Send "{END}" Return } previous_line() { global if is_pre_spc - Send +{Up} + Send "+{Up}" Else - Send {Up} + Send "{Up}" Return } next_line() { global if is_pre_spc - Send +{Down} + Send "+{Down}" Else - Send {Down} + Send "{Down}" Return } forward_char() { global if is_pre_spc - Send +{Right} + Send "+{Right}" Else - Send {Right} + Send "{Right}" Return } backward_char() { global if is_pre_spc - Send +{Left} + Send "+{Left} " Else - Send {Left} + Send "{Left}" Return } scroll_up() { global if is_pre_spc - Send +{PgUp} + Send "+{PgUp}" Else - Send {PgUp} + Send "{PgUp}" Return } scroll_down() { global if is_pre_spc - Send +{PgDn} + Send "+{PgDn}" Else - Send {PgDn} + Send "{PgDn}" Return } ^x:: - If is_target() - Send %A_ThisHotkey% - Else - is_pre_x = 1 - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + is_pre_x := 1 + Return +} ^f:: - If is_target() - Send %A_ThisHotkey% - Else - { - If is_pre_x - find_file() - Else - forward_char() - } - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + { + If is_pre_x + find_file() + Else + forward_char() + } + Return +} ^c:: - If is_target() - Send %A_ThisHotkey% - Else - { - If is_pre_x - kill_emacs() - } - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + { + If is_pre_x + kill_emacs() + } + Return +} ^d:: - If is_target() - Send %A_ThisHotkey% - Else - delete_char() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + delete_char() + Return +} ^h:: - If is_target() - Send %A_ThisHotkey% - Else - delete_backward_char() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + delete_backward_char() + Return +} ^k:: - If is_target() - Send %A_ThisHotkey% - Else - kill_line() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + kill_line() + Return +} ;; ^o:: -;; If is_target() -;; Send %A_ThisHotkey% -;; Else -;; open_line() -;; Return +{ + ;; If is_target() + ;; Send "%A_ThisHotkey%" + ;; Else + ;; open_line() + ;; Return +} ^g:: - If is_target() - Send %A_ThisHotkey% - Else - quit() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + quit() + Return +} ;; ^j:: -;; If is_target() -;; Send %A_ThisHotkey% -;; Else -;; newline_and_indent() -;; Return +{ + ;; If is_target() + ;; Send "%A_ThisHotkey%" + ;; Else + ;; newline_and_indent() + ;; Return +} ^m:: - If is_target() - Send %A_ThisHotkey% - Else - newline() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + newline() + Return +} ^i:: - If is_target() - Send %A_ThisHotkey% - Else - indent_for_tab_command() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + indent_for_tab_command() + Return +} ^s:: - If is_target() - Send %A_ThisHotkey% - Else - { - If is_pre_x - save_buffer() - Else - isearch_forward() - } - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + { + If is_pre_x + save_buffer() + Else + isearch_forward() + } + Return +} ^r:: - If is_target() - Send %A_ThisHotkey% - Else - isearch_backward() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + isearch_backward() + Return +} ^w:: - If is_target() - Send %A_ThisHotkey% - Else - kill_region() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + kill_region() + Return +} !w:: - If is_target() - Send %A_ThisHotkey% - Else - kill_ring_save() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + kill_ring_save() + Return +} ^y:: - If is_target() - Send %A_ThisHotkey% - Else - yank() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + yank() + Return +} ^/:: - If is_target() - Send %A_ThisHotkey% - Else - undo() - Return - +{ + If is_target() + Send "%A_ThisHotkey%" + Else + undo() + Return +} ;$^{Space}:: ;^vk20sc039:: ^vk20:: - If is_target() - Send {CtrlDown}{Space}{CtrlUp} - Else - { - If is_pre_spc - is_pre_spc = 0 - Else - is_pre_spc = 1 - } - Return +{ + If is_target() + Send "{CtrlDown}{Space}{CtrlUp}" + Else + { + If is_pre_spc + global is_pre_spc := 0 + Else + global is_pre_spc := 1 + } + Return +} ^@:: - If is_target() - Send %A_ThisHotkey% - Else - { - If is_pre_spc - is_pre_spc = 0 - Else - is_pre_spc = 1 - } - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + { + If is_pre_spc + global is_pre_spc := 0 + Else + global is_pre_spc := 1 + } + Return +} ^a:: - If is_target() - Send %A_ThisHotkey% - Else - move_beginning_of_line() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + move_beginning_of_line() + Return +} ^e:: - If is_target() - Send %A_ThisHotkey% - Else - move_end_of_line() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + move_end_of_line() + Return +} ^p:: - If is_target() - Send %A_ThisHotkey% - Else - previous_line() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + previous_line() + Return +} ^n:: - If is_target() - Send %A_ThisHotkey% - Else - next_line() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + next_line() + Return +} ^b:: - If is_target() - Send %A_ThisHotkey% - Else - backward_char() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + backward_char() + Return +} ^v:: - If is_target() - Send %A_ThisHotkey% - Else - scroll_down() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + scroll_down() + Return +} !v:: - If is_target() - Send %A_ThisHotkey% - Else - scroll_up() - Return +{ + If is_target() + Send "%A_ThisHotkey%" + Else + scroll_up() + Return +}