Re: [code] Close editor when unsaved changes

From: Procházka Lukáš Ing. <LPr.att.pontex.cz>
Date: Tue, 03 Sep 2019 15:35:52 +0200

Hello,

I created a simple code which should provide "Save & quit" option for TA.
Unsaved changes in [Message Buffer] and similar [...] are to be discarded.

Place the code anywhere you modify your key bindings.

In my case, I overwrite Ctrl+Q key.

----
-- Quit (save all unsaved files optionally)
keys["cq"] = function()
   local quit = function()
     -- Clear modification flags for all buffers first
     for _, buf in ipairs(_BUFFERS) do
       buf:set_save_point()
     end
     quit() -- Original
   end
   --
   local unsaved = {}
   for _, buf in ipairs(_BUFFERS) do
     if buf.filename and buf.modify then table.insert(unsaved, buf.filename) end
   end
   if #unsaved > 0 then
     local ans = ui.dialogs.msgbox{ title = "Quit?",
                                    text = "The following buffers were not saved: \n\n\t" ..
                                             table.concat(unsaved, "\n\t") ..
                                             "\n",
                                           icon  = "gtk-dialog-question",
                                           button2 = "Cancel",
                                           button3 = "Quit anyway",
                                           button1 = "Save unsaved files & quit",
                                  }
--ui.print(ans); do return  end
     if ans == -1 or ans == 2 then
       -- Cancel - do not do anything
     elseif ans == 1 then
       -- Save & quit
       io.save_all_files()
       quit()
     elseif ans == 3 then
       -- Quit anyway
       quit()
     end
   else
     -- Nothing to save
     quit()
   end
end
----
Any feedback is welcome.
Best regards,
Lukas
On Tue, 13 Aug 2019 22:52:10 +0200, Thorsten Kampe <thorsten.att.thorstenkampe.de> wrote:
> Hi,
>
> when trying to close the editor or document, I get the options
> "Quit without saving" and "Cancel". Every other editor I know,
> offers "Save and quit" or "Save and close". Why not Textadept?
>
> Regards, Thorsten
>
-- 
Ing. Lukáš Procházka | mailto:LPr.att.pontex.cz
Pontex s. r. o.      | mailto:pontex@pontex.cz | http://www.pontex.cz | IDDS:nrpt3sn
Bezová 1658
147 14 Praha 4
Mob.: +420 702 033 396
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Tue 03 Sep 2019 - 09:35:52 EDT

This archive was generated by hypermail 2.2.0 : Wed 04 Sep 2019 - 06:51:02 EDT