Feature request: Relative line numbers
Hi, thanks for developing Textadept :)
I couldn't find any references in the API docs about relative line numbers, so I assume they aren't currently supported.
I am developing a Kakoune mode for Textadept, and relative line numbers would be really useful for doing relative line jumps e.g. 5j. E.g. see this screenshot from my VS Code:
At the moment, neither Textadept nor Scintilla (the editing component Textadept uses) support relative line numbers. The editor supports custom text margins though, so in theory this feature could be emulated. How are wrapped lines handled? Do they have their own line numbers?
There was this in 2017: https://github.com/abaez/textadept-relative
Not sure how much those APIs have changed.
Good find! Textadept now uses 1-based indices (that module uses 0-based indices), but other than that I think it's usable.
Ah, shame it's blocked on Scintilla. I will have a look at that emulated implementation, thanks.
How are wrapped lines handled? Do they have their own line numbers?
In VS Code, wrapped continuation lines don't have their own numbers, and Dance (the Kakoune extension I'm using) treats them all as one single line. So here, 3j will go to the line marked 3, not the continuation of line 2.
Here's a 7 line Lua snippet that does what you want. Note that it does use the text margin, and there is only one available per line, so if you're using that margin for something else you might have to do some hacky string concatenation...
view.margin_type_n[1] = view.MARGIN_RTEXT
events.connect(events.UPDATE_UI, function()
local current_line = buffer:line_from_position(buffer.current_pos)
for i = 1, buffer.line_count do
buffer.margin_text[i] = math.abs(i - current_line)
end
buffer.margin_text[current_line] = current_line
end)
I can't quite figure out how to get margin styling to work for e.g. bolding the current line. I tried e.g.
view.styles[100] = {bold = true}
view:set_styles()
buffer.margin_style[1] = 100
but the style of the line 1 text margin doesn't change. I wonder if there's an event hook that does it programmatically that has to be overridden or something.