Replies: 3 comments 2 replies
-
For a single instance, textfilter is very convenient. For one-liners, I recommend Python 'py' command. At least for me, Python is needed often and commands are thus easy to remember. I rarely use perl outside one-liners, and now 'py' can do that in Python, too. My plugin palettero has case change with Python, but you can easily add perl, too. Palettero uses
And similar for lower(), upper(), translate to ASCII, urlencode... I would also be curious if it's possible to apply textfilter for each multicursor instance. Currently, textfilter seems to only apply to first selected instance. Maybe this could be a feature for micro itself? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi, Lua has in-built, locale specific, functions to change the case of strings: sel = string.toupper(sel)
-- and
sel = string.tolower(sel) To use this functionality in Micro you need bindable functions, something like: function toupper(Current)
-- Change case to upper
if editor.HasSelection(Current) then
local sel = editor.GetSelection(Current)
sel = string.upper(sel)
editor.Insert(Current,sel)
end
end
function tolower(Current)
-- Change case to lower
if editor.HasSelection(Current) then
local sel = editor.GetSelection(Current)
sel = string.lower(sel)
editor.Insert(Current,sel)
end
end
These functions can be placed in your -- Import Go libraries
local micro = import("micro")
local util = import("micro/util")
local buffer = import("micro/buffer")
-- Set up editor table and define functions
editor = {}
function editor.HasSelection(Current)
return Current.Cursor:HasSelection()
end
function editor.GetSelection(Current)
return util.String(Current.Cursor:GetSelection()) or nil
end
function editor.Insert(Current,item)
-- TODO: Does not work at every cursor
if type(item)=="string" then
Current.Cursor:DeleteSelection()
Current.Buf:Insert(editor.GetTextLoc(Current), item)
end
end
-- Add bindable functions below Hope this is useful. Kind Regards Gavin Holt |
Beta Was this translation helpful? Give feedback.
-
Is there a command or a shortcut to switch cases for each selection (single or multicursor)?
If not, which
micro
Lua API to use to make an extension with such feature?I can also probably try using
textfilter perl
for that.Beta Was this translation helpful? Give feedback.
All reactions