-
Notifications
You must be signed in to change notification settings - Fork 121
/
IntelliSense2.ahk
197 lines (166 loc) · 5.77 KB
/
IntelliSense2.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
#include FcnLib.ahk
#NoTrayIcon
;originally was in autohotkey install dir Extras/Scripts/IntelliSense.ahk
; IntelliSense -- by Rajat (requires XP/2k/NT)
; http://www.autohotkey.com
; This script watches while you edit an AutoHotkey script. When it sees you
; type a command followed by a comma or space, it displays that command's
; parameter list to guide you. In addition, you can press Ctrl+F1 (or
; another hotkey of your choice) to display that command's page in the help
; file. To dismiss the parameter list, press Escape or Enter.
; Requires v1.0.41+
; CONFIGURATION SECTION: Customize the script with the following variables.
; The hotkey below is pressed to display the current command's page in the
; help file:
;;;I_HelpHotkey = ^F1
; The string below must exist somewhere in the active window's title for
; IntelliSense to be in effect while you're typing. Make it blank to have
; IntelliSense operate in all windows. Make it Pad to have it operate in
; editors such as Metapad, Notepad, and Textpad. Make it .ahk to have it
; operate only when a .ahk file is open in Notepad, Metapad, etc.
I_Editor = GVIM
; If you wish to have a different icon for this script to distinguish it from
; other scripts in the tray, provide the filename below (leave blank to have
; no icon). For example: E:\stuff\Pics\icons\GeoIcons\Information.ico
I_Icon =
; END OF CONFIGURATION SECTION (do not make changes below this point unless
; you want to change the basic functionality of the script).
SetKeyDelay, 0
;#SingleInstance
;if I_HelpHotkey <>
;Hotkey, %I_HelpHotkey%, I_HelpHotkey
; Change tray icon (if one was specified in the configuration section above):
if I_Icon <>
IfExist, %I_Icon%
Menu, Tray, Icon, %I_Icon%
; Determine AutoHotkey's location:
RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
if ErrorLevel ; Not found, so look for it in some other common locations.
{
if A_AhkPath
SplitPath, A_AhkPath,, ahk_dir
else IfExist ..\..\AutoHotkey.chm
ahk_dir = ..\..
else IfExist %A_ProgramFiles%\AutoHotkey\AutoHotkey.chm
ahk_dir = %A_ProgramFiles%\AutoHotkey
else
{
MsgBox Could not find the AutoHotkey folder.
ExitApp
}
}
ahk_help_file = %ahk_dir%\AutoHotkey.chm
; Read command syntaxes from help file:
Loop, Read, %ahk_dir%\Extras\Editors\Syntax\Commands.txt
{
I_FullCmd = %A_LoopReadLine%
; Directives have a first space instead of a first comma.
; So use whichever comes first as the end of the command name:
StringGetPos, I_cPos, I_FullCmd, `,
StringGetPos, I_sPos, I_FullCmd, %A_Space%
if (I_cPos = -1 or (I_cPos > I_sPos and I_sPos <> -1))
I_EndPos := I_sPos
else
I_EndPos := I_cPos
if I_EndPos <> -1
StringLeft, I_CurrCmd, I_FullCmd, %I_EndPos%
else ; This is a directive/command with no parameters.
I_CurrCmd = %A_LoopReadLine%
StringReplace, I_CurrCmd, I_CurrCmd, [,, All
StringReplace, I_CurrCmd, I_CurrCmd, %A_Space%,, All
StringReplace, I_FullCmd, I_FullCmd, ``n, `n, All
StringReplace, I_FullCmd, I_FullCmd, ``t, `t, All
; Make arrays of command names and full cmd syntaxes:
I_Cmd%A_Index% = %I_CurrCmd%
I_FullCmd%A_Index% = %I_FullCmd%
AppendIndex:=A_Index
}
AppendIndex++
I_Cmd%AppendIndex% = debug
I_FullCmd%AppendIndex%=debug() `;use this to output debug msgs
;TODO read from FunctionLibrary here:
; Read command syntaxes:
;Loop, Read, %ahk_dir%\Extras\Editors\Syntax\Commands.txt
;{
;This
;I_FullCmd = %A_LoopReadLine%
;; Directives have a first space instead of a first comma.
;; So use whichever comes first as the end of the command name:
;StringGetPos, I_cPos, I_FullCmd, `,
;StringGetPos, I_sPos, I_FullCmd, %A_Space%
;if (I_cPos = -1 or (I_cPos > I_sPos and I_sPos <> -1))
;I_EndPos := I_sPos
;else
;I_EndPos := I_cPos
;if I_EndPos <> -1
;StringLeft, I_CurrCmd, I_FullCmd, %I_EndPos%
;else ; This is a directive/command with no parameters.
;I_CurrCmd = %A_LoopReadLine%
;StringReplace, I_CurrCmd, I_CurrCmd, [,, All
;StringReplace, I_CurrCmd, I_CurrCmd, %A_Space%,, All
;StringReplace, I_FullCmd, I_FullCmd, ``n, `n, All
;StringReplace, I_FullCmd, I_FullCmd, ``t, `t, All
;; Make arrays of command names and full cmd syntaxes:
;I_Cmd%A_Index% = %I_CurrCmd%
;I_FullCmd%A_Index% = %I_FullCmd%
;}
; Use the Input command to watch for commands that the user types:
Loop
{
; Editor window check:
WinGetTitle, ActiveTitle, A
IfNotInString, ActiveTitle, %I_Editor%
{
ToolTip
Sleep, 500
Continue
}
; Get all keys till endkey:
Input, I_Word, V, {enter}{escape}{space}`,
I_EndKey = %ErrorLevel%
; Tooltip is hidden in these cases:
if I_EndKey in EndKey:Enter,EndKey:Escape
{
ToolTip
Continue
}
; Editor window check again!
WinGetActiveTitle, ActiveTitle
IfNotInString, ActiveTitle, %I_Editor%
{
ToolTip
Continue
}
; Compensate for any indentation that is present:
StringReplace, I_Word, I_Word, %A_Space%,, All
StringReplace, I_Word, I_Word, %A_Tab%,, All
if I_Word =
Continue
; Check for commented line:
StringLeft, I_Check, I_Word, 1
if (I_Check = ";" or I_Word = "If") ; "If" seems a little too annoying to show tooltip for.
Continue
; Match word with command:
I_Index =
Loop
{
; It helps performance to resolve dynamic variables only once.
; In addition, the value put into I_ThisCmd is also used by the
; I_HelpHotkey subroutine:
I_ThisCmd := I_Cmd%A_Index%
if I_ThisCmd =
break
if (I_Word = I_ThisCmd)
{
I_Index := A_Index
I_HelpOn = %I_ThisCmd%
break
}
}
; If no match then resume watching user input:
if I_Index =
Continue
; Show matched command to guide the user:
I_ThisFullCmd := I_FullCmd%I_Index%
ToolTip, %I_ThisFullCmd%, A_CaretX, A_CaretY + 20
}