Configure Django SnipMate for Django Projects Only

I am using SnipMate with Rob Hudson snipmate_for_djangoto develop Django with MacVim .

To activate fragments automatically depending on the type of file, Rob recommends adding the ~/.vimrcfollowing:

autocmd FileType python set ft=python.django " For SnipMate
autocmd FileType html set ft=htmldjango.html " For SnipMate

This allows snippets htmldjangofor all files html.

Is there a way to include fragments htmldjangoonly for files htmllocated in a Django project?

For example, I do not want to include fragments htmldjangoif I am working on a file htmlassociated with a Rails project.

+3
source share
2 answers

, rails.vim, Rails Tim Pope, .

*.rb(Ruby) Rails, Rails. .

, :

augroup railsPluginDetect
  autocmd!
  autocmd BufNewFile,BufRead * call s:Detect(expand("<afile>:p"))
  autocmd VimEnter * if expand("<amatch>") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
  autocmd FileType netrw if !exists("b:rails_root") | call s:Detect(expand("<afile>:p")) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
  autocmd BufEnter * if exists("b:rails_root")|silent doau User BufEnterRails|endif
  autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
  autocmd Syntax railslog if s:autoload()|call rails#log_syntax()|endif
augroup END

, s:Detect , Rails , ./config/environment.rb, , BufEnterRails silent doau User BufEnterRails, , BufEnterRails .

. Django html, , , Django .

Django, , , , , , Django.

+1

, , . filetype.vim, MacVim - /Applications/MacVim.app/Contents/Resources/vim/runtime/filetype.vim - , HTML Django, , , extends block :

au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm  call s:FThtml()

" Distinguish between HTML, XHTML and Django
func! s:FThtml()
  let n = 1
  while n < 10 && n < line("$")
    if getline(n) =~ '\<DTD\s\+XHTML\s'
      setf xhtml
      return
    endif
    if getline(n) =~ '{%\s*\(extends\|block\)\>'
      setf htmldjango
      return
    endif
    let n = n + 1
  endwhile
  setf html
endfunc

, load , .

+1

Source: https://habr.com/ru/post/1793863/


All Articles