Replies: 2 comments 1 reply
-
I'm not aware of any Python plugins. I guess it would be as simple as checking if the file type is Python and previous character is |
Beta Was this translation helpful? Give feedback.
-
This is what I came up with: local buffer = import("micro/buffer")
local util = import("micro/util")
local colonIndentable = {
python = true,
yaml = true,
nim = true,
}
local shouldIndent = false
function runeBeforeCursor(buf)
local cursor = buf:GetActiveCursor()
if cursor.Loc.X == 0 then return "\n" end
local locBefore = buffer.Loc(cursor.Loc.X - 1, cursor.Loc.Y)
return util.RuneStr(buf:RuneAt(locBefore))
end
function preInsertNewline(bp)
shouldIndent = colonIndentable[bp.Buf:FileType()] and runeBeforeCursor(bp.Buf) == ":"
end
function onInsertNewline(bp)
if shouldIndent then bp:IndentLine() end
shouldIndent = false
end I also started to implement auto-outdenting when typing eg. "else:", but quickly realized that it would be impossible to handle in a consistent way that is not confusing to users – so I figured it's probably best to leave outdenting to the user. |
Beta Was this translation helpful? Give feedback.
-
The auto-indent works pretty well enough already. Ig I've just grown soft and lazy and accustomed to VSCode and IDLE spoonfeeding me my python-specific auto-indents for functions and loops etc. But it would be nice and seems like it shouldn't be too complicated to extend the python syntax file, has anyone done this already?
Beta Was this translation helpful? Give feedback.
All reactions