Skip to content

Commit

Permalink
Show number of unsaved buffers on quit.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbm committed Apr 28, 2023
1 parent 2debb10 commit a69b0dd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -719,17 +719,18 @@ function e.redo(b)
end--redo

function e.exiteditor(b)
local anyunsaved = false
local unsaved = 0
for i, bx in ipairs(editor.buflist) do
-- tmp buffers: if name starts with '*',
-- buffer is not considered as unsaved
if bx.filename and not bx.filename:match("^%*") then
anyunsaved = anyunsaved or bx.unsaved
if bx.filename and not bx.filename:match("^%*") and bx.unsaved then
unsaved = unsaved + 1
end
end
if anyunsaved then
local ch = readchar(
"Some buffers not saved. Quit? ", "[YNyn\r\n]")
if unsaved ~= 0 then
local readmsg = unsaved .. " buffers not saved. Quit? "
if unsaved == 1 then readmsg = "1 buffer not saved. Quit? " end
local ch = readchar(readmsg, "[YNyn\r\n]")
if ch ~= "y" and ch ~= "Y" then
msg("aborted.")
return
Expand Down

0 comments on commit a69b0dd

Please sign in to comment.