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

Add sass variable matcher. #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add sass variable matcher. #22

wants to merge 2 commits into from

Conversation

norcalli
Copy link
Owner

@norcalli norcalli commented Oct 23, 2019

Usage will be in two parts:

  1. Setting your setup file:
require'colorizer'.setup {
  '*';
  scss = { custom_matcher = require'colorizer/sass'.variable_matcher };
}
  1. 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.

Usage will be in two parts:

1. Setting your setup file:
```
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
Copy link
Owner Author

norcalli commented Oct 23, 2019

@norcalli
Copy link
Owner Author

norcalli commented Oct 23, 2019

TODO:

  • Add documentation
  • Decide on organization hierarchy (use colorizer/deps instead for other files?)
  • Decide on variables to export and consider refactoring matcher vs parser terminology.
  • Change the VALUE_PARSER to a buffer specific parser in case they customize their options?

@norcalli
Copy link
Owner Author

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

colorizer.attach_to_buffer(bufnr)
end
end
-- TODO can this get out of sync with highlighting order if it updates the database
Copy link
Owner Author

Choose a reason for hiding this comment

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

delete comment

local length, rgb_hex = VALUE_PARSER(variable_value, j)
if length then
variable_definitions_changed = true
print("parsed variable value", variable_name, length, rgb_hex)
Copy link
Owner Author

Choose a reason for hiding this comment

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

delete prints

@alxndr
Copy link

alxndr commented Oct 23, 2019

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
Copy link
Owner Author

@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
Copy link

alxndr commented Oct 23, 2019

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
Copy link
Owner Author

@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
Copy link

alxndr commented Oct 24, 2019

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
Copy link
Owner Author

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

@alxndr
Copy link

alxndr commented Oct 25, 2019

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()

alxndr added a commit to alxndr/dotfiles that referenced this pull request Oct 25, 2019
@norcalli
Copy link
Owner Author

norcalli commented Nov 8, 2019

@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
Copy link

alxndr commented Nov 8, 2019

@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

  • I'd love to be able to use this with notermguicolors to fit in with my current theme.
  • Support for opaque colors using rgba() would be great... (I don't have any bright ideas about how to represent the opacity)

Screen Shot 2019-11-08 at 9 26 43

@ghost
Copy link

ghost commented Oct 30, 2020

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

@Akianonymus
Copy link

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

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.

3 participants