aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormitchell <70453897+orbitalquark@users.noreply.github.com>2020-12-15 09:41:59 -0500
committermitchell <70453897+orbitalquark@users.noreply.github.com>2020-12-15 09:41:59 -0500
commitfcb9c717b3721251c52921b123687aa4d62174b1 (patch)
tree06defbf67bce9e09fc9399ba1349eb180bd023aa /core
parentba1f5b94a33e8c586593b62143f22f9e0c4b7bb5 (diff)
downloadtextadept-fcb9c717b3721251c52921b123687aa4d62174b1.tar.gz
textadept-fcb9c717b3721251c52921b123687aa4d62174b1.zip
Do not prompt for file reload during `io.close_all_buffers()`.
Diffstat (limited to 'core')
-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)