Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lexers #1133

Merged
merged 5 commits into from
Mar 27, 2024
Merged

Update lexers #1133

merged 5 commits into from
Mar 27, 2024

Conversation

rnpnr
Copy link
Collaborator

@rnpnr rnpnr commented Sep 22, 2023

This should be just about ready to merge now. One thing I'm still not
sure about is the modifying of the default styles. I don't think it is
necessary to bloat up the lexers table with all the possible style tags
but there should still be some way of indicating to users how they can
add styles for missing tags. Let me know if someone has a better idea
than just copying from upstream and leaving them commented out.

As indicated by the commit authors this contains the work of a few
different people whom I pass on my thanks!

@rnpnr rnpnr mentioned this pull request Sep 23, 2023
8 tasks
@mcepl
Copy link
Contributor

mcepl commented Sep 25, 2023

Very hesitant +1 from me. Shouldn’t we first make some vivisection like what I suggested in https://paste.sr.ht/~mcepl/ef4aba41df3c516bc6a96ed1ee9643fed78e01d0 (and orbitalquark/scintillua#99 (comment)) so that at least we have something half-functional?

@rnpnr
Copy link
Collaborator Author

rnpnr commented Sep 25, 2023

So right now any styles added with lex:add_style will not get
added. This applies to the following (excluding lexer.lua):

# grep 'add_style' lua/lexers/* | cut -d ':' -f 1 | uniq
antlr.lua
clojure.lua
crystal.lua
gleam.lua
icon.lua
jq.lua
julia.lua
lexer.lua
mediawiki.lua
meson.lua
moonscript.lua
rest.lua
txt2tags.lua

Which out of ~150 lexers isn't bad. You can still get styling for all
of these by adding extra entries to your theme. For example:

vis/lua/themes/dark-16.lua

Lines 132 to 144 in d37a20c

-- reST
lexers.STYLE_LITERAL_BLOCK = lexers.STYLE_EMBEDDED
lexers.STYLE_FOOTNOTE_BLOCK = lexers.STYLE_LABEL
lexers.STYLE_CITATION_BLOCK = lexers.STYLE_LABEL
lexers.STYLE_LINK_BLOCK = lexers.STYLE_LABEL
lexers.STYLE_CODE_BLOCK = lexers.STYLE_EMBEDDED
lexers.STYLE_DIRECTIVE = lexers.STYLE_KEYWORD
lexers.STYLE_SPHINX_DIRECTIVE = lexers.STYLE_KEYWORD
lexers.STYLE_UNKNOWN_DIRECTIVE = lexers.STYLE_KEYWORD
lexers.STYLE_SUBSTITUTION = lexers.STYLE_VARIABLE
lexers.STYLE_INLINE_LITERAL = lexers.STYLE_EMBEDDED
lexers.STYLE_ROLE = lexers.STYLE_CLASS
lexers.STYLE_INTERPRETED = lexers.STYLE_STRING

So I don't really think this is half functional as you say.

@mcepl
Copy link
Contributor

mcepl commented Sep 25, 2023

Yes, “half functional” is too harsh, but what I meant is that current state of that branch is a regression against the previous released version.

@rnpnr rnpnr force-pushed the update-lexers branch 2 times, most recently from cbea2a9 to b753520 Compare October 23, 2023 03:58
@TwoF1nger
Copy link

@rnpnr I think there's a redrawtime leftover in the man page.

lexers.STYLE_TARGET = ''

-- Markdown
lexers.STYLE_HR = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The markdown theming example is missing:

  • STYLE_BOLD
  • STYLE_ITALIC
  • STYLE_LIST
  • STYLE_LINK
  • STYLE_REFERENCE
  • STYLE_HEADING_H1 - STYLE_HEADING_H6

Here is what I use in my theme:

lexers.STYLE_BOLD = 'fore:default,back:default,bold'
lexers.STYLE_ITALIC = 'fore:default,back:default,italics'
lexers.STYLE_LIST = lexers.STYLE_KEYWORD
lexers.STYLE_LINK = lexers.STYLE_KEYWORD
lexers.STYLE_REFERENCE = lexers.STYLE_KEYWORD
lexers.STYLE_HR = 'fore:red'
for i=1, 6 do lexers['STYLE_HEADING_H'..i] = 'fore:red' end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The STYLE_HEADING_H? are already in the txt2tags example but I can add your line to both. As for the others I missed them since they were defined elsewhere in the scintillua themes. They are also used in a couple other lexers so it might be useful to just define them by default.

By the way stuff like:

lexers.STYLE_BOLD = 'fore:default,back:default,bold'

is equivalent to:

