aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/html.vim
blob: e0d47e47c7cc7b640a4219ccae2fd516705a7ad2 (plain) (blame)
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
" Make a bare URL into a link to itself
function! html#UrlLink() abort

  " Yank this whole whitespace-separated word
  normal! yiW
  " Open a link tag
  normal! i<a href="">
  " Paste the URL into the quotes
  normal! hP
  " Move to the end of the link text URL
  normal! E
  " Close the link tag
  normal! a</a>

endfunction

" Tidy the whole buffer
function! html#TidyBuffer() abort
  let l:view = winsaveview()
  %!tidy -quiet
  call winrestview(l:view)
endfunction

" Update a timestamp
function! html#TimestampUpdate() abort
  if !&modified
    return
  endif
  let l:cv = winsaveview()
  call cursor(1,1)
  let l:li = search('\C^\s*<em>Last updated: .\+</em>$', 'n')
  if l:li
    let l:date = substitute(system('date -u'), '\C\n$', '', '')
    let l:line = getline(l:li)
    call setline(l:li, substitute(l:line, '\C\S.*',
          \ '<em>Last updated: '.l:date.'</em>', ''))
  endif
  call winrestview(l:cv)
endfunction