forked from dail8859/LuaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstylecustom.lua.html
More file actions
156 lines (129 loc) · 7.07 KB
/
Copy pathstylecustom.lua.html
File metadata and controls
156 lines (129 loc) · 7.07 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>LuaScript Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>LuaScript <sub>v0.6.0</sub></h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Examples</h2>
<ul class="nowrap">
<li><a href="../examples/bookmark.lua.html">bookmark.lua</a></li>
<li><a href="../examples/highlightoccurrences.lua.html">highlightoccurrences.lua</a></li>
<li><a href="../examples/luaautoindent.lua.html">luaautoindent.lua</a></li>
<li><a href="../examples/luasyntaxchecker.lua.html">luasyntaxchecker.lua</a></li>
<li><a href="../examples/selectionaddnext.lua.html">selectionaddnext.lua</a></li>
<li><a href="../examples/sessionmanager.lua.html">sessionmanager.lua</a></li>
<li><a href="../examples/stylecsv.lua.html">stylecsv.lua</a></li>
<li><strong>stylecustom.lua</strong></li>
<li><a href="../examples/visualstudiolinecopy.lua.html">visualstudiolinecopy.lua</a></li>
</ul>
<h2>Classes</h2>
<ul class="nowrap">
<li><a href="../classes/Editor.html">Editor</a></li>
<li><a href="../classes/Match.html">Match</a></li>
<li><a href="../classes/Styler.html">Styler</a></li>
<li><a href="../classes/Notepad.html">Notepad</a></li>
</ul>
<h2>Topics</h2>
<ul class="">
<li><a href="../topics/callbacks.md.html">callbacks</a></li>
</ul>
</div>
<div id="content">
<h2>stylecustom.lua</h2>
<pre>
<span class="comment">--[[ An example file
proc clip(int a)
« Clip into the positive zone »
if (a > 0) a
0
end
]]</span>
<span class="comment">-- Define style numbers
</span>S_DEFAULT = <span class="number">0</span>
S_IDENTIFIER = <span class="number">1</span>
S_KEYWORD = <span class="number">2</span>
S_UNICODECOMMENT = <span class="number">3</span>
<span class="comment">-- Anytime a file is switched, check to see if it needs styled
</span>npp.AddEventHandler(<span class="string">"OnSwitchFile"</span>, <span class="keyword">function</span>(filename, bufferid)
<span class="keyword">if</span> npp:GetExtPart() == <span class="string">".abc"</span> <span class="keyword">then</span>
<span class="comment">-- Add the event handler for our custom style function
</span> npp.AddEventHandler(<span class="string">"OnStyle"</span>, CustomStyle)
<span class="comment">-- Make sure to set the lexer as a custom container
</span> editor.Lexer = SCLEX_CONTAINER
<span class="comment">-- Set up the styles as appropriate
</span> editor.StyleFore[S_DEFAULT] = <span class="number">0x7f007f</span>
editor.StyleBold[S_DEFAULT] = <span class="keyword">true</span>
editor.StyleFore[S_IDENTIFIER] = <span class="number">0x000000</span>
editor.StyleFore[S_KEYWORD] = <span class="number">0x800000</span>
editor.StyleBold[S_KEYWORD] = <span class="keyword">true</span>
editor.StyleFore[S_UNICODECOMMENT] = <span class="number">0x008000</span>
editor.StyleFont[S_UNICODECOMMENT] = <span class="string">"Georgia"</span>
editor.StyleItalic[S_UNICODECOMMENT] = <span class="keyword">true</span>
editor.StyleSize[S_UNICODECOMMENT] = <span class="number">9</span>
<span class="comment">-- Clear any style and re-lex the entire document
</span> editor:ClearDocumentStyle()
editor:Colourise(<span class="number">0</span>, -<span class="number">1</span>)
<span class="keyword">else</span>
<span class="comment">-- Can remove the handler if it's not needed
</span> npp.RemoveEventHandler(<span class="string">"OnStyle"</span>, CustomStyle)
<span class="keyword">end</span>
<span class="keyword">return</span> <span class="keyword">false</span>
<span class="keyword">end</span>)
<span class="comment">-- Style the document. Handles UTF-8 characters
</span><span class="keyword">function</span> CustomStyle(styler)
identifierCharacters = <span class="string">"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"</span>
styler:StartStyling(styler.startPos, styler.lengthDoc, styler.initStyle)
<span class="keyword">while</span> styler:More() <span class="keyword">do</span>
<span class="comment">-- Exit state if needed
</span> <span class="keyword">if</span> styler:State() == S_IDENTIFIER <span class="keyword">then</span>
<span class="keyword">if</span> <span class="keyword">not</span> identifierCharacters:find(styler:Current(), <span class="number">1</span>, <span class="keyword">true</span>) <span class="keyword">then</span>
identifier = styler:Token()
<span class="keyword">if</span> identifier == <span class="string">"if"</span> <span class="keyword">or</span> identifier == <span class="string">"end"</span> <span class="keyword">then</span>
styler:ChangeState(S_KEYWORD)
<span class="keyword">end</span>
styler:SetState(S_DEFAULT)
<span class="keyword">end</span>
<span class="keyword">elseif</span> styler:State() == S_UNICODECOMMENT <span class="keyword">then</span>
<span class="keyword">if</span> styler:Match(<span class="string">"»"</span>) <span class="keyword">then</span>
styler:ForwardSetState(S_DEFAULT)
<span class="keyword">end</span>
<span class="keyword">end</span>
<span class="comment">-- Enter state if needed
</span> <span class="keyword">if</span> styler:State() == S_DEFAULT <span class="keyword">then</span>
<span class="keyword">if</span> styler:Match(<span class="string">"«"</span>) <span class="keyword">then</span>
styler:SetState(S_UNICODECOMMENT)
<span class="keyword">elseif</span> identifierCharacters:find(styler:Current(), <span class="number">1</span>, <span class="keyword">true</span>) <span class="keyword">then</span>
styler:SetState(S_IDENTIFIER)
<span class="keyword">end</span>
<span class="keyword">end</span>
styler:Forward()
<span class="keyword">end</span>
styler:EndStyling()
<span class="keyword">end</span></pre>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>Generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
<footer>
<a href="https://github.com/dail8859/LuaScript"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png"></a>
</footer>
</body>
</html>