mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-06 07:00:24 +09:00
Restore the original meaning of LastVisualX before commit 6d13710d93
("Implement moving cursor up/down within a wrapped line"): last visual x
location of the cursor in a logical line in the buffer, not in a visual
line on the screen (in other words, taking tabs and wide characters into
account, but not taking softwrap into account). And add a separate
LastWrappedVisualX field, similar to LastVisualX but taking softwrap
into account as well.
This allows tracking last x position at the same time for both cases
when we care about softwrap and when we don't care about it. This can be
useful, for example, for implementing cursor up/down movement actions
that always move by logical lines, not by visual lines, even if softwrap
is enabled (in addition to our default CursorUp and CursorDown actions
that move by visual lines).
Also this fixes a minor bug: in InsertTab(), when `tabstospaces` is
enabled and we insert a tab, the amount of inserted spaces depends on
the visual line wrapping (i.e. on the window width), which is probably
not a good idea.
67 lines
1.5 KiB
Lua
67 lines
1.5 KiB
Lua
VERSION = "1.0.0"
|
|
|
|
local micro = import("micro")
|
|
local buffer = import("micro/buffer")
|
|
local config = import("micro/config")
|
|
local humanize = import("humanize")
|
|
|
|
function init()
|
|
micro.SetStatusInfoFn("status.branch")
|
|
micro.SetStatusInfoFn("status.hash")
|
|
micro.SetStatusInfoFn("status.paste")
|
|
micro.SetStatusInfoFn("status.vcol")
|
|
micro.SetStatusInfoFn("status.lines")
|
|
micro.SetStatusInfoFn("status.bytes")
|
|
micro.SetStatusInfoFn("status.size")
|
|
config.AddRuntimeFile("status", config.RTHelp, "help/status.md")
|
|
end
|
|
|
|
function lines(b)
|
|
return tostring(b:LinesNum())
|
|
end
|
|
|
|
function vcol(b)
|
|
return tostring(b:GetActiveCursor():GetVisualX(false))
|
|
end
|
|
|
|
function bytes(b)
|
|
return tostring(b:Size())
|
|
end
|
|
|
|
function size(b)
|
|
return humanize.Bytes(b:Size())
|
|
end
|
|
|
|
function branch(b)
|
|
if b.Type.Kind ~= buffer.BTInfo then
|
|
local shell = import("micro/shell")
|
|
local strings = import("strings")
|
|
|
|
local branch, err = shell.ExecCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
|
|
if err == nil then
|
|
return strings.TrimSpace(branch)
|
|
end
|
|
return ""
|
|
end
|
|
end
|
|
|
|
function hash(b)
|
|
if b.Type.Kind ~= 5 then
|
|
local shell = import("micro/shell")
|
|
local strings = import("strings")
|
|
|
|
local hash, err = shell.ExecCommand("git", "rev-parse", "--short", "HEAD")
|
|
if err == nil then
|
|
return strings.TrimSpace(hash)
|
|
end
|
|
return ""
|
|
end
|
|
end
|
|
|
|
function paste(b)
|
|
if config.GetGlobalOption("paste") then
|
|
return "PASTE "
|
|
end
|
|
return ""
|
|
end
|