vim-css-color
vim-css-color copied to clipboard
LESS support
Since Bootstrap is based on LESS, I would find vim-css-color much more useful if it highlighted all of the colour references in .less files. There are two situations in which vim-css-color doesn't work for .less files:
-
When declaring global colour variables:
@white: #111
-
When referring to a colour variable:
div {background-color: @white;}
It will be important to look outside the current file, in other imported .less files, if the variable declaration isn't found in the current file.
It would be great if vim-css-color also respected LESS colour functions like spin(), lighten(), and darken(). But that would likely be a bit more complicated, so maybe at a separate stage. To begin with, it would be nice just to have the colour variable within the function highlighted:
div {background-color: darken(@white, 20%)
Thanks
This is far more complex to implement than the current way the plugin works. It may or may not even be possible.
(And the “a bit more complicated” part is at least as much more complicated than simple variables than the variable support is over its current implementation – it requires implementing LESS In Vimscript.)
Have you seen some other Vim plugin which already does any or all this?
No, I haven't seen a plugin that does this, but I'm not sure it would be too difficult if at least part were written in Python (I haven't looked at your plugin source). Since the import chain of LESS files is always at the top of the document, it would just involve:
- collecting all of the the @ variables in the current document
- getting the imported file paths from the @import statements
- opening those files (in the background) and searching for a place where the @ variable is followed by a colour code
- if you don't find a colour assigned to the variable, do nothing with it (some of them won't be colours, but other things like dimensions).
This could be done once at the time a document is opened, so it wouldn't have to affect speed too much. You could also make it cross-platform fairly easily if you use the Python os module. I suppose you could also run it as a background process (using the subprocess module) so that it wouldn't block the foreground operations of Vim even when the file is opened.
Or is there some complication that I'm missing? This assumes, of course, that you know Python.
Ian
On Fri, Jun 14, 2013 at 5:58 PM, Aristotle Pagaltzis < [email protected]> wrote:
This is far more complex to implement than the current way the plugin works. It may or may not even be possible.
Have you seen some other Vim plugin which already does this?
— Reply to this email directly or view it on GitHubhttps://github.com/skammer/vim-css-color/issues/15#issuecomment-19483949 .
Ian W. Scott, PhD (McMaster RS) Associate Professor of New Testament Tyndale Seminary Toronto, Ontario, Canada http://www.ian-w-scott.com
Paul's Way of Knowing: Story, Experience and the Spirit (WUNT II/205; Tübingen: Mohr Siebeck, 2006/Grand Rapids: Baker Academic, 2008).*
The Online Critical Pseudepigrapha* (Atlanta: Society of Biblical Literature, 2006-). Online: http://www.purl.org/net/ocp.
Or is there some complication that I'm missing? This assumes, of course, that you know Python.
I know this is old, but seriously, wtf. It annoys me to no end when people suggest something is so simple at the same time as admitting they have not looked through the source code or don't even freaken understand how vim or a vim plugin works (Python? Really?).
If it's so simple, how about actually submitting a PR.
I'm sorry @JonDum that my suggestion bothered you. The reason I haven't done it myself is that (like you, I'm sure) I'm extremely busy and have to think twice before taking something on. My suggestions were responding to your suggestion that LESS support like this might be impossible. So I was offering a bit of help to think through how it might be done. But I have no illusions that executing it would be a quick job. Simple and fast are very different things. As for my reference to Python, I'm not sure why you find that odd. For many tasks Python runs faster than vimscript and it is an officially supported language for writing plugins. You are free to dislike the language, but I don't think there's any need to put down the language or those who use it in vim.
You're right that in a perfect world I could write the patch and submit a pull request. But we all use many more vim plugins and other free software tools than we can contribute to. If the wording of my suggestion implied to you that I was impatient or sarcastic then I do apologize. It was just meant to be a friendly contribution which you could take or leave. Thanks for all your work on this plugin, which continues to make my life a bit easier on a daily basis.
I understand you are busy, we all are. Ideas are cheap, implementing them is not.
You are misreading my comment about Python. My qualm with you bringing up python is because python has nothing to do with this project, not because Python is in any way a bad language. It's like saying, "this would be so easy if you could just use x, even though this project uses y and has nothing to do with x, so just rewrite the whole thing in x already while I sit here and complain."
Also, AP is the one you should be thanking, not me.
Thanks for the clarification @JonDum. For the record, it's not uncommon to have hybrid vim plugins that mix vimscript and Python. Again, I wasn't "sitting here and complaining." I wasn't complaining at all, and if it sounded like I was then that was my mistake in wording. I was merely trying to demonstrate to AP that it wasn't as impossibly complex as it sounded, since he seemed unsure how one would even go about it. If this kind of suggestion isn't welcome in an issues page (as a feature request) then I've misconstrued their purpose. On the other hand, I'm not sure that these pages are the place for ad hominem attacks against other posters. This is now just cluttering up the issue.
It’s far from impossible but it’s a much bigger job than what the plugin does currently. Right now, all it does is scan the current line for potential CSS colours, then add rules to Vim’s highlight engine for any colours it finds. That’s it. Written in pure VimL.
And just doing that already takes work to make performant (c.f. all the work I put into my fork).
Properly supporting LESS is basically a separate plugin just in terms of the amount of code, and I have no guess as to whether it can be made fast enough. (You have to parse multiple entire files on every single keystroke, or at least come to close to being able to, to cover the worst case.)