aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/file_io.lua13
-rw-r--r--core/gui.lua24
2 files changed, 18 insertions, 19 deletions
diff --git a/core/file_io.lua b/core/file_io.lua
index 1b24586c..adcc3d28 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -219,7 +219,7 @@ local function set_encoding(buffer, encoding)
error(_L['Cannot change binary file encoding'])
end
local pos, first_visible_line = buffer.current_pos, buffer.first_visible_line
- local text = buffer:get_text(buffer.length)
+ local text = buffer:get_text()
text = text:iconv(buffer.encoding, 'UTF-8')
text = text:iconv(encoding, buffer.encoding)
text = text:iconv('UTF-8', encoding)
@@ -236,7 +236,7 @@ local function save(buffer)
buffer:check_global()
if not buffer.filename then buffer:save_as() return end
events.emit(events.FILE_BEFORE_SAVE, buffer.filename)
- local text = buffer:get_text(buffer.length)
+ local text = buffer:get_text()
if buffer.encoding then
text = (buffer.encoding_bom or '')..text:iconv(buffer.encoding, 'UTF-8')
end
@@ -264,11 +264,10 @@ local function save_as(buffer, utf8_filename)
(buffer.filename or ''):match('[^/\\]+$') or '',
'--no-newline')
end
- if #utf8_filename > 0 then
- buffer.filename = utf8_filename
- buffer:save()
- events.emit(events.FILE_SAVED_AS, utf8_filename)
- end
+ if utf8_filename == '' then return end
+ buffer.filename = utf8_filename
+ buffer:save()
+ events.emit(events.FILE_SAVED_AS, utf8_filename)
end
---
diff --git a/core/gui.lua b/core/gui.lua
index 445a65de..4c3c322e 100644
--- a/core/gui.lua
+++ b/core/gui.lua
@@ -252,7 +252,7 @@ function gui.select_theme()
reset()
end
-local events, events_connect, events_emit = events, events.connect, events.emit
+local events, events_connect = events, events.connect
-- Sets default properties for a Scintilla window.
events_connect(events.VIEW_NEW, function()
@@ -274,7 +274,7 @@ events_connect(events.VIEW_NEW, function()
local ok, err = pcall(dofile, THEME..'/view.lua')
if not ok then io.stderr:write(err) end
end)
-events_connect(events.VIEW_NEW, function() events_emit(events.UPDATE_UI) end)
+events_connect(events.VIEW_NEW, function() events.emit(events.UPDATE_UI) end)
local SETDIRECTFUNCTION = _SCINTILLA.properties.direct_function[1]
local SETDIRECTPOINTER = _SCINTILLA.properties.doc_pointer[2]
@@ -310,7 +310,7 @@ end)
-- Sets the title of the Textadept window to the buffer's filename.
-- @param buffer The global buffer.
-local function set_title(buffer)
+local function set_title()
local filename = buffer.filename or buffer._type or _L['Untitled']
local basename = buffer.filename and filename:match('[^/\\]+$') or filename
gui.title = string.format('%s %s Textadept (%s)', basename,
@@ -320,13 +320,13 @@ end
-- Changes Textadept title to show the buffer as being "clean".
events_connect(events.SAVE_POINT_REACHED, function()
buffer.dirty = false
- set_title(buffer)
+ set_title()
end)
-- Changes Textadept title to show thee buffer as "dirty".
events_connect(events.SAVE_POINT_LEFT, function()
buffer.dirty = true
- set_title(buffer)
+ set_title()
end)
-- Open uri(s).
@@ -344,7 +344,7 @@ events_connect(events.URI_DROPPED, function(utf8_uris)
end
end)
events_connect(events.APPLEEVENT_ODOC, function(uri)
- return events_emit(events.URI_DROPPED, 'file://'..uri)
+ return events.emit(events.URI_DROPPED, 'file://'..uri)
end)
local EOLs = {_L['CRLF'], _L['CR'], _L['LF']}
@@ -371,8 +371,8 @@ events_connect(events.MARGIN_CLICK, function(margin, pos, modifiers)
end)
-- Updates the statusbar and titlebar for a new Scintilla document.
-events_connect(events.BUFFER_NEW, function() events_emit(events.UPDATE_UI) end)
-events_connect(events.BUFFER_NEW, function() set_title(buffer) end)
+events_connect(events.BUFFER_NEW, function() events.emit(events.UPDATE_UI) end)
+events_connect(events.BUFFER_NEW, function() set_title() end)
-- Save buffer properties.
events_connect(events.BUFFER_BEFORE_SWITCH, function()
@@ -403,14 +403,14 @@ end)
-- Updates titlebar and statusbar.
events_connect(events.BUFFER_AFTER_SWITCH, function()
- set_title(buffer)
- events_emit(events.UPDATE_UI)
+ set_title()
+ events.emit(events.UPDATE_UI)
end)
-- Updates titlebar and statusbar.
events_connect(events.VIEW_AFTER_SWITCH, function()
- set_title(buffer)
- events_emit(events.UPDATE_UI)
+ set_title()
+ events.emit(events.UPDATE_UI)
end)
events_connect(events.RESET_AFTER,