-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormat source.script
77 lines (57 loc) · 1.75 KB
/
Format source.script
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
npp_console -
npp_switch $(ARGV[2])
// Holds the path to a temporary file with the source to be formatted
set local FILE = $(SYS.TEMP)\$(FILE_NAME)
// Holds the path to a temporary file with the stderr output of the command
set local ERRLOG = $(SYS.TEMP)\output.err
// Holds the path to the C and C++ config for Uncrustify.
set local UNCRUSTIFY_CFG =
// Holds the path to the google-java-format tool.
set local GOOGLE_JAVA_FORMAT =
sci_sendmsg SCI_GETCURRENTPOS
set local POS = $(MSG_RESULT)
sci_sendmsg SCI_GETFIRSTVISIBLELINE
set local FIRST_LINE = $(MSG_RESULT)
sci_sendmsg SCI_GETXOFFSET
set local X_OFFSET = $(MSG_RESULT)
sci_sendmsg SCI_SELECTALL
sel_saveto $(FILE)
set local EXT ~ strlower $(EXT_PART)
if $(EXT) == .c goto format_c
if $(EXT) == .h goto format_c
if $(EXT) == .cpp goto format_cpp
if $(EXT) == .hpp goto format_cpp
if $(EXT) == .java goto format_java
if $(EXT) == .py goto format_python
cmd /c echo "Unsupported extension: $(EXT)" > $(ERRLOG)
goto error
:format_c
:format_cpp
cmd /c uncrustify -f $(FILE) -o $(FILE) -c $(UNCRUSTIFY_CFG) 2> $(ERRLOG)
goto validate
:format_java
cmd /c java -jar $(GOOGLE_JAVA_FORMAT) -r $(FILE) 2> $(ERRLOG)
goto validate
:format_python
cmd /c yapf --in-place $(FILE) 2> $(ERRLOG)
goto validate
:validate
if $(EXITCODE) != 0 goto error
npp_switch $(ARGV[])
sci_sendmsg SCI_SELECTALL
sel_loadfrom $(FILE)
sci_sendmsg SCI_GOTOPOS $(POS)
sci_sendmsg SCI_SETXOFFSET $(X_OFFSET)
sci_sendmsg SCI_SETFIRSTVISIBLELINE $(FIRST_LINE)
goto done
:error
sci_sendmsg SCI_GOTOPOS $(POS)
con_color FG=FF0000 BG=FFFFFF
npp_console on
npp_console +
echo Failed to format source file $(FILE)
con_loadfrom $(ERRLOG)
npp_console -
con_color reset
:done
npp_console +