2 ; AutoHotkey Version: 1.x
\r
5 ; Author: David <tchepak@gmail.com>
\r
6 ; Modified: Andrew DeFaria <Andrew@ClearSCM.com>
\r
9 ; Provides an Emacs-like keybinding emulation mode that can be toggled on and off using
\r
10 ; the ScrollLoke key.
\r
12 ;==========================
\r
14 ;==========================
\r
15 #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
\r
16 SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
\r
17 SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
\r
18 SetTitleMatchMode, RegEx
\r
20 enabledIcon := "emacs_everywhere_16.ico"
\r
21 disabledIcon := "emacs_everywhere_disabled_16.ico"
\r
22 IsInEmacsMode := false
\r
25 ;==========================
\r
27 ;==========================
\r
28 SetEmacsMode(toActive) {
\r
29 local iconFile := toActive ? enabledIcon : disabledIcon
\r
30 local state := toActive ? "ON" : "OFF"
\r
32 IsInEmacsMode := toActive
\r
33 TrayTip, Emacs Everywhere, Emacs mode is %state%, 10, 1
\r
34 Menu, Tray, Icon, %iconFile%,
\r
35 Menu, Tray, Tip, Emacs Everywhere`nEmacs mode is %state%
\r
40 SendCommand(emacsKey, translationToWindowsKeystrokes, secondWindowsKeystroke="") {
\r
41 global IsInEmacsMode
\r
42 if (IsInEmacsMode) {
\r
43 Send, %translationToWindowsKeystrokes%
\r
44 if (secondWindowsKeystroke<>"") {
\r
45 Send, %secondWindowsKeystroke%
\r
48 Send, %emacsKey% ;passthrough original keystroke
\r
53 ;==========================
\r
55 ;==========================
\r
57 SetEmacsMode(!IsInEmacsMode)
\r
60 ;==========================
\r
61 ;Character navigation
\r
62 ;==========================
\r
64 #IfWinActive ahk_class Chrome_WidgetWin_1
\r
65 $^f::SendCommand("^f","{Right}")
\r
66 $^s::SendCommand("^s","^g")
\r
69 $^p::SendCommand("^p","{Up}")
\r
70 $^n::SendCommand("^n","{Down}")
\r
71 $^b::SendCommand("^b","{Left}")
\r
72 $^f::SendCommand("^f","{Right}")
\r
74 ;==========================
\r
76 ;==========================
\r
78 $!p::SendCommand("!p","^{Up}")
\r
79 $!n::SendCommand("!n","^{Down}")
\r
80 $!f::SendCommand("!f","^{Right}")
\r
82 $!b::SendCommand("!b","^{Left}")
\r
84 ;==========================
\r
86 ;==========================
\r
87 $^a::SendCommand("^a","{Home}")
\r
88 $^e::SendCommand("^e","{End}")
\r
90 ;==========================
\r
92 ;==========================
\r
94 ;Ctrl-V disabled. Too reliant on that for pasting :$
\r
95 $^v::SendCommand("^v","{PgDn}")
\r
96 $!v::SendCommand("!v","{PgUp}")
\r
97 $!<::SendCommand("!<","^{Home}")
\r
98 $!>::SendCommand("!>","^{End}")
\r
100 ;==========================
\r
102 ;==========================
\r
104 ;==========================
\r
109 #IfWinNotActive ahk_class SWT_Window0
\r
110 $^/::SendCommand("^_","^z")
\r
113 ;==========================
\r
114 ;Killing and Deleting
\r
115 ;==========================
\r
116 #IfWinNotActive ahk_class mintty
\r
117 $^d::SendCommand("^d","{Delete}")
\r
119 $!d::SendCommand("!d","^+{Right}","{Delete}")
\r
120 $^h::SendCommand("^h","{Backspace}")
\r
122 $!Delete::SendCommand("!{Del}","^+{Left}","{Del}")
\r
124 #IfWinNotActive ahk_class (mintty|SWT_Window0)
\r
125 $^k::SendCommand("^k","+{End}","+{Delete}") ;cut region
\r
128 $^w::SendCommand("^w","+{Delete}","{Shift Up}") ;cut region
\r
130 $!w::SendCommand("!w","^{Insert}","{Shift Up}") ;copy region
\r
132 $^y::SendCommand("^y","+{Insert}") ;paste