-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmacsEverywhere.ahk
128 lines (91 loc) · 2.96 KB
/
EmacsEverywhere.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: David <tchepak@gmail.com>
;
; Script Function:
; Provides an Emacs-like keybinding emulation mode that can be toggled on and off using
; the CapsLock key.
;
;==========================
;Initialise
;==========================
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
enabledIcon := "emacs_everywhere_16.ico"
disabledIcon := "emacs_everywhere_disabled_16.ico"
IsInEmacsMode := false
SetEmacsMode(false)
;==========================
;Functions
;==========================
SetEmacsMode(toActive) {
local iconFile := toActive ? enabledIcon : disabledIcon
local state := toActive ? "ON" : "OFF"
IsInEmacsMode := toActive
TrayTip, Emacs Everywhere, Emacs mode is %state%, 10, 1
Menu, Tray, Icon, %iconFile%,
Menu, Tray, Tip, Emacs Everywhere`nEmacs mode is %state%
Send {Shift Up}
}
SendCommand(emacsKey, translationToWindowsKeystrokes, secondWindowsKeystroke="") {
global IsInEmacsMode
if (IsInEmacsMode) {
Send, %translationToWindowsKeystrokes%
if (secondWindowsKeystroke<>"") {
Send, %secondWindowsKeystroke%
}
} else {
Send, %emacsKey% ;passthrough original keystroke
}
return
}
;==========================
;Emacs mode toggle
;==========================
CapsLock::
SetEmacsMode(!IsInEmacsMode)
return
;==========================
;Character navigation
;==========================
$^p::SendCommand("^p","{Up}")
$^n::SendCommand("^n","{Down}")
$^f::SendCommand("^f","{Right}")
$^b::SendCommand("^b","{Left}")
;==========================
;Word Navigation
;==========================
$!p::SendCommand("!p","^{Up}")
$!n::SendCommand("!n","^{Down}")
$!f::SendCommand("!f","^{Right}")
$!b::SendCommand("!b","^{Left}")
;==========================
;Line Navigation
;==========================
$^a::SendCommand("^a","{Home}")
$^e::SendCommand("^e","{End}")
;==========================
;Page Navigation
;==========================
;Ctrl-V disabled. Too reliant on that for pasting :$
;$^v::SendCommand("^v","{PgDn}")
;$!v::SendCommand("!v","{PgUp}")
$!<::SendCommand("!<","^{Home}")
$!>::SendCommand("!>","^{End}")
;==========================
;Undo
;==========================
$^_::SendCommand("^_","^z")
;==========================
;Killing and Deleting
;==========================
$^d::SendCommand("^d","{Delete}")
$!d::SendCommand("!d","^+{Right}","{Delete}")
$!Delete::SendCommand("!{Del}","^+{Left}","{Del}")
$^k::SendCommand("^k","+{End}","{Delete}")
$^w::SendCommand("^w","+{Delete}","{Shift Up}") ;cut region
$!w::SendCommand("!w","^{Insert}","{Shift Up}") ;copy region
$^y::SendCommand("^y","+{Insert}") ;paste