-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpp-newlisp.ahk
249 lines (226 loc) · 6.18 KB
/
npp-newlisp.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
;=====================================
; npp-newlisp.ahk
; Connect newLisp and editor (notepad++)
; AutoHotkey: 1.x
; Language: English
; Platform: Windows 7/10
; Author: cameyo - 2018
; License: MIT license
;=====================================
; Hotkeys:
; Win-F12 -> Start newLisp
; Left_Shift-Enter -> Evaluate current line
; Right_Shift-Enter -> Evaluate selected block
; Paste in REPL with Ctrl+v
; Insert Greek chars
; Swap [] with ()
; Control-Alt-q -> Insert text ";-> "
;=====================================
; How to set your editor:
; 1: run winspy utility (bundled with autohotkey)
; 2: run your editor
; 3: copy the ahk_class text value
; 4: set the global variable editor to "<ahk_class>"
; 5: That's all.
; EXAMPLES:
; (notepad++):
;global editor = "notepad++"
; (SciTE):
;global editor = "SciTEWindow"
; (Notepad)
;global editor = "Notepad";
; (PSPad)
;global editor = "TfPSPad.UnicodeClass"
; (Programmer's Notepad)
;global editor = "ATL:006AD5B8"
; (Sublime Text)
;global editor = "PX_WINDOW_CLASS"
;-------------------------------------
global editor = "notepad++"
;-------------------------------------
; To use (and view) the greek letters the editor must be set to UTF-8 encoding.
;=====================================
;=====================================
; Basic hotkeys symbol
;=====================================
; # Win key
; ! Alt key
; ^ Control key
; + Shift key
;=====================================
; General statements
;=====================================
#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.
#SingleInstance force ; Allow reload script
#WinActivateForce ; activate window with forceful method
;=====================================
; Global variables
;=====================================
#EscapeChar \
global hasRunnewLisp = 0
global newLispPID = 0
global editorPID = 0
;---------------------------
OpennewLisp()
{
if %hasRunnewLisp% = 0
{
Run newlisp.exe,,,newLispPID
hasRunnewLisp = 1
ReturnToEditor()
return
}
Process, Exist, %newLispPID%
if %ErrorLevel% = 0
{
Run newlisp.exe,,,newLispPID
hasRunnewLisp = 1
ReturnToEditor()
return
}
}
;---------------------------
ReOpennewLisp()
{
WinClose, ahk_pid %newLispPID%
OpennewLisp()
}
;---------------------------
SendTonewLisp()
{
OpennewLisp()
WinWait, ahk_pid %newLispPID%
WinActivate, ahk_pid %newLispPID%
WinWaitActive, ahk_pid %newLispPID%
;Paste via menu (must disable SendMode Input)
;Send {Alt Down}{Space}{Alt up}ep{Enter}
;Paste with send clipboard
StringReplace clipboard2, clipboard, \r\n, \n, All
SendInput {Raw}%clipboard2%\n
}
;---------------------------
ReturnToEditor()
{
WinActivate, ahk_pid %editorPID%
SendInput {End}
}
;---------------------------
PassLine()
{
WinGetCLASS, currentClass, A
If currentClass = %editor%
{
WinGet, editorPID, PID, A
SendInput {Home}{Shift Down}{End}{Shift Up}{Ctrl Down}c{Ctrl Up}{End}
SendTonewLisp()
ReturnToEditor()
}
}
;---------------------------
PassBlock()
{
WinGetCLASS, currentClass, A
If currentClass = %editor%
{
WinGet, editorPID, PID, A
SendInput {Ctrl Down}c{Ctrl Up}
SendTonewLisp()
ReturnToEditor()
}
}
;-------------------------------------------
; Eval current line (Left Shift - Enter)
LShift & Enter:: PassLine()
;-------------------------------------------
;-------------------------------------------
; Eval selected block (Right Shift - Enter)
RShift & Enter:: PassBlock()
;-------------------------------------------
;-------------------------------------------
; Run newLisp (Win-F12)
#$F12:: ReOpennewLisp()
;-------------------------------------------
;================================================
; REPL enhancements
; Work only on console window
#IfWinActive ahk_class ConsoleWindowClass
;=============================
; Scroll command window back and forward
; Ctrl+PageUp / PageDown
;=============================
^PgUp:: SendInput {WheelUp}
^PgDn:: SendInput {WheelDown}
;=============================
; Paste in REPL
; Ctrl-V
; Better version
;=============================
^V::
StringReplace clipboard2, clipboard, \r\n, \n, All
SendInput {Raw}%clipboard2%
return
;=============================
; Paste in REPL
; Ctrl-V
; Old version (must disable SendMode Input)
;=============================
;^V::
; English menu (Edit->Paste)
;Send !{Space}ep
;return
#IfWinActive
;================================================
;=============================
; Greek Letters (lowercase)
; Control-Win-<char>
; char 'j' can't be used (REPL)
; char 'q' is free...
; To use (and view) the greek letters the editor must be set to UTF-8 encoding.
; Note: a lot of these greek letters are protected in newLISP 10.7.1
;=============================
^#a:: SendInput {U+03B1} ; alpha
^#b:: SendInput {U+03B2} ; beta
^#g:: SendInput {U+03B3} ; gamma
^#d:: SendInput {U+03B4} ; delta
^#y:: SendInput {U+03B5} ; epsilon (y)
^#z:: SendInput {U+03B6} ; zeta
^#e:: SendInput {U+03B7} ; eta
^#h:: SendInput {U+03B8} ; theta (h)
^#i:: SendInput {U+03B9} ; iota
^#k:: SendInput {U+03BA} ; kappa
^#l:: SendInput {U+03BB} ; lambda
^#m:: SendInput {U+03BC} ; mu
^#n:: SendInput {U+03BD} ; nu
^#x:: SendInput {U+03BE} ; xi
^#o:: SendInput {U+03BF} ; omicron
^#p:: SendInput {U+03C0} ; pi
^#r:: SendInput {U+03C1} ; rho
^#s:: SendInput {U+03C3} ; sigma
^#t:: SendInput {U+03C4} ; tau
^#u:: SendInput {U+03C5} ; upsilon
^#f:: SendInput {U+03C6} ; phi (f)
^#c:: SendInput {U+03C7} ; chi
^#v:: SendInput {U+03C8} ; psi (v)
^#w:: SendInput {U+03C9} ; omega (w)
;-------------------------------------------
; Swap [] with ()
;-------------------------------------------
[::Send {( Down}
[ Up::Send {( Up}
]::Send {) Down}
] Up::Send {) Up}
+9::Send {[ Down}
+9 Up::Send {[ Up}
+0::Send {] Down}
+0 Up::Send {] Up}
;-------------------------------------------
; Control-Alt-q -> Insert text ";-> "
;-------------------------------------------
^!q:: Send {;}->{Space}
;-------------------------------------------
; Swap " with '
;-------------------------------------------
;$'::Send "
;+$'::Send '