-
Notifications
You must be signed in to change notification settings - Fork 2
/
display_filename.lua
62 lines (53 loc) · 1.56 KB
/
display_filename.lua
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
-- Shorten display filenames in buffer title and switch buffer dialog.
-- On Windows
-- C:\Documents and Settings\username\Desktop\...
-- is replaced with
-- Desktop\...,
-- on Max OS X and Linux
-- /home/username/..
-- or
-- /Users/username/...
-- with
-- ~/...
--
-- Modified from Textadept's `core.ui. module.
-- ## Fields
local pattern, replacement
-- Read environment variable.
if WIN32 then
pattern = os.getenv('USERPROFILE')..'\\'
replacement = ''
else
pattern = '^'..os.getenv('HOME')
replacement = '~'
end
-- ## Commands
-- Sets the title of the Textadept window to the buffer's filename.
-- Parameter:<br>
-- _buffer_: The currently focused buffer.
local function set_title(buffer)
local buffer = buffer
local filename = buffer.filename or buffer._type or _L['Untitled']
local dirty = buffer.dirty and '*' or '-'
ui.title = string.format('%s %s Textadept (%s)', filename:match('[^/\\]+$'),
dirty, filename:gsub(pattern, replacement))
end
-- Connect to events that change the title.
events.connect('save_point_reached',
function() -- changes Textadept title to show 'clean' buffer
buffer.dirty = false
set_title(buffer)
end)
events.connect('save_point_left',
function() -- changes Textadept title to show 'dirty' buffer
buffer.dirty = true
set_title(buffer)
end)
events.connect('buffer_after_switch',
function() -- updates titlebar and statusbar
set_title(buffer)
end)
events.connect('view_after_switch',
function() -- updates titlebar and statusbar
set_title(buffer)
end)