aboutsummaryrefslogtreecommitdiff
path: root/core/file_io.lua
diff options
context:
space:
mode:
Diffstat (limited to 'core/file_io.lua')
-rw-r--r--core/file_io.lua32
1 files changed, 17 insertions, 15 deletions
diff --git a/core/file_io.lua b/core/file_io.lua
index 0426083a..24c04926 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -244,6 +244,21 @@ local function close(buffer, force)
return true
end
+-- Detects if the current file has been externally modified and, if so, emits a
+-- `FILE_CHANGED` event.
+local function update_modified_file()
+ if not buffer.filename then return end
+ local mod_time = lfs.attributes(buffer.filename, 'modification')
+ if mod_time and buffer.mod_time and buffer.mod_time < mod_time then
+ buffer.mod_time = mod_time
+ events.emit(events.FILE_CHANGED, buffer.filename)
+ end
+end
+events.connect(events.BUFFER_AFTER_SWITCH, update_modified_file)
+events.connect(events.VIEW_AFTER_SWITCH, update_modified_file)
+events.connect(events.FOCUS, update_modified_file)
+events.connect(events.RESUME, update_modified_file)
+
---
-- Closes all open buffers, prompting the user to continue if there are unsaved
-- buffers, and returns `true` if the user did not cancel.
@@ -252,7 +267,9 @@ end
-- @see buffer.close
-- @name close_all_buffers
function io.close_all_buffers()
+ events.disconnect(events.BUFFER_AFTER_SWITCH, update_modified_file)
while #_BUFFERS > 1 do if not buffer:close() then return nil end end
+ events.connect(events.BUFFER_AFTER_SWITCH, update_modified_file)
return buffer:close() -- the last one
end
@@ -268,21 +285,6 @@ end)
-- emitted.
io._reload, io._save, io._save_as, io._close = reload, save, save_as, close
--- Detects if the current file has been externally modified and, if so, emits a
--- `FILE_CHANGED` event.
-local function update_modified_file()
- if not buffer.filename then return end
- local mod_time = lfs.attributes(buffer.filename, 'modification')
- if mod_time and buffer.mod_time and buffer.mod_time < mod_time then
- buffer.mod_time = mod_time
- events.emit(events.FILE_CHANGED, buffer.filename)
- end
-end
-events.connect(events.BUFFER_AFTER_SWITCH, update_modified_file)
-events.connect(events.VIEW_AFTER_SWITCH, update_modified_file)
-events.connect(events.FOCUS, update_modified_file)
-events.connect(events.RESUME, update_modified_file)
-
-- Prompts the user to reload the current file if it has been externally
-- modified.
events.connect(events.FILE_CHANGED, function(filename)