File: html.vim

package info (click to toggle)
vim 2%3A9.1.1882-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 92,504 kB
  • sloc: ansic: 432,444; cpp: 6,371; makefile: 4,596; sh: 2,387; java: 2,312; xml: 2,099; python: 1,559; perl: 1,419; awk: 730; lisp: 501; cs: 458; objc: 369; sed: 8; csh: 6
file content (111 lines) | stat: -rw-r--r-- 3,181 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
" Vim filetype plugin file
" Language:		HTML
" Maintainer:		Doug Kearns <dougkearns@gmail.com>
" Previous Maintainer:	Dan Sharp
" Last Change:		2025 Sep 12

if exists("b:did_ftplugin")
  finish
endif
let b:did_ftplugin = 1

let s:save_cpo = &cpo
set cpo-=C

setlocal matchpairs+=<:>
setlocal commentstring=<!--\ %s\ -->
setlocal comments=s:<!--,m:\ \ \ \ ,e:-->

if exists('b:undo_ftplugin')
  " no whitespace before |, handle possible :unmap at end of current value
  let b:undo_ftplugin ..= "| setlocal comments< commentstring< matchpairs<"
else
  let b:undo_ftplugin = "setlocal comments< commentstring< matchpairs<"
endif

if get(g:, "ft_html_autocomment", 0)
  setlocal formatoptions-=t formatoptions+=croql
  let b:undo_ftplugin ..= " | setlocal formatoptions<"
endif

if exists('&omnifunc')
  setlocal omnifunc=htmlcomplete#CompleteTags
  call htmlcomplete#DetectOmniFlavor()
  let b:undo_ftplugin ..= " | setlocal omnifunc<"
endif

" HTML: thanks to Johannes Zellner and Benji Fisher.
if exists("loaded_matchit") && !exists("b:match_words")
  let b:match_ignorecase = 1
  let b:match_words = '<!--:-->,' ..
	\	      '<:>,' ..
	\	      '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' ..
	\	      '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' ..
	\	      '<\@<=\([^/!][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>'
  let b:html_set_match_words = 1
  let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words b:html_set_match_words"
endif

" Change the :browse e filter to primarily show HTML-related files.
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  let  b:browsefilter = "HTML Files (*.html, *.htm)\t*.html;*.htm\n" ..
	\		"JavaScript Files (*.js)\t*.js\n" ..
	\		"Cascading StyleSheets (*.css)\t*.css\n"
  if has("win32")
    let b:browsefilter ..= "All Files (*.*)\t*\n"
  else
    let b:browsefilter ..= "All Files (*)\t*\n"
  endif
  let b:html_set_browsefilter = 1
  let b:undo_ftplugin ..= " | unlet! b:browsefilter b:html_set_browsefilter"
endif

if has("folding") && get(g:, "html_expr_folding", 0)
  function! HTMLTagFold() abort
    if empty(get(b:, "foldsmap", {}))
      if empty(get(b:, "current_syntax", ''))
	return '0'
      else
	let b:foldsmap = htmlfold#MapBalancedTags()
      endif
    endif

    return get(b:foldsmap, v:lnum, '=')
  endfunction

  setlocal foldexpr=HTMLTagFold()
  setlocal foldmethod=expr
  let b:undo_ftplugin ..= " | setlocal foldexpr< foldmethod<"

  if !get(g:, "html_expr_folding_without_recomputation", 0)
    augroup htmltagfold
      autocmd! htmltagfold
      autocmd TextChanged,InsertLeave <buffer> let b:foldsmap = {}
    augroup END

    " XXX: Keep ":autocmd" last in "b:undo_ftplugin" (see ":help :bar").
    let b:undo_ftplugin ..= " | silent! autocmd! htmltagfold * <buffer>"
  endif
endif

let &cpo = s:save_cpo
unlet s:save_cpo

" See ":help vim9-mix".
if !has("vim9script")
  finish
endif

if exists("*g:HTMLTagFold")
  def! g:HTMLTagFold(): string
    if empty(get(b:, "foldsmap", {}))
      if empty(get(b:, "current_syntax", ''))
	return '0'
      else
	b:foldsmap = g:htmlfold#MapBalancedTags()
      endif
    endif

    return get(b:foldsmap, v:lnum, '=')
  enddef
endif