lexers.STYLE_BOLD = 'bold'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops the txt2tags is STYLE_H? (which from what I see in the lexer is never actually used). Either way both can be replaced by the for loop.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops the txt2tags is STYLE_H? (which from what I see in the lexer is never actually used). Either way both can be replaced by the for loop.

It is actually used at:

return token('h' .. level, equal + plus) * header_label^-1

I have not confirmed it but looking at the code the tokens h1 up to h6 are defined.

@rnpnr
Copy link
Collaborator Author

rnpnr commented Oct 25, 2023

@rnpnr I think there's a redrawtime leftover in the man page.

Good catch, I will fix it.

@rnpnr
Copy link
Collaborator Author

rnpnr commented Oct 25, 2023

Do people think that the commented out examples should just be enabled by default? It would result in some small amount of extra runtime memory usage but should make it so this patchset doesn't remove the working existing styles.

@fischerling
Copy link
Contributor

Do people think that the commented out examples should just be enabled by default? It would result in some small amount of extra runtime memory usage but should make it so this patchset doesn't remove the working existing styles.

I don't really care, because I use my own theme definitions.
But I think that people would definitely expect proper syntax highlighting (highlighting all tokens) for all supported file types out of the box.

@mcepl
Copy link
Contributor

mcepl commented Oct 25, 2023

But I think that people would definitely expect proper syntax highlighting (highlighting all tokens) for all supported file types out of the box.

That +1 was for this, not for the first sentence.

@rnpnr
Copy link
Collaborator Author

rnpnr commented Oct 25, 2023

Sounds good to me. In that case here is an idea: combine light-16.lua and dark-16.lua into a single file and replace all fore:white,back:black etc. with empty declarations to just use the default terminal foreground and background. This is what I do in my term.lua theme so that I can have a light or dark background depending on the time of day. This should also address some of the complaints about the default style not matching the terminal.

As for the zenburn.lua and solarized.lua I don't know much about them. So I can either try to reuse styles, as in lexers.STYLE_H1 = lexers.STYLE_HEADING, or just leave it for someone else to fix.

@mcepl
Copy link
Contributor

mcepl commented Oct 26, 2023

Sounds a like a sound plan ;).

@mcepl
Copy link
Contributor

mcepl commented Nov 2, 2023

You made a huge amount of work with reviving those themes. Respect and thank you!

Applied to my devel branch and after five minutes testing it seems to work almost perfectly.

We should also collect what changes (if any) we want to push upstream and somehow resolve orbitalquark/scintillua#99.

@rnpnr
Copy link
Collaborator Author

rnpnr commented Nov 2, 2023

We should also collect what changes (if any) we want to push upstream

Actually everything here is upstream besides your change to search in the correct path.

and somehow resolve orbitalquark/scintillua#99.

Unfortunately I don't have any knowledge of reST so I don't know which add_styles() can be dropped and which need to stay. Some can probably be changed to the styles added for the other markup languages.

Sounds a like a sound plan ;).

I'm still working on this btw. There are some bugs in the logic for applying themes which is probably why no one else has attempted to merge the styles. Work in progress is in my selstyle branch. If I can figure it out I will apply it to master and then update this patch set accordingly.

@rnpnr
Copy link
Collaborator Author

rnpnr commented Dec 5, 2023

I think I'm going to cherry-pick the following commits into master:
lua: drop redrawtime option
lua: filetype: use alt_name field to alias to other lexers
These are strictly bugfixes and shouldn't be contentious.

@mcepl
Copy link
Contributor

mcepl commented Dec 5, 2023 via email

mcepl and others added 5 commits March 27, 2024 06:04
Rather than cherry pick patches from after 6.2 we will just grab
everything as is.
Based on the advice from the upstream maintainer of Scintillua
(gh#orbitalquark/scintillua#87).
vis{,-std}.lua:
	* replace removed _TOKENSTYLES with _TAGS
	* don't add default styles to the lexer. lexers no longer
	  define their own styles

filetype.lua: update path detection for scintillua 6.2
Caching lexers causes lexer tables to be constructed once and
reused during each HIGHLIGHT event. Additionally it allows to
modify the lexer used for syntax highlighting from Lua code.

This is used for example for the syntax aware spellchecking
performed by the vis-spellcheck plugin.
This also involves modifying the style definitions so that they
include sub tags as well. For example command.section in latex
should be mapped to COMMAND_SECTION.
@rnpnr rnpnr merged commit 6f537f3 into martanne:master Mar 27, 2024
24 checks passed
@rnpnr rnpnr deleted the update-lexers branch March 27, 2024 12:06
@mcepl
Copy link
Contributor

mcepl commented Mar 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants