Browse files

merge with local

  • Loading branch information...
2 parents ff6f5ee + 1536b3c commit cd8d57b1076100d6977f5e95a5fbb9f1ad5c5c77 @mjbrownie committed Apr 24, 2012
Showing with 74 additions and 13 deletions.
  1. +4 −0 CHANGELOG
  2. +27 −5 README
  3. +43 −8 autoload/htmldjangocomplete.vim
View
4 CHANGELOG
@@ -1,4 +1,8 @@
+<<<<<<< HEAD
v0.5.1 Mon 23 Apr 2012
- compatability fixes for older django versions
- fix some edge cases in tag detection
+=======
+v0.6 - html omni support / better matching
+>>>>>>> 1536b3ca8b747f5578c5a41c1684b17e709113bc
View
32 README
@@ -50,6 +50,21 @@ SETUP
au FileType htmldjango set omnifunc=htmldjangocomplete#CompleteDjango
+ 3. Optional: At the moment you need to force a html flavour for htmlcompletion
+
+ in .vimrc
+
+ let g:htmldjangocomplete_html_flavour = 'html401s'
+
+ :verbose function htmlcomplete#CheckDoctype for DocType details
+
+ Choices:
+ 'html401t' 'xhtml10s' 'html32' 'html40t' 'html40f' 'html40s'
+ 'html401t' 'html401f' 'html401s' 'xhtml10t' 'xhtml10f' 'xhtml10s'
+ 'xhtml11'
+
+ 'html5' if you have html5.vim
+
TESTING
django needs to be in sys.path along with DJANGO_SETTINGS_MODULE in your
@@ -70,12 +85,9 @@ TESTING
TODO
- This is just a proof of concept at the moment. It does not yet fall back
- to html omnicomplete elegantly.
-
most of the line regexps still need tweaking. This might not work well with
an auto popup plugin like autocompletepop. Expect incorrect types to be set
- as the context.
+ as the context for edge cases.
-python fallback to naive lists.
@@ -84,7 +96,7 @@ TODO
plugging in python omnicomplete and grabbing Variables with some
middleware trickery. Ideas welcome.
- some vim file to :so
+ some vim file to :so
python << EOF
htmldjango_opts['variable'] = [
@@ -93,3 +105,13 @@ TODO
]
EOF
+ super block complete
+
+ eg {% block c<c-x><c-o> %} to complete 'content' or something defined
+ in an extended template.
+
+ url complete
+ {% url <c-x><c-o> %} should complete views and named urls
+
+ Intelligent DOCTYPE handling
+ look for extends ... detect type in base html document etc
View
51 autoload/htmldjangocomplete.vim
@@ -1,16 +1,39 @@
" Vim completion script
" Language: htmldjango
" Maintainer: Michael Brown
-" Version: v0.5.1
-" Last Change: Mon 23 Apr 2012 21:06:03 EST
+" Last Change: Mon Apr 23 22:52:25 CDT 2012
+" Version: 0.6
" Omnicomplete for django template taga/variables/filters
-"
+" {{{1 Environment Settings
+if !exists('g:htmldjangocomplete_html_flavour')
+ " :verbose function htmlcomplete#CheckDoctype for details
+ " No html5!
+ "'html401t' 'xhtml10s' 'html32' 'html40t' 'html40f' 'html40s'
+ "'html401t' 'html401f' 'html401s' 'xhtml10t' 'xhtml10f' 'xhtml10s'
+ "'xhtml11'
+ let g:htmldjangocomplete_html_flavour = 'xhtml11'
+endif
+
+"Allow settings of DEBUG
+if !exists('g:htmldjangocomplete_debug')
+ let g:htmldjangocomplete_debug = 0
+endif
+
"{{{1 The actual omnifunc
function! htmldjangocomplete#CompleteDjango(findstart, base)
- "findstart = 1 when we need to get the text length
+ "{{{2 findstart = 1 when we need to get the text length
"
-
if a:findstart == 1
+
+ "Fallback to htmlcomplete
+ if searchpair('{{','','}}','nc') == 0 && searchpair('{%',"",'%}','nc') == 0
+ if !exists('b:html_doctype')
+ let b:html_doctype = 1
+ let b:html_omni_flavor = g:htmldjangocomplete_html_flavour
+ endif
+ return htmlcomplete#CompleteTags(a:findstart,a:base)
+ endif
+
" locate the start of the word
let line = getline('.')
let start = col('.') - 1
@@ -30,8 +53,16 @@ function! htmldjangocomplete#CompleteDjango(findstart, base)
let start -= 1
endwhile
return start
- "findstart = 0 when we need to return the list of completions
+ "{{{2 findstart = 0 when we need to return the list of completions
else
+ "Fallback to htmlcomplete
+ if searchpair('{{','','}}','nc') == 0 && searchpair('{%',"",'%}','nc') == 0
+ let matches = htmlcomplete#CompleteTags(a:findstart,a:base)
+ "suppress all DOCTYPE matches
+ call filter(matches, 'stridx(v:val["word"],"DOCTYPE") == -1')
+ return matches
+ endif
+
"TODO: Reduce load always nature of this plugin
call s:load_libs()
"get context look for {% {{ and |
@@ -100,7 +131,10 @@ let g:htmldjangocomplete_completions = []
function! s:load_libs()
if has('python')
python << EOF
-DEBUG = False
+try:
+ HTMLDJANGO_DEBUG = vim.eval("g:htmldjangocomplete_debug") == 0 and True or False
+except:
+ HTMLDJANGO_DEBUG = False
TEMPLATE_EXTS = ['.html','.txt','.htm']
@@ -211,7 +245,8 @@ for line in cb:
htmldjango_opts['filter'] += _get_opt_dict(l,'filters',lib)
htmldjango_opts['tag'] += _get_opt_dict(l,'tags',lib)
except Exception as e:
- if DEBUG:
+ if HTMLDJANGO_DEBUG:
+ print "FAILED TO LOAD: %s" % lib
raise e
#TODO I may be able to populate RequestContext via middleware component

0 comments on commit cd8d57b

Please sign in to comment.