Re: [Ext] [code] How to auto save?

From: Mitchell <>
Date: Wed, 24 Jun 2020 18:50:24 -0400 (EDT)

Hi James,

On Wed, 24 Jun 2020, James Reynolds wrote:

> My goal is to minimize a lot of problems I'm having because the files I open are located on a file share. If I disconnect the fileshare one problem is that I can't save the file unless I remount the fileshare. So periodic saving would solve that problem.
> I'm assuming this isn't checking to see if the buffer has changed since the last save. How hard is that? And is it possible to force open a "save as" dialog if the buffer doesn't have a filename? I know I could look this up but I am still really overwhelmed by the documentation... I'm hoping you can give me some quick hints.

   events.connect(events.BUFFER_BEFORE_SWITCH, function()
     if buffer.modify then buffer:save() end

`buffer:save()` will prompt for a filename if there isn't one.

> Another problem I have is if I try to open Textadept (or a session file) and the files in the session are located on the fileshare but the fileshare isn't mounted. Obviously it can't open the files but the problem is that Textadept immediately saves the session and excludes the previously open files so that the next time I open the session the files are not even attempted. Is there a way to not save the session file if one of the files in it doesn't load but instead to only save if I make a change to the session?

There is no specific setting for this, however you may be able to work around the problem by connecting to `events.SESSION_LOAD` and `events.SESSION_SAVE`, storing and loading your fileshare files as necessary. (Note, you can get a list of files in the session via the undocumented `session.buffers` object.) For example:

   local fileshare_files = {}
   events.connect(events.SESSION_LOAD, function(session)
     -- These are read from what Textadept saves.
     for _, buf in ipairs(session.buffers) do
       if buf.filename:find('fileshare_pattern') then
         fileshare_files[#fileshare_files + 1] = buf.filename
     -- These are read from what you save in your SESSION_SAVE.
     for _, filename in ipairs(session.my_fileshare_files) do
       fileshare_files[#fileshare_files + 1] = filename
       if lfs.attributes(filename) then io.open_file(filename) end
   events.connect(events.SESSION_SAVE, function(session)
     session.my_fileshare_files = fileshare_files

It's completely untested, but that's the idea. You can also manually save a session you want to preserve, and then use the command line to specify a read-only session via `ta -n -s my_session`. The `-n` switch means Textadept will not save session on exit. Otherwise, *my_session* would be saved on exit.

>> Textadept does not report when its window loses focus.
> Is this because of Scintilla?

This is because I've not exposed that event to Lua (if GTK reports it).

> I'm just thinking about this and everything I want to change to make it more Mac like is probably because of Scintilla/GTK. I know Cocoa apps are notified when they lose focus. I have no intention of asking anyone of doing this or doing it myself, but I'm curious how difficult it would be to swap Scintilla/GTK with a native Cocoa app... If most of the logic of Textadept is in the Lua files, and if it's less than 4000 lines of code (or something), then maybe it wouldn't be that hard...

That would involve a GUI toolkit switch from GTK to Cocoa, which I will not be doing. I prefer one toolkit that runs on all platforms.


You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Wed 24 Jun 2020 - 18:50:24 EDT

This archive was generated by hypermail 2.2.0 : Thu 25 Jun 2020 - 06:43:03 EDT