diff --git a/runtime/autoload/htmlcomplete.vim b/runtime/autoload/htmlcomplete.vim
index cbe5792c3b..759d1267cd 100644
--- a/runtime/autoload/htmlcomplete.vim
+++ b/runtime/autoload/htmlcomplete.vim
@@ -1,7 +1,7 @@
" Vim completion script
" Language: XHTML 1.0 Strict
" Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
-" Last Change: 2006 Mar 5
+" Last Change: 2006 Mar 19
function! htmlcomplete#CompleteTags(findstart, base)
if a:findstart
@@ -87,17 +87,25 @@ function! htmlcomplete#CompleteTags(findstart, base)
let context_lines = getline(curline-i, curline)
let b:compl_context = join(context_lines, ' ')
break
- elseif context_line =~ '>[^<]*$'
- " Normal tag line, no need for completion at all
+ elseif context_line =~ '>[^<]*$' || i == curline
+ " We are in normal tag line, no need for completion at all
+ " OR reached first line without tag at all
let b:compl_context = ''
break
endif
let i += 1
+ " We reached first line and no tag approached
+ " Prevents endless loop
+ "if i > curline
+ "let b:compl_context = ''
+ "break
+ "endif
endwhile
" Make sure we don't have counter
unlet! i
endif
let b:compl_context = matchstr(b:compl_context, '.*\zs<.*')
+
" Return proper start for on-events. Without that beginning of
" completion will be badly reported
if b:compl_context =~? 'on[a-z]*\s*=\s*\(''[^'']*\|"[^"]*\)$'
@@ -106,6 +114,15 @@ function! htmlcomplete#CompleteTags(findstart, base)
let start -= 1
endwhile
endif
+ " If b:compl_context begins with we are inside of PHP code. It
+ " wasn't closed so PHP completion passed it to HTML
+ if &filetype =~? 'php' && b:compl_context =~ '^'
+ let b:phpcompl = 1
+ let start = col('.') - 1
+ while start >= 0 && line[start - 1] =~ '[a-zA-Z_0-9\x7f-\xff$]'
+ let start -= 1
+ endwhile
+ endif
else
let b:compl_context = getline('.')[0:compl_begin]
endif
@@ -117,7 +134,8 @@ function! htmlcomplete#CompleteTags(findstart, base)
" a:base is very short - we need context
let context = b:compl_context
" Check if we should do CSS completion inside of