From f661199197cc1346124b0b12e77f25150c50a776 Mon Sep 17 00:00:00 2001 From: Ashkan Kiani Date: Fri, 18 Oct 2019 09:56:49 -0700 Subject: Allow excluding files from highlight with '*' (#11) Fixes GH-5 --- README.md | 11 +++++++++-- doc/colorizer-lua.txt | 9 ++++++++- lua/colorizer.lua | 14 +++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2cb28b3..cf25c87 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ require 'colorizer'.setup { 'css'; 'javascript'; html = { - mode = 'foreground'; + mode = 'foreground'; } } @@ -83,7 +83,14 @@ require 'colorizer'.setup({ require 'colorizer'.setup { '*'; -- Highlight all files, but customize some others. css = { rgb_fn = true; }; -- Enable parsing rgb(...) functions in css. - html = { no_names = true; } -- Disable parsing "names" like Blue or Gray + html = { names = false; } -- Disable parsing "names" like Blue or Gray +} + +-- Exclude some filetypes from highlighting by using `!` +require 'colorizer'.setup { + '*'; -- Highlight all files, but customize some others. + '!vim'; -- Exclude vim from highlighting. + -- Exclusion Only makes sense if '*' is specified! } ``` diff --git a/doc/colorizer-lua.txt b/doc/colorizer-lua.txt index 2d27d27..9f2afda 100644 --- a/doc/colorizer-lua.txt +++ b/doc/colorizer-lua.txt @@ -91,7 +91,7 @@ PARAMETERS: 'css'; 'javascript'; html = { - mode = 'foreground'; + mode = 'foreground'; } } @@ -112,6 +112,13 @@ PARAMETERS: css = { rgb_fn = true; }; -- Enable parsing rgb(...) functions in css. html = { names = false; } -- Disable parsing "names" like Blue or Gray } + + -- Exclude some filetypes from highlighting by using `!` + require 'colorizer'.setup { + '*'; -- Highlight all files, but customize some others. + '!vim'; -- Exclude vim from highlighting. + -- Exclusion Only makes sense if '*' is specified! + } < |colorizer.highlight_buffer| *colorizer.highlight_buffer* diff --git a/lua/colorizer.lua b/lua/colorizer.lua index b869897..32717e5 100644 --- a/lua/colorizer.lua +++ b/lua/colorizer.lua @@ -292,6 +292,9 @@ local function setup(filetypes, default_options) default_options = SETUP_SETTINGS.default_options function COLORIZER_SETUP_HOOK() local filetype = nvim.bo.filetype + if SETUP_SETTINGS.exclusions[filetype] then + return + end local options = FILETYPE_OPTIONS[filetype] or SETUP_SETTINGS.default_options attach_to_buffer(nvim_get_current_buf(), options) end @@ -315,9 +318,14 @@ local function setup(filetypes, default_options) else filetype = v end - FILETYPE_OPTIONS[filetype] = options - -- TODO What's the right mode for this? BufEnter? - nvim.ex.autocmd("FileType", filetype, "lua COLORIZER_SETUP_HOOK()") + -- Exclude + if filetype:sub(1,1) == '!' then + SETUP_SETTINGS.exclusions[filetype:sub(2)] = true + else + FILETYPE_OPTIONS[filetype] = options + -- TODO What's the right mode for this? BufEnter? + nvim.ex.autocmd("FileType", filetype, "lua COLORIZER_SETUP_HOOK()") + end end end nvim.ex.augroup("END") -- cgit v1.2.3-70-g09d2