mirror of
https://github.com/tpope/vim-haml.git
synced 2025-12-07 01:34:25 +08:00
Initial commit
This commit is contained in:
2
ftdetect/haml.vim
Normal file
2
ftdetect/haml.vim
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
autocmd BufNewFile,BufRead *.haml setf haml
|
||||||
|
autocmd BufNewFile,BufRead *.sass setf sass
|
||||||
89
ftplugin/haml.vim
Normal file
89
ftplugin/haml.vim
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
" Vim filetype plugin
|
||||||
|
" Language: Haml
|
||||||
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.info>
|
||||||
|
|
||||||
|
" Only do this when not done yet for this buffer
|
||||||
|
if exists("b:did_ftplugin")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:save_cpo = &cpo
|
||||||
|
set cpo-=C
|
||||||
|
|
||||||
|
" Define some defaults in case the included ftplugins don't set them.
|
||||||
|
let s:undo_ftplugin = ""
|
||||||
|
let s:browsefilter = "All Files (*.*)\t*.*\n"
|
||||||
|
let s:match_words = ""
|
||||||
|
|
||||||
|
if !exists("g:haml_default_subtype")
|
||||||
|
let g:haml_default_subtype = "html"
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists("b:haml_subtype")
|
||||||
|
let s:lines = getline(1)."\n".getline(2)."\n".getline(3)."\n".getline(4)."\n".getline(5)."\n".getline("$")
|
||||||
|
let b:haml_subtype = matchstr(s:lines,'haml_subtype=\zs\w\+')
|
||||||
|
if b:haml_subtype == ''
|
||||||
|
let b:haml_subtype = matchstr(substitute(expand("%:t"),'\c\%(\.haml\)\+$','',''),'\.\zs\w\+$')
|
||||||
|
endif
|
||||||
|
if b:haml_subtype == 'txt'
|
||||||
|
" Conventional; not a real file type
|
||||||
|
let b:haml_subtype = 'text'
|
||||||
|
elseif b:haml_subtype == ''
|
||||||
|
let b:haml_subtype = g:haml_default_subtype
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if exists("b:haml_subtype") && b:haml_subtype != ''
|
||||||
|
exe "runtime! ftplugin/".b:haml_subtype.".vim ftplugin/".b:haml_subtype."_*.vim ftplugin/".b:haml_subtype."/*.vim"
|
||||||
|
else
|
||||||
|
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
|
||||||
|
endif
|
||||||
|
unlet! b:did_ftplugin
|
||||||
|
|
||||||
|
" Override our defaults if these were set by an included ftplugin.
|
||||||
|
if exists("b:undo_ftplugin")
|
||||||
|
let s:undo_ftplugin = b:undo_ftplugin
|
||||||
|
unlet b:undo_ftplugin
|
||||||
|
endif
|
||||||
|
if exists("b:browsefilter")
|
||||||
|
let s:browsefilter = b:browsefilter
|
||||||
|
unlet b:browsefilter
|
||||||
|
endif
|
||||||
|
if exists("b:match_words")
|
||||||
|
let s:match_words = b:match_words
|
||||||
|
unlet b:match_words
|
||||||
|
endif
|
||||||
|
|
||||||
|
runtime! ftplugin/ruby.vim ftplugin/ruby_*.vim ftplugin/ruby/*.vim
|
||||||
|
let b:did_ftplugin = 1
|
||||||
|
|
||||||
|
" Combine the new set of values with those previously included.
|
||||||
|
if exists("b:undo_ftplugin")
|
||||||
|
let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin
|
||||||
|
endif
|
||||||
|
if exists ("b:browsefilter")
|
||||||
|
let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter
|
||||||
|
endif
|
||||||
|
if exists("b:match_words")
|
||||||
|
let s:match_words = b:match_words . ',' . s:match_words
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Change the browse dialog on Win32 to show mainly Haml-related files
|
||||||
|
if has("gui_win32")
|
||||||
|
let b:browsefilter="Haml Files (*.haml)\t*.haml\n" . s:browsefilter
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Load the combined list of match_words for matchit.vim
|
||||||
|
if exists("loaded_matchit")
|
||||||
|
let b:match_words = s:match_words
|
||||||
|
endif
|
||||||
|
|
||||||
|
"setlocal comments=f:/[,fb:/,fb:-#
|
||||||
|
setlocal commentstring=-#\ %s
|
||||||
|
|
||||||
|
let b:undo_ftplugin = "setl cms< com< "
|
||||||
|
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo
|
||||||
|
|
||||||
|
" vim: nowrap sw=2 sts=2 ts=8 ff=unix:
|
||||||
73
indent/haml.vim
Normal file
73
indent/haml.vim
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
" Vim indent file
|
||||||
|
" Language: HAML
|
||||||
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.info>
|
||||||
|
" Last Change: 2007 Dec 16
|
||||||
|
|
||||||
|
if exists("b:did_indent")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
runtime! indent/ruby.vim
|
||||||
|
unlet! b:did_indent
|
||||||
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
setlocal autoindent sw=2 et
|
||||||
|
setlocal indentexpr=GetHamlIndent()
|
||||||
|
setlocal indentkeys=o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when
|
||||||
|
|
||||||
|
" Only define the function once.
|
||||||
|
if exists("*GetHamlIndent")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:attributes = '\%({.\{-\}}\|\[.\{-\}\]\)'
|
||||||
|
let s:tag = '\%([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
|
||||||
|
|
||||||
|
if !exists('g:haml_self_closing_tags')
|
||||||
|
let g:haml_self_closing_tags = 'meta|link|img|hr|br'
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! GetHamlIndent()
|
||||||
|
let lnum = prevnonblank(v:lnum-1)
|
||||||
|
if lnum == 0
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
let line = substitute(getline(lnum),'\s\+$','','')
|
||||||
|
let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
|
||||||
|
let lastcol = strlen(line)
|
||||||
|
let line = substitute(line,'^\s\+','','')
|
||||||
|
let indent = indent(lnum)
|
||||||
|
let cindent = indent(v:lnum)
|
||||||
|
if cline =~# '\v^-\s*%(elsif|else|when)>'
|
||||||
|
let indent = cindent < indent ? cindent : indent - &sw
|
||||||
|
endif
|
||||||
|
let increase = indent + &sw
|
||||||
|
if indent == indent(lnum)
|
||||||
|
let indent = cindent <= indent ? -1 : increase
|
||||||
|
endif
|
||||||
|
"let indent = indent == indent(lnum) ? -1 : indent
|
||||||
|
"let indent = indent > indent(lnum) + &sw ? indent(lnum) + &sw : indent
|
||||||
|
|
||||||
|
let group = synIDattr(synID(lnum,lastcol,1),'name')
|
||||||
|
|
||||||
|
if line =~ '^!!!'
|
||||||
|
return indent
|
||||||
|
elseif line =~ '^/\%(\[[^]]*\]\)\=$'
|
||||||
|
return increase
|
||||||
|
elseif line =~ '^:'
|
||||||
|
return increase
|
||||||
|
elseif line =~ '^'.s:tag.'[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do |[^|]*|\s*$\)'
|
||||||
|
return increase
|
||||||
|
elseif line == '-#'
|
||||||
|
return increase
|
||||||
|
elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^%\v%('.g:haml_self_closing_tags.')>'
|
||||||
|
return indent
|
||||||
|
elseif group =~? '\v^%(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$'
|
||||||
|
return increase
|
||||||
|
elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter'
|
||||||
|
return GetRubyIndent()
|
||||||
|
else
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" vim:set sw=2:
|
||||||
83
syntax/haml.vim
Normal file
83
syntax/haml.vim
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
" Vim syntax file
|
||||||
|
" Language: Haml
|
||||||
|
" Maintainer: Tim Pope <vimNOSPAM@tpope.info>
|
||||||
|
" Filenames: *.haml
|
||||||
|
|
||||||
|
if exists("b:current_syntax")
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists("main_syntax")
|
||||||
|
let main_syntax = 'haml'
|
||||||
|
endif
|
||||||
|
let b:ruby_no_expensive = 1
|
||||||
|
|
||||||
|
runtime! syntax/html.vim
|
||||||
|
unlet! b:current_syntax
|
||||||
|
silent! syn include @hamlSassTop syntax/sass.vim
|
||||||
|
unlet! b:current_syntax
|
||||||
|
syn include @hamlRubyTop syntax/ruby.vim
|
||||||
|
|
||||||
|
syn case match
|
||||||
|
|
||||||
|
syn cluster hamlComponent contains=hamlAttributes,hamlClassChar,hamlIdChar,hamlObject,hamlDespacer,hamlSelfCloser,hamlRuby,hamlPlainChar,hamlInterpolatable
|
||||||
|
syn cluster hamlEmbeddedRuby contains=hamlAttributes,hamlObject,hamlRuby,hamlRubyFilter
|
||||||
|
syn cluster hamlTop contains=hamlBegin,hamlPlainFilter,hamlRubyFilter,hamlSassFilter,hamlComment,hamlHtmlComment
|
||||||
|
|
||||||
|
syn match hamlBegin "^\s*[<>&]\@!" nextgroup=hamlTag,hamlAttributes,hamlClassChar,hamlIdChar,hamlObject,hamlRuby,hamlPlainChar,hamlInterpolatable
|
||||||
|
|
||||||
|
syn match hamlTag "%\w\+" contained contains=htmlTagName,htmlSpecialTagName nextgroup=@hamlComponent
|
||||||
|
syn region hamlAttributes matchgroup=hamlAttributesDelimiter start="{" end="}" contained contains=@hamlRubyTop nextgroup=@hamlComponent
|
||||||
|
syn region hamlObject matchgroup=hamlObjectDelimiter start="\[" end="\]" contained contains=@hamlRubyTop nextgroup=@hamlComponent
|
||||||
|
syn match hamlDespacer "[<>]" contained nextgroup=hamlDespacer,hamlSelfCloser,hamlRuby,hamlPlainChar,hamlInterpolatable
|
||||||
|
syn match hamlSelfCloser "/" contained
|
||||||
|
syn match hamlClassChar "\." contained nextgroup=hamlClass
|
||||||
|
syn match hamlIdChar "#" contained nextgroup=hamlId
|
||||||
|
syn match hamlClass "\%(\w\|-\)\+" contained nextgroup=@hamlComponent
|
||||||
|
syn match hamlId "\%(\w\|-\)\+" contained nextgroup=@hamlComponent
|
||||||
|
syn region hamlDocType start="^\s*!!!" end="$"
|
||||||
|
|
||||||
|
syn region hamlRuby matchgroup=hamlRubyOutputChar start="[=~]" end="$" contained contains=@hamlRubyTop keepend
|
||||||
|
syn region hamlRuby matchgroup=hamlRubyChar start="-" end="$" contained contains=@hamlRubyTop keepend
|
||||||
|
syn match hamlPlainChar "\\" contained
|
||||||
|
syn region hamlInterpolatable matchgroup=hamlInterpolatableChar start="==" end="$" keepend contained contains=rubyInterpolation
|
||||||
|
|
||||||
|
syn match hamlHelper "\<action_view?\|\.\@<!\<\%(flatten\|open\|puts\)" contained containedin=@hamlEmbeddedRuby,@hamlRubyTop,rubyInterpolation
|
||||||
|
syn keyword hamlHelper capture_haml find_and_preserve html_attrs init_haml_helpers list_of preced preserve succeed surround tab_down tab_up page_class contained containedin=@hamlEmbeddedRuby,@hamlRubyTop,rubyInterpolation
|
||||||
|
|
||||||
|
syn region hamlPlainFilter matchgroup=hamlFilter start="^\z(\s*\):\%(plain\|preserve\|erb\|redcloth\|textile\|markdown\)\s*$" end="^\%(\z1 \)\@!" contains=htmlTag,htmlEndTag,htmlSpecialChar,htmlComment,@htmlTop
|
||||||
|
syn region hamlRubyFilter matchgroup=hamlFilter start="^\z(\s*\):ruby\s*$" end="^\%(\z1 \)\@!" contains=@hamlRubyTop
|
||||||
|
syn region hamlSassFilter matchgroup=hamlFilter start="^\z(\s*\):sass\s*$" end="^\%(\z1 \)\@!" contains=@hamlSassTop
|
||||||
|
|
||||||
|
syn region hamlJavascriptBlock start="^\z(\s*\)%script" nextgroup=@hamlComponent,hamlError end="^\%(\z1 \)\@!" contains=@hamlTop,@htmlJavaScript keepend
|
||||||
|
syn region hamlCssBlock start="^\z(\s*\)%style" nextgroup=@hamlComponent,hamlError end="^\%(\z1 \)\@!" contains=@hamlTop,@htmlCss keepend
|
||||||
|
syn match hamlError "\$" contained
|
||||||
|
|
||||||
|
syn region hamlComment start="^\z(\s*\)-#" end="^\%(\z1 \)\@!" contains=rubyTodo
|
||||||
|
syn region hamlHtmlComment start="^\z(\s*\)/" end="^\%(\z1 \)\@!" contains=@hamlTop,rubyTodo
|
||||||
|
syn match hamlIEConditional "\%(^\s*/\)\@<=\[if\>[^]]*]" contained containedin=hamlHtmlComment
|
||||||
|
|
||||||
|
hi def link hamlSelfCloser Special
|
||||||
|
hi def link hamlDespacer Special
|
||||||
|
hi def link hamlClassChar Special
|
||||||
|
hi def link hamlIdChar Special
|
||||||
|
hi def link hamlTag Special
|
||||||
|
hi def link hamlClass Type
|
||||||
|
hi def link hamlId Identifier
|
||||||
|
hi def link hamlPlainChar Special
|
||||||
|
hi def link hamlInterpolatableChar hamlRubyChar
|
||||||
|
hi def link hamlRubyOutputChar hamlRubyChar
|
||||||
|
hi def link hamlRubyChar Special
|
||||||
|
hi def link hamlDocType PreProc
|
||||||
|
hi def link hamlFilter PreProc
|
||||||
|
hi def link hamlAttributesDelimiter Delimiter
|
||||||
|
hi def link hamlObjectDelimiter Delimiter
|
||||||
|
hi def link hamlHelper Function
|
||||||
|
hi def link hamlHtmlComment hamlComment
|
||||||
|
hi def link hamlComment Comment
|
||||||
|
hi def link hamlIEConditional SpecialComment
|
||||||
|
hi def link hamlError Error
|
||||||
|
|
||||||
|
let b:current_syntax = "haml"
|
||||||
|
|
||||||
|
" vim:set sts=4 sw=4:
|
||||||
Reference in New Issue
Block a user