diff options
-rw-r--r-- | doc/04_WorkingWithFiles.md | 10 | ||||
-rw-r--r-- | doc/13_Help.md | 1 | ||||
-rw-r--r-- | modules/textadept/session.lua | 9 |
3 files changed, 15 insertions, 5 deletions
diff --git a/doc/04_WorkingWithFiles.md b/doc/04_WorkingWithFiles.md index 1ea480ce..04b4726c 100644 --- a/doc/04_WorkingWithFiles.md +++ b/doc/04_WorkingWithFiles.md @@ -87,10 +87,12 @@ files to reopen. By default, Textadept saves its state on exit so it can be restored the next time the editor starts up. You can disable this by passing the `-n` or `--nosession` switch to Textadept on startup. Sessions can be manually saved and -opened via the "File -> Save Session..." and "File -> Load Session..." menus. -Session files store information such as open buffers, current split views, caret -and scroll positions in each buffer, Textadept's window size, and recently -opened files. Tampering with session files may have unintended consequences. +opened via the "File -> Save Session..." and "File -> Load Session..." menus or +by using the `-s` and `--session` switches on startup. The switches accept the +path of a session file or the name of a session in *~/.textadept/*. Session +files store information such as open buffers, current split views, caret and +scroll positions in each buffer, Textadept's window size, and recently opened +files. Tampering with session files may have unintended consequences. ### Snapopen diff --git a/doc/13_Help.md b/doc/13_Help.md index 6cbcdb52..f2c3dedc 100644 --- a/doc/13_Help.md +++ b/doc/13_Help.md @@ -10,6 +10,7 @@ Switch |Arguments|Description `-f`, `--force` | 0 |Forces [unique instance][]. `-h`, `--help` | 0 |Shows this. `-n`, `--nosession`| 0 |No [session][] functionality. +`-s`, `--session` | 1 |Loads [session][] on startup. `-u`, `--userhome` | 1 |Sets alternate [`_USERHOME`][]. The help switch is unavailable in ncurses. diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index b09c2b54..05b7ff58 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -198,12 +198,19 @@ function M.save(filename) f:close() end end --- Save session on quit. +-- Saves session on quit. events.connect(events.QUIT, function() if M.SAVE_ON_QUIT then M.save(M.DEFAULT_SESSION) end end, 1) +-- Does not save session on quit. local function no_session() M.SAVE_ON_QUIT = false end args.register('-n', '--nosession', 0, no_session, 'No session functionality') +-- Loads the given session on startup. +local function load_session(name) + if lfs.attributes(name) then M.load(name) return end + M.load(_USERHOME..'/'..name) +end +args.register('-s', '--session', 1, load_session, 'Load session') return M |