Repository navigation
Replies: 4 comments 5 replies
|
There's no need to make it so complicated :) All you have to do is call Lexers like CSS and HTML do this with arbitrary tag names. It's no different than what you want to do. |
|
Oops, I forget to mention this is not from a lexer (I was thinking to say it, but forget). This is for the tree-sitter colorizer I try to finish. It need to map node types to styles. For it to work without any mapping defined, there is a default mapping which try to guess. For that mapping, I need a style for keyword, error, punctuation and default. Punctuation is not the same as operator. Also, I guess people who will use it (if there will be any), will feel the need to define some other style tags. |
|
In 8 is the number of items in I’m just thinking about something to be plugged-in there. |
|
Here is what I came to, which could be inserted in (*) Initially, I inserted it at line 902, but there was an issue with this, it changed the style of WHITESPACE to the one defined for STYLE_LINENUMBER, while WHITESPACE used to be styled like DEFAULT. It is not to be useful for the default lexers. It seems it cannot be done outside of the lexer module. Edit: removed some pedantic check to make it shorter. local function add_additional_tag(name)
assert(name ~= nil)
if lexer._num_styles < 256 and lexer._TAGS[name] == nil then
local key = name:upper():gsub('%.', '_')
local index = #lexer._TAGS + 1
M[key] = name
lexer._TAGS[name] = index
lexer._TAGS[index] = name
lexer._num_styles = lexer._num_styles + 1
end
end
local function add_additional_tags()
add_additional_tag('punctuation')
add_additional_tag('text')
local list = require('additional-style-tags')
for _, name in ipairs(list) do
add_additional_tag(name)
end
end
-- The module `additional-style-tags` may not exist.
pcall(add_additional_tags)Sample return {'this', 'that'} |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I need to add style tags, at least "punctuation". I tried this in
init.lua:No error but no effect
Error about
lexer._TAGSwhich does not exist (so maybe created later)Add it in
lexers/lexer.lualike this at about line 879:No error but no effect
The style is defined in the theme. Whatever I do,
buffer:style_of_name('punctuation')always returns the index for default (33, may vary).All reactions