mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
Merge
This commit is contained in:
@@ -23,12 +23,9 @@ func shouldContinue() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(text) <= 1 {
|
text = strings.TrimRight(text, "\r\n")
|
||||||
// default continue
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.ToLower(text)[0] == 'y'
|
return len(text) == 0 || strings.ToLower(text)[0] == 'y'
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanConfig performs cleanup in the user's configuration directory
|
// CleanConfig performs cleanup in the user's configuration directory
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package action
|
package action
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -807,7 +810,7 @@ func (h *BufPane) SaveAs() bool {
|
|||||||
func (h *BufPane) saveBufToFile(filename string, action string, callback func()) bool {
|
func (h *BufPane) saveBufToFile(filename string, action string, callback func()) bool {
|
||||||
err := h.Buf.SaveAs(filename)
|
err := h.Buf.SaveAs(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.HasSuffix(err.Error(), "permission denied") {
|
if errors.Is(err, fs.ErrPermission) {
|
||||||
saveWithSudo := func() {
|
saveWithSudo := func() {
|
||||||
err = h.Buf.SaveAsWithSudo(filename)
|
err = h.Buf.SaveAsWithSudo(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -824,12 +827,15 @@ func (h *BufPane) saveBufToFile(filename string, action string, callback func())
|
|||||||
if h.Buf.Settings["autosu"].(bool) {
|
if h.Buf.Settings["autosu"].(bool) {
|
||||||
saveWithSudo()
|
saveWithSudo()
|
||||||
} else {
|
} else {
|
||||||
InfoBar.YNPrompt("Permission denied. Do you want to save this file using sudo? (y,n)", func(yes, canceled bool) {
|
InfoBar.YNPrompt(
|
||||||
if yes && !canceled {
|
fmt.Sprintf("Permission denied. Do you want to save this file using %s? (y,n)", config.GlobalSettings["sucmd"].(string)),
|
||||||
saveWithSudo()
|
func(yes, canceled bool) {
|
||||||
h.completeAction(action)
|
if yes && !canceled {
|
||||||
}
|
saveWithSudo()
|
||||||
})
|
h.completeAction(action)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if readonly && prompt != nil {
|
if readonly && prompt != nil {
|
||||||
prompt.Message("Warning: file is readonly - sudo will be attempted when saving")
|
prompt.Message(fmt.Sprintf("Warning: file is readonly - %s will be attempted when saving", config.GlobalSettings["sucmd"].(string)))
|
||||||
// buf.SetOptionNative("readonly", true)
|
// buf.SetOptionNative("readonly", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -60,13 +60,11 @@ ft["zig"] = "// %s"
|
|||||||
ft["zscript"] = "// %s"
|
ft["zscript"] = "// %s"
|
||||||
ft["zsh"] = "# %s"
|
ft["zsh"] = "# %s"
|
||||||
|
|
||||||
function onBufferOpen(buf)
|
function updateCommentType(buf)
|
||||||
if buf.Settings["commenttype"] == nil then
|
if ft[buf.Settings["filetype"]] ~= nil and ft[buf.Settings["filetype"]] ~= nil then
|
||||||
if ft[buf.Settings["filetype"]] ~= nil then
|
buf.Settings["commenttype"] = ft[buf.Settings["filetype"]]
|
||||||
buf.Settings["commenttype"] = ft[buf.Settings["filetype"]]
|
elseif buf.Settings["commenttype"] == nil then
|
||||||
else
|
buf.Settings["commenttype"] = "# %s"
|
||||||
buf.Settings["commenttype"] = "# %s"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -79,6 +77,8 @@ function isCommented(bp, lineN, commentRegex)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function commentLine(bp, lineN)
|
function commentLine(bp, lineN)
|
||||||
|
updateCommentType(bp.Buf)
|
||||||
|
|
||||||
local line = bp.Buf:Line(lineN)
|
local line = bp.Buf:Line(lineN)
|
||||||
local commentType = bp.Buf.Settings["commenttype"]
|
local commentType = bp.Buf.Settings["commenttype"]
|
||||||
local sel = -bp.Cursor.CurSelection
|
local sel = -bp.Cursor.CurSelection
|
||||||
@@ -100,6 +100,8 @@ function commentLine(bp, lineN)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function uncommentLine(bp, lineN, commentRegex)
|
function uncommentLine(bp, lineN, commentRegex)
|
||||||
|
updateCommentType(bp.Buf)
|
||||||
|
|
||||||
local line = bp.Buf:Line(lineN)
|
local line = bp.Buf:Line(lineN)
|
||||||
local commentType = bp.Buf.Settings["commenttype"]
|
local commentType = bp.Buf.Settings["commenttype"]
|
||||||
local sel = -bp.Cursor.CurSelection
|
local sel = -bp.Cursor.CurSelection
|
||||||
@@ -149,6 +151,8 @@ function toggleCommentSelection(bp, startLine, endLine, commentRegex)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function comment(bp, args)
|
function comment(bp, args)
|
||||||
|
updateCommentType(bp.Buf)
|
||||||
|
|
||||||
local commentType = bp.Buf.Settings["commenttype"]
|
local commentType = bp.Buf.Settings["commenttype"]
|
||||||
local commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)"):gsub("%s+", "%s*")
|
local commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)"):gsub("%s+", "%s*")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user