This commit is contained in:
Zachary Yedidia 2020-07-06 03:14:06 +00:00
commit f1318f28ea
4 changed files with 74 additions and 33 deletions

File diff suppressed because one or more lines are too long

View file

@ -69,10 +69,38 @@ function onBufferOpen(buf)
end end
end end
function isCommented(bp, lineN, commentRegex)
local line = bp.Buf:Line(lineN)
if string.match(line, commentRegex) then
return true
end
return false
end
function commentLine(bp, lineN) function commentLine(bp, lineN)
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 commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)") local sel = -bp.Cursor.CurSelection
local curpos = -bp.Cursor.Loc
local index = string.find(commentType, "%%s") - 1
local commentedLine = commentType:gsub("%%s", trim(line))
bp.Buf:Replace(buffer.Loc(0, lineN), buffer.Loc(#line, lineN), util.GetLeadingWhitespace(line) .. commentedLine)
if bp.Cursor:HasSelection() then
bp.Cursor.CurSelection[1].Y = sel[1].Y
bp.Cursor.CurSelection[2].Y = sel[2].Y
bp.Cursor.CurSelection[1].X = sel[1].X
bp.Cursor.CurSelection[2].X = sel[2].X
else
bp.Cursor.X = curpos.X + index
bp.Cursor.Y = curpos.Y
end
bp.Cursor:Relocate()
bp.Cursor.LastVisualX = bp.Cursor:GetVisualX()
end
function uncommentLine(bp, lineN, commentRegex)
local line = bp.Buf:Line(lineN)
local commentType = bp.Buf.Settings["commenttype"]
local sel = -bp.Cursor.CurSelection local sel = -bp.Cursor.CurSelection
local curpos = -bp.Cursor.Loc local curpos = -bp.Cursor.Loc
local index = string.find(commentType, "%%s") - 1 local index = string.find(commentType, "%%s") - 1
@ -88,46 +116,57 @@ function commentLine(bp, lineN)
bp.Cursor.X = curpos.X - index bp.Cursor.X = curpos.X - index
bp.Cursor.Y = curpos.Y bp.Cursor.Y = curpos.Y
end end
else
local commentedLine = commentType:gsub("%%s", trim(line))
bp.Buf:Replace(buffer.Loc(0, lineN), buffer.Loc(#line, lineN), util.GetLeadingWhitespace(line) .. commentedLine)
if bp.Cursor:HasSelection() then
bp.Cursor.CurSelection[1].Y = sel[1].Y
bp.Cursor.CurSelection[2].Y = sel[2].Y
bp.Cursor.CurSelection[1].X = sel[1].X
bp.Cursor.CurSelection[2].X = sel[2].X
else
bp.Cursor.X = curpos.X + index
bp.Cursor.Y = curpos.Y
end
end end
bp.Cursor:Relocate() bp.Cursor:Relocate()
bp.Cursor.LastVisualX = bp.Cursor:GetVisualX() bp.Cursor.LastVisualX = bp.Cursor:GetVisualX()
end end
function commentSelection(bp, startLine, endLine) function toggleCommentLine(bp, lineN, commentRegex)
if isCommented(bp, lineN, commentRegex) then
uncommentLine(bp, lineN, commentRegex)
else
commentLine(bp, lineN)
end
end
function toggleCommentSelection(bp, startLine, endLine, commentRegex)
local allComments = true
for line = startLine, endLine do for line = startLine, endLine do
commentLine(bp, line) if not isCommented(bp, line, commentRegex) then
allComments = false
break
end
end
for line = startLine, endLine do
if allComments then
uncommentLine(bp, line, commentRegex)
else
commentLine(bp, line)
end
end end
end end
function comment(bp, args) function comment(bp, args)
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*")
if bp.Cursor:HasSelection() then if bp.Cursor:HasSelection() then
if bp.Cursor.CurSelection[1]:GreaterThan(-bp.Cursor.CurSelection[2]) then if bp.Cursor.CurSelection[1]:GreaterThan(-bp.Cursor.CurSelection[2]) then
local endLine = bp.Cursor.CurSelection[1].Y local endLine = bp.Cursor.CurSelection[1].Y
if bp.Cursor.CurSelection[1].X == 0 then if bp.Cursor.CurSelection[1].X == 0 then
endLine = endLine - 1 endLine = endLine - 1
end end
commentSelection(bp, bp.Cursor.CurSelection[2].Y, endLine) toggleCommentSelection(bp, bp.Cursor.CurSelection[2].Y, endLine, commentRegex)
else else
local endLine = bp.Cursor.CurSelection[2].Y local endLine = bp.Cursor.CurSelection[2].Y
if bp.Cursor.CurSelection[2].X == 0 then if bp.Cursor.CurSelection[2].X == 0 then
endLine = endLine - 1 endLine = endLine - 1
end end
commentSelection(bp, bp.Cursor.CurSelection[1].Y, endLine) toggleCommentSelection(bp, bp.Cursor.CurSelection[1].Y, endLine, commentRegex)
end end
else else
commentLine(bp, bp.Cursor.Y) toggleCommentLine(bp, bp.Cursor.Y, commentRegex)
end end
end end

View file

@ -1,32 +1,21 @@
# This script creates the nightly release on Github for micro # This script updates the nightly release on Github for micro
# Must be run from inside the micro git repository # Must be run from inside the micro git repository
commitID=$(git rev-parse --short HEAD) commitID=$(git rev-parse --short HEAD)
# info=$(github-release info -u zyedidia -r micro -t nightly)
# if [[ $info = *$commitID* ]]; then
# echo "No new commits since last nightly"
# exit 1
# fi
go run remove-nightly-assets.go go run remove-nightly-assets.go
# echo "Moving tag"
# hub push origin :refs/tags/nightly
# git tag -f nightly $commitID
# hub push --tags
echo "Cross compiling binaries" echo "Cross compiling binaries"
./cross-compile.sh $1 ./cross-compile.sh $1
mv ../binaries . mv ../binaries .
MESSAGE=$'Nightly build\n\nAutogenerated nightly build of micro' MESSAGE=$'Nightly build\n\nAutogenerated nightly build of micro'
echo "Creating new release" echo "Updating release"
hub release edit nightly \ hub release edit nightly \
--prerelease \ --prerelease \
--draft=false \ --draft=false \
--message "$MESSAGE. Assets uploaded on $(date) for commit $commitID." \ --message "$MESSAGE (please DISREGARD the creation date of this Github release). Assets uploaded on $(date) for commit $commitID." \
--attach "binaries/micro-$1-osx.tar.gz" \ --attach "binaries/micro-$1-osx.tar.gz" \
--attach "binaries/micro-$1-linux64.tar.gz" \ --attach "binaries/micro-$1-linux64.tar.gz" \
--attach "binaries/micro-$1-linux64-static.tar.gz" \ --attach "binaries/micro-$1-linux64-static.tar.gz" \

13
tools/update-nightly-tag.sh Executable file
View file

@ -0,0 +1,13 @@
commitID=$(git rev-parse --short HEAD)
echo "Moving tag"
hub push origin :refs/tags/nightly
git tag -f nightly $commitID
hub push --tags
MESSAGE=$'Nightly build\n\nAutogenerated nightly build of micro'
echo "Creating new release"
hub release create nightly \
--prerelease \
--draft=false \
--message "$MESSAGE."