aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshkan Kiani <ashkan.k.kiani@gmail.com>2019-10-18 09:56:49 -0700
committerGitHub <noreply@github.com>2019-10-18 09:56:49 -0700
commitf661199197cc1346124b0b12e77f25150c50a776 (patch)
treeec4f9429458b4e13048c1f755e46509434554441
parentUpdate docs and luadocs (diff)
Allow excluding files from highlight with '*' (#11)
Fixes GH-5
-rw-r--r--README.md11
-rw-r--r--doc/colorizer-lua.txt9
-rw-r--r--lua/colorizer.lua14
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")