Use sparkup on other file extensions / types #33

Open
devth opened this Issue Jan 28, 2011 · 15 comments

10 participants

@devth

How would I wire this up to work in other file types, such as .mustache?

@nelas

Same question here. I'm not managing to get it to work on filetype=htmldjango with Vim. Any clues? (on plain html works fine)

@nelas

Ok, copying sparkup.py and sparkup.vim into a new folder ~/.vim/ftplugin/htmldjango worked around the issue. Sorry for the buzz...

@devth

Another thing that worked was to set the filetype for *.mustache to mustache.html
:set filetype=mustache.html

@millermedeiros

to avoid copying files you can create new ftplugin files for each file type like:

" ftplugin/htmldjango.vim
runtime! ftplugin/html/sparkup.vim

or you can add an auto command to your .vimrc file (simpler):

augroup sparkup_types
  " Remove ALL autocommands of the current group.
  autocmd!
  " Add sparkup to new filetypes
  autocmd FileType mustache,php,htmldjango runtime! ftplugin/html/sparkup.vim
augroup END

I would fork the project and add the auto command to the sparkup plugin but I think this plugin was abandoned... (since the author isn't replying to any issue)

@kitmonisit

I tried the lines above but they cause recursive autocmd loops. Here's my solution in .vimrc

au FileType html set ft=htmldjango # sparkup is already loaded here due to the initial html filetype,
                                   # all we need now is the htmldjango (or htmljinja) syntax highlighting
au FileType htmldjango runtime! ftplugin/html/sparkup.vim # load sparkup if vim decides that the file is htmldjango
@millermedeiros

@kitmonisit by using augroup and clearing the group before adding new commands (autocmd!) it is supposed to run the command only once when FileType matches one of the patterns, usually when you open the file or :set filetype=foo... - see: clearing groups

@kitmonisit

@millermedeiros Thanks for the resource! I pull my hair around Vim scripting :P

@rhardih

@millermedeiros Tried pasting your snippet in my .vimrc but it causes an error for me:

Error detected while processing /Users/rene/.vimrc:
line   13:
E216: No such group or event: " Remove ALL autocommands for the current group.
Press ENTER or type command to continue
@millermedeiros

@rhardih try moving the comment to another line and/or deleting it, that might be the problem. (I just updated the snippet)

@rhardih

@millermedeiros Sweet, it was the comment. Works now.

@dwiprabowo

hello, is it solved? sorry but, i have tried to write the code above at my _vimrc file but it didn't work in my *.tmpl file, anyone can help?

@faceleg
Collaborator

Is it possible for someone to create a PR with this behaviour? I think it would be useful for the general populace.

@blueyed

There's an approach in @MarcWeber's fork, where you have a configuration variable to list the filetypes.
https://github.com/MarcWeber/sparkup

#33 (comment) should work.
Another approach is to create a symlink in the sparkup/ftplugin directory (there are a few already; won't work on Windows).

@gkop

I am using this very simple solution to enable sparkup in my jsx files:

autocmd FileType javascript.jsx runtime! ftplugin/html/sparkup.vim
@nathanielks

@gkop this is exactly what I was looking for. thanks mate! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment