brennier / quicktex

A vim plugin for writing Latex quickly.
http://brennier.com/projects
MIT License
116 stars 17 forks source link

Inline CSS / JS Support #10

Closed Jab2870 closed 6 years ago

Jab2870 commented 7 years ago

Hi, I know that this plugin was originally intended to be used for latex but I also use it (a lot) for web development languages, HTML, CSS and JavaScript.

Would it be possible to make it use CSS shortcuts when inside style tags and JS shortcuts when inside Script tags?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        test{
             <CSS Shortcuts should work here>
        }
    </style>
    <script type="text/javascript">
        <javssscript shortcuts should work here>
    </script>
</head>
<body>

</body>
</html>
brennier commented 7 years ago

Okay, I've created a new git branch called modes for implementing this functionality. It should be working already, though it's experimental for the time being. To create the "modes" that you want, you can simply add the following lines to your .vimrc

let g:quicktex_modes = [
    \['js', ['<script'], ['<\script>']]
    \['css', ['<style>'], ['<\style>']]
\]

The syntax for an entry in g:quicktex_modes is [NameOfDictionary, ListOfStartingDelimiters, ListOfEndingDelimiters]. This way, you can set the dictionaries g:quicktex_js and g:quicktex_css and you should have the functionality that you wish.

However, as this is an experimental feature at the moment, the syntax for this might change in the future. If that happens, I will put a note of it in the readme/documentation.

Jab2870 commented 7 years ago

That is very helpful. Thank you. Will this now work in any file type? I think it would be useful to be able to specify that these delimiters should only work in HTML mode. Just a suggestion.

I originally suggested this for html but I can see it also being useful for markdown code snippet. I might add something like the following:

let g:quicktex_modes = [
    \['js', ['```js'], ['```']]
    \['css', ['```css'], ['```']]
\]
brennier commented 7 years ago

Yes, I think this could have a lot of potential. Though, it could mean having to rebrand the plugin to make it more general, which would be a pain. I'm actually surprised how fast it still is, though.

In any case, I've just sent a commit to make the modes filetype-specific. The format of g:quicktex_modes should now be [FileType, NameOfDictionary, ListOfStartingDelimiters, ListOfEndingDelimiters]. Also, I'm not sure if I mentioned this, but the order of the entries matters: earlier entries have priority over latter entries.