-
Notifications
You must be signed in to change notification settings - Fork 0
/
NPP syntax check on save.ahk
90 lines (87 loc) · 3.57 KB
/
NPP syntax check on save.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
; By DRSAgile, https://github.com/DRSAgile/NPP-syntax-check-on-save/
;
; This file MUST be saved with "UTF-8 with BOM" encoding at all times, unlike JS where it is better without BOM
;
;
;The necessary steps for the script to work as intended:
;
;
; in Windows:
;
; 1. install MAMP (uncheck "MAMP Pro", if you do not have a paid account) or a standalone PHP engine
;
; 2. set "Run as administrator" in "Compatibility" section of AHK executable's settings
;
; 3. set "Run as administrator" in "Compatibility" section of NPP executable's settings OR -- since the flag is sometimes dropped with NPP updates -- use Task Scheduler to launch it with elevated rights
;
; in NPP:
;
; 4. install JSLint plugin via "Plugins", "Plagins Admin..." menu
;
; 5. install NPPExect plugin via "Plugins", "Plagins Admin..." menu
;
;
; in NppExec plugin within NPP:
;
; 6. in "Console Output..." menu, set "Console input/output encoding" to "UTF8/UTF" as otherwise non-ANSI paths will not be understood
;
; 7. in "Execute NppExec Script..." menu, create "Start AHK for NPP syntax check on save" script; for example:
; cmd.exe /C start "" "C:\Program Files\AutoHotkey\AutoHotkey.exe" "C:\Users\zxs\OneDrive\Рабочий стол\Прочее\NPP syntax check on save.ahk"
;
; 8. in "Advanced Options..." menu, add this script to "Execute this script when Notepad++ starts" field
;
; 9. in "Execute NppExec Script..." menu, create "PHP syntax check" script; for example:
; "C:\MAMP\bin\php\php8.1.0\php.exe" -l "$(FULL_CURRENT_PATH)"
;
; 10. in "Advanced Options..." menu, select this (#9) script in "Associated scripts" field
;
;
; in NPP again:
;
; 11. restart NPP
;
; 12. assign specifically "alt+shift+F6" hotkey to the script #9) script via "Settings", "Shortcut Mapper...", "Plugin commands", "Execute NppExec Script..." (care for possible shortcut key conflicts)
;
; 13. for AHK's Function List panel to work follow the instruction: https://www.autohotkey.com/boards/viewtopic.php?p=366054#p366054 and https://npp-user-manual.org/docs/function-list/
; this will lead to updating %APPDATA%\notepad++\functionList\overrideMap.xml and to creating "akh.xml" in %APPDATA%\notepad++\functionList\.
; Be careful to correctly put the name of User Defined Language in overrideMap.xml
#Persistent
#SingleInstance force
#IfWinActive, ahk_class Notepad++
$^vk53::
$^s::
$^sc01F::
StatusBarGetText,text,,ahk_class Notepad++
if (text = "JavaScript file")
{
WinWaitActive, ahk_class Notepad++ ; use Sleep 1000 in case if Control+S should come AFTER the text processing as otherwise the ANSI control code "DC3" will be inserted in the text instead of saving the file. Calls for plug-ins such as JSLint do not get reflected correctly in NP++'s "Ready" responses to Windows API. Saving the file is a built-in operation and thus it does not require the use of Sleep 1000 after it to properly call for a syntax check
Send ^{vk53sc01F}
WinWaitActive, ahk_class Notepad++
Send ^+{F5}
}
else if (text = "PHP Hypertext Preprocessor file")
{
WinWaitActive, ahk_class Notepad++
Send ^{vk53sc01F}
WinWaitActive, ahk_class Notepad++
Send !+{F6}
}
else if (text = "User Defined language file - Autohotkey")
{
WinWaitActive, ahk_class Notepad++
Send ^{vk53sc01F}
WinWaitActive, ahk_class Notepad++
WinGetTitle, title
StringGetPos, pos, title, %A_ScriptName%
if (pos >= 0)
Reload
else
Run % Trim(StrReplace(StrReplace(title, " - NotePad++", ""), "*", ""))
}
else
{
WinWaitActive, ahk_class Notepad++
Send ^{vk53sc01F}
}
return
#IfWinActive