Drastic proposal: rename eruby to rhtml to make way for an HTML free eruby filetype
Hugh Sasse
hgs at dmu.ac.uk
Fri Mar 9 11:39:20 EST 2007
On Fri, 9 Mar 2007, Tim Pope wrote:
> The subject says it all. The most common use of eruby is filling out
> HTML templates, but this is by no means the only use. I think it
No, see the book "Code Generation in Action" for example.
http://www.codegeneration.net/tiki-index.php?page=GenerationBooks
> would be a good idea to have an rhtml filetype for html templates, and
> an eruby filetype for everything else. There is precedent for this
> elsewhere: Vim has a django filetype for Django templates and
OK, but I've not looked at that yet, so my comments aren't based on
deep knowledge...
> apparently will be getting a separate djangohtml filetype.
>
> transition until Vim 7.1 draws nearer. At this point, I'm looking for
> objections other than "this would be hard to do." If there were
The difficulty I see is that when you mix syntaxes you have to pull
in the right syntax groups, and there isn't a *simple* way to do thig
in vim. With lots of help from Doug and others I have, for example
in my .vimrc:
function RubyMetaMake()
:unlet! b:current_syntax
:syntax include @MAKESTUFF ~/.vimrc_include_make_syn
:syntax region rubyC1 matchgroup=String start=+%Q{+ end=+}+ keepend contains=@CSTUFF
:syntax region rubyMakeString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-MAKESTRING\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zsMAKESTRING$+ contains=rubyHeredocStart, at rubyStringSpecial, at MAKESTUFF fold keepend
endfunction
" To MetaProgram C using Ruby
function RubyMetaC1()
:unlet! b:current_syntax
:syntax include @CSTUFF ~/.vimrc_include_c_syn
:syntax region rubyC1 matchgroup=String start=+%Q{+ end=+}+ keepend contains=@CSTUFF
:syntax region rubyC2 matchgroup=String start=+%Q(+ end=+)+ keepend contains=@CSTUFF
:syntax region rubyC3 matchgroup=String start=+%Q<+ end=+>+ keepend contains=@CSTUFF
:syntax region rubyC3 matchgroup=String start=+%Q£+ end=+£+ keepend contains=@CSTUFF
" :syntax on
endfunction
function RubyMetaC2()
unlet b:current_syntax
syn include @cTop syntax/c.vim
let b:current_syntax = "ruby"
syn region rubyCString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<CSTRING\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^CSTRING$+ contains=rubyHeredocStart, at rubyStringSpecial, at cTop fold keepend
syn region rubyCString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<"CSTRING"\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^CSTRING$+ contains=rubyHeredocStart, at rubyStringSpecial, at cTop fold keepend
syn region rubyCString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<'CSTRING'\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^CSTRING$+ contains=rubyHeredocStart, at cTop fold keepend
syn region rubyCString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<`CSTRING`\ze+hs=s+2 matchgroup=rubyStringDelimiter end=+^CSTRING$+ contains=rubyHeredocStart, at rubyStringSpecial, at cTop fold keepend
syn region rubyCString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-CSTRING\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zsCSTRING$+ contains=rubyHeredocStart, at rubyStringSpecial, at cTop fold keepend
syn region rubyCString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-"CSTRING"\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zsCSTRING$+ contains=rubyHeredocStart, at rubyStringSpecial, at cTop fold keepend
syn region rubyCString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-'CSTRING'\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zsCSTRING$+ contains=rubyHeredocStart, at cTop fold keepend
syn region rubyCString start=+\%(\%(class\s*\|\%(\.\|::\)\)\_s*\)\@<!<<-`CSTRING`\ze+hs=s+3 matchgroup=rubyStringDelimiter end=+^\s*\zsCSTRING$+ contains=rubyHeredocStart, at rubyStringSpecial, at cTop fold keepend
syn cluster cCommentGroup contains=cTodo,rubyInterpolation
endfunction
There are 2 ways of doing it in there.
Well, I don't call that light reading, anyway. :-)
My point is that the OTHER syntax, outside of the ruby, is nontrivial
to cnnect to, and I expect that having a syntax file for ERB will
raise the expectation that it is trivial to get the highlighting right
for that as well at the same time.
> no technical or backwards compatibility restrictions, and such a
> change could be made with zero side-effects, would anybody disagree
> with such a change?
>
> An alternative to this is to have a new filetype for eruby files
> without HTML. Something like plaineruby or erubytext. This would
Is the extension .erb already taken?
> work but it makes me cringe, much like the tex filetype being LaTeX
Assuming that
:filetype detect
is "indistinguishable from magic", could it tell the files apart by
the presence of /<%[#=].*?%>/ ?
> and the plaintex filetype being TeX. I'd like to make my proposed
> change while Vim support for eruby is still young and evolving.
>
> Once again, I'm looking for idealistic objections at this point rather
> than practical ones. Does anyone object to the idea of two filetypes,
Drat! :-) I've answered the wrong question. Hope soemthing in here
is of use... In principle I'm in favour of encouraging this use of
eruby, mainly because I keep forgetting about it, and doing code generation
the hard way. Hence all that sfuff in my vimrc.
> or of my suggested naming scheme?
>
> Cheers,
> Tim
Hugh
More information about the vim-ruby-devel
mailing list