Skip to content

no syntax highlighting option - #1390

Open
Nomarian wants to merge 1 commit into
martanne:masterfrom
Nomarian:nocolor
Open

no syntax highlighting option#1390
Nomarian wants to merge 1 commit into
martanne:masterfrom
Nomarian:nocolor

Conversation

@Nomarian

@Nomarian Nomarian commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Changes:

Environmental Variables:
Identifies $NO_COLOR and $VIS_NOCOLOR

Adds set syntax_highlight BOOLEAN

Changes functionality of syntax option

set syntax on -- sets syntax on of the window
set syntax off -- sets syntax off of the window
set syntax X -- changes syntax of current window to X

FILE_SAVE_POST only triggers once

@Nomarian Nomarian mentioned this pull request Aug 18, 2026
@Nomarian
Nomarian force-pushed the nocolor branch 6 times, most recently from 3acf821 to d6d0881 Compare August 19, 2026 20:30
@Nomarian
Nomarian marked this pull request as ready for review August 19, 2026 20:35
@Nomarian
Nomarian force-pushed the nocolor branch 4 times, most recently from 9f37b8d to 9017ce1 Compare August 20, 2026 00:36
@Nomarian

Copy link
Copy Markdown
Contributor Author

This also adds the feature of #1311

@Nomarian
Nomarian force-pushed the nocolor branch 3 times, most recently from f119662 to 7ac5f36 Compare August 24, 2026 15:50
@Nomarian

Copy link
Copy Markdown
Contributor Author

@rnpnr This is ready for merging, functionality didn't change either so nothing should break... I hope

@rnpnr rnpnr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi thank you for working on this! Overall I think the idea is sound but there are few things that should be changed.

Also can you address the case of the user manually specifying a syntax and then that getting overwritten in FILE_SAVE_POST. Basically if the user ever enters :set syntax off (doesn't have to be off), FILE_SAVE_POST should not set the syntax again.

PS: sorry to be a little bit more nitpicky about style then usual but I don't anything near the horrendous style I have to look at every day at work making its way into vis.

Comment thread lua/plugins/filetype.lua

return 'text'
return M.default_syntax
end M.Detect = Detect

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't really get the point of this over M.Detect = function(...) ... end. Is there a reason?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So when localizing variables, the linter I use (luacheck) picks it up in the file, so if I make a typo like DEtect(), it will warn me there is no such thing as DEtect(), but it wont pick up typos inside tables like M.DEtect, probably because tables could be a metatable so they could return anything.

This has a drawback, both a bug and also a feature depending on how you see it, if anybody decides to replace vis.ftdetect.Detect = theirfunction then all the other functions that use localized Detect will still use it and not the other version.

it also saves a GETTABLE call which is... honestly just a non noticeable 1 ns speedup.

Comment thread lua/vis-std.lua Outdated
return false

-- syntax_highlight is on by default, unless $NO_COLOR is set
vis.options.SYNTAX_HIGHLIGHT = not(os.getenv"NO_COLOR" or os.getenv"VIS_NOCOLOR")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please just set the default to true. I don't want any more vis or platform specific environment variable usage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, no VIS_NOCOLOR, I do think supporting NO_COLOR is good, for the colorblind at least, but I'm not colorblind, and I never disable syntax highlighting anyway.

It's also a good workaround for now for the lexer recursivity limit, so vis doesn't crash.

Comment thread lua/vis-std.lua
Comment on lines +60 to +61
-- NOTE: .options.SYNTAX_HIGHLIGHT is used as the real option because modifying
-- .options.syntax_highlight leads to a C stack overflow, possible BUG?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This needs to be investigated before this can be merged. We don't want extra and inconsistent public API just to workaround an unexplored issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

its not just vis.options but win.options as well, win.options doesn't even exist sometimes.

Comment thread lua/plugins/filetype.lua
Comment on lines +423 to +427
local FindSyntax
= function --> syntax: string --
(
win -- vis.win|nil
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is really ugly and difficult to read. If you need to include these put it in a comment above the function declaration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How should it look? I want it to keep parameter and return type information

-- (win: window|nil): syntax: string
local FindSyntax = function(win)

I should probably switch to ldoc, but I'll have to read the docs.

vis-std.lua:
	set syntax_highlight option.
	set syntax is now per window and overrides global syntax_highlight option
	statusbar:
		added win.SYNTAX to the statusbar
		Also always displays a file.name if it can, uses file.path or file.name

filetype.lua:
	added M.default_syntax
	Detect() uses file.path or file.name instead of just file.name
	WIN_OPEN takes into account global highlight option
	FILE_SAVE_POST doesn't constantly reset the syntax on each save
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.

2 participants