norcalli / nvim-colorizer.lua

The fastest Neovim colorizer.
Other
2.25k stars 117 forks source link

Add sass variable matcher. #22

Open norcalli opened 4 years ago

norcalli commented 4 years ago

Usage will be in two parts:

  1. Setting your setup file:

    require'colorizer'.setup {
    '*';
    scss = { custom_matcher = require'colorizer/sass'.variable_matcher };
    }
  2. Attaching to a buffer to trigger updating the dictionary.

autocmd FileType scss lua require'colorizer/sass'.attach_to_buffer()

Demo https://github.com/norcalli/github-assets/raw/master/colorizer-demo-sass.gif

https://github.com/norcalli/github-assets/raw/master/colorizer-demo-sass.mp4

Only the buffers which have been attached will be considered for variable definitions.

norcalli commented 4 years ago

As suggested by https://www.reddit.com/r/neovim/comments/djfpke/nvimcolorizerlua_fast_colorizer_with_no_external/f4rjt77/

norcalli commented 4 years ago

TODO:

norcalli commented 4 years ago

For the record, based on the reddit comment timestamps, it took me only an hour to implement :P

alxndr commented 4 years ago

Ass [sic] suggested by https://www.reddit.com/r/neovim/comments/djfpke/nvimcolorizerlua_fast_colorizer_with_no_external/f4rjt77/

Thanks @norcalli !

I'm guessing that the autocmd can go in my .vimrc, but I'm unsure what to do with the setup file step.

norcalli commented 4 years ago

@alxndr It depends on how you were doing your setup already. Here's an example:

lua << EOF
require 'colorizer'.setup {
  '*';
  scss = { custom_matcher = require'colorizer/sass'.variable_matcher };
}
EOF
alxndr commented 4 years ago

It depends on how you were doing your setup already.

I'm using vim-plug, and I've set termguicolors, added these lines to my init.vim, and then :so % | PlugInstall...

Plug 'norcalli/nvim-colorizer.lua', {'do': ':lua require''colorizer''.setup()'}
autocmd FileType scss lua require'colorizer/sass'.attach_to_buffer()

I haven't yet used Lua with Neovim so I'm unfamiliar with what else might be involved in setting up a plugin that uses it.

norcalli commented 4 years ago

@alxndr Putting it in the do block is not correct here. It'll only run once when you install it. You should put it after the plug#end() statement in your vimrc so it's sourced every time.

alxndr commented 4 years ago

Okay, thanks. So I've got the Plug line, then I've done PlugInstall, and then added to my init.vim:

set termguicolors
lua require'colorizer'.setup()
autocmd FileType scss lua require'colorizer/sass'.attach_to_buffer()
lua << EOF
require 'colorizer'.setup {
  '*';
  scss = { custom_matcher = require'colorizer/sass'.variable_matcher };
}
EOF

However when I start up Neovim I see this error at the top of a long stack trace (?):

Error detected while processing /Users/x/.config/nvim/init.vim:
line  206:
E5105: Error while calling lua chunk: [string "<VimL compiled string>"]:3: module 'colorizer/sass' not found:
        no field package.preload['colorizer/sass']
        no file '/Users/x/.config/nvim/lua/colorizer/sass.lua'
        no file '/Users/x/.config/nvim/lua/colorizer/sass/init.lua'
        [...many more "no file" lines listing files in other plugins I have installed...]

(Line 206 is the last line of the snippet I shared above, with just EOF on the line.)

Thanks for looking into this!

norcalli commented 4 years ago

@alxndr You're going to want to use Plug 'norcalli/nvim-colorizer.lua', { 'branch': 'sass-variable-matcher' } for the correct branch.

alxndr commented 4 years ago

Aha, thank you! Here's the bare-bones init file I used to get this working:

set termguicolors
call plug#begin("~/.config/nvim/plugged")
  Plug 'norcalli/nvim-colorizer.lua', { 'branch': 'sass-variable-matcher' }
call plug#end()
lua << EOF
require'colorizer'.setup({
  '*';
  'lua';
  scss = { custom_matcher = require'colorizer/sass'.variable_matcher };
  css = { css = true; };
}, { mode = 'background'; })
EOF
autocmd FileType scss lua require'colorizer/sass'.attach_to_buffer()
norcalli commented 4 years ago

@alxndr have you been using this branch? I'm interested in trying to get it merged and I want to hear any feedback first.

alxndr commented 4 years ago

@alxndr have you been using this branch? I'm interested in trying to get it merged and I want to hear any feedback first.

I've been using it on and off, and it's very nice!

Minor bug? I'm using this to open a floating window with a terminal; between when I exit that terminal and when the floating window closes, this error appears in the status bar: Error executing lua callback: ...onfig/nvim/plugged/nvim-colorizer.lua//lua/colorizer.lua:523: Index out of bounds

General feedback

Screen Shot 2019-11-08 at 9 26 43
ghost commented 3 years ago

Looks amazing! Any chance of getting it merged at some point? Thanks for great plugin @norcalli!

Akianonymus commented 1 year ago

I have implemented sass support in my repo, loosely based on this pr. Along with support for imports, recursive imports and variables.

https://github.com/NvChad/nvim-colorizer.lua