aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-12-15 12:20:55 -0500
committerGravatar mitchell <70453897+orbitalquark@users.noreply.github.com>2020-12-15 12:20:55 -0500
commit2bf2867a5095fa88cbe4c22ba39ad87c04b8b393 (patch)
treea557fc7f5fb1cf9c46904c45a51cff1381a8174a
parent7028682c314b636e39d1ab3c74990e27d4666e3c (diff)
Save the current session prior to loading another one.
-rw-r--r--modules/textadept/session.lua1
-rw-r--r--test/test.lua35
2 files changed, 36 insertions, 0 deletions
diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua
index 55a33be8..efadb243 100644
--- a/modules/textadept/session.lua
+++ b/modules/textadept/session.lua
@@ -52,6 +52,7 @@ function M.load(filename)
}
if not filename then return end
end
+ if session_file ~= filename then M.save(session_file) end
local f = loadfile(filename, 't', {})
if not f or not io.close_all_buffers() then return end -- fail silently
local session = f()
diff --git a/test/test.lua b/test/test.lua
index 7bac8baa..7463bfea 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -3149,6 +3149,41 @@ function test_session_save()
events.disconnect(events.SESSION_SAVE, handler)
end
+function test_session_save_before_load()
+ local test_output_text = buffer:get_text()
+ local foo = os.tmpname()
+ local bar = os.tmpname()
+ local baz = os.tmpname()
+ buffer.new()
+ buffer.filename = foo
+ local session1 = os.tmpname()
+ textadept.session.save(session1)
+ buffer:close()
+ buffer.new()
+ buffer.filename = bar
+ local session2 = os.tmpname()
+ textadept.session.save(session2)
+ buffer.new()
+ buffer.filename = baz
+ textadept.session.load(session1) -- should save baz to session
+ assert_equal(#_BUFFERS, 1 + 1) -- test output buffer is open
+ assert_equal(buffer.filename, foo)
+ for i = 1, 2 do
+ textadept.session.load(session2) -- when i == 2, reload; should not re-save
+ assert_equal(#_BUFFERS, 2 + 1) -- test output buffer is open
+ assert_equal(_BUFFERS[#_BUFFERS - 1].filename, bar)
+ assert_equal(_BUFFERS[#_BUFFERS].filename, baz)
+ buffer:close()
+ buffer:close()
+ end
+ os.remove(foo)
+ os.remove(bar)
+ os.remove(baz)
+ os.remove(session1)
+ os.remove(session2)
+ buffer:add_text(test_output_text)
+end
+
function test_snippets_find_snippet()
snippets.foo = 'bar'
textadept.snippets.paths[1] = _HOME .. '/test/modules/textadept/snippets'