-
Notifications
You must be signed in to change notification settings - Fork 2
/
display_filename.html
185 lines (161 loc) · 5.31 KB
/
display_filename.html
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
<!DOCTYPE html>
<html>
<head>
<title>display_filename.lua</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="locco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<div id="jump_to">
Jump To …
<div id="jump_wrapper">
<div id="jump_page">
<a class="source" href="display_filename.html">display_filename.lua</a>
<a class="source" href="enclose.html">enclose.lua</a>
<a class="source" href="filename.html">filename.lua</a>
<a class="source" href="findall.html">findall.lua</a>
<a class="source" href="highlight.html">highlight.lua</a>
<a class="source" href="index.html">init.lua</a>
<a class="source" href="lastbuffer.html">lastbuffer.lua</a>
<a class="source" href="multiedit.html">multiedit.lua</a>
<a class="source" href="project.html">project.lua</a>
<a class="source" href="save_strips_ws.html">save_strips_ws.lua</a>
</div>
</div>
</div>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="docs">
<h1>
display_filename.lua
</h1>
</th>
<th class="code">
</th>
</tr>
</thead>
<tbody>
<tr id="section-1">
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-1">¶</a>
</div>
<p>Shorten display filenames in buffer title and switch buffer dialog.
On Windows</p>
<pre><code>C:\Documents and Settings\username\Desktop\...
</code></pre>
<p>is replaced with</p>
<pre><code>Desktop\...,
</code></pre>
<p>on Max OS X and Linux</p>
<pre><code>/home/username/..
</code></pre>
<p>or</p>
<pre><code>/Users/username/...
</code></pre>
<p>with</p>
<pre><code>~/...
</code></pre>
<p>Modified from Textadept's `core.ui. module.</p>
</td>
<td class="code">
<div class="highlight"><pre>
</pre></div>
</td>
</tr><tr id="section-2">
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<h2>Fields</h2>
</td>
<td class="code">
<div class="highlight"><pre>
<span class="k">local</span> pattern, replacement
</pre></div>
</td>
</tr><tr id="section-3">
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<p>Read environment variable.</p>
</td>
<td class="code">
<div class="highlight"><pre><span class="k">if</span> WIN32 <span class="k">then</span>
pattern = os.getenv(<span class="s">'USERPROFILE'</span>)..<span class="s">'\\'</span>
replacement = <span class="s">''</span>
<span class="k">else</span>
pattern = <span class="s">'^'</span>..os.getenv(<span class="s">'HOME'</span>)
replacement = <span class="s">'~'</span>
<span class="k">end</span>
</pre></div>
</td>
</tr><tr id="section-4">
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<h2>Commands</h2>
</td>
<td class="code">
<div class="highlight"><pre>
</pre></div>
</td>
</tr><tr id="section-5">
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<p>Sets the title of the Textadept window to the buffer's filename.
Parameter:<br>
<em>buffer</em>: The currently focused buffer.</p>
</td>
<td class="code">
<div class="highlight"><pre><span class="k">local</span> <span class="k">function</span> <span class="nf">set_title</span>(buffer)
<span class="k">local</span> buffer = buffer
<span class="k">local</span> filename = buffer.filename <span class="o">or</span> buffer._<span class="nt">type</span> <span class="o">or</span> _L[<span class="s">'Untitled'</span>]
<span class="k">local</span> dirty = buffer.dirty <span class="o">and</span> <span class="s">'*'</span> <span class="o">or</span> <span class="s">'-'</span>
ui.title = string.format(<span class="s">'%s %s Textadept (%s)'</span>, filename:match(<span class="s">'[^/\\]+$'</span>),
dirty, filename:gsub(pattern, replacement))
<span class="k">end</span>
</pre></div>
</td>
</tr><tr id="section-6">
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-6">¶</a>
</div>
<p>Connect to events that change the title.</p>
</td>
<td class="code">
<div class="highlight"><pre>events.connect(<span class="s">'save_point_reached'</span>,
<span class="k">function</span>() <span class="c">-- changes Textadept title to show 'clean' buffer
</span> buffer.dirty = <span class="k">false</span>
set_title(buffer)
<span class="k">end</span>)
events.connect(<span class="s">'save_point_left'</span>,
<span class="k">function</span>() <span class="c">-- changes Textadept title to show 'dirty' buffer
</span> buffer.dirty = <span class="k">true</span>
set_title(buffer)
<span class="k">end</span>)
events.connect(<span class="s">'buffer_after_switch'</span>,
<span class="k">function</span>() <span class="c">-- updates titlebar and statusbar
</span> set_title(buffer)
events.emit(<span class="s">'update_ui'</span>)
<span class="k">end</span>)
events.connect(<span class="s">'view_after_switch'</span>,
<span class="k">function</span>() <span class="c">-- updates titlebar and statusbar
</span> set_title(buffer)
events.emit(<span class="s">'update_ui'</span>)
<span class="k">end</span>)
</pre></div>
</td>
</tr></tbody>
</table>
</div>
</body>
</html>