Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 98 lines (88 sloc) 3.239 kb
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
" Sparkup
" Notes:
" (romainl:2012.10.25) Added SparkupPrevious() and the corresponding mappings.
"
" Installation:
" Copy the contents of vim/ftplugin/ to your ~/.vim/ftplugin directory.
"
" $ cp -R vim/ftplugin ~/.vim/ftplugin/
"
" Configuration:
" g:sparkup (Default: 'sparkup') -
" Location of the sparkup executable. You shouldn't need to change this
" setting if you used the install option above.
"
" g:sparkupArgs (Default: '--no-last-newline') -
" Additional args passed to sparkup.
"
" g:sparkupExecuteMapping (Default: '<c-e>') -
" Mapping used to execute sparkup.
"
" g:sparkupNextMapping (Default: '<c-n>') -
" Mapping used to jump to the next empty tag/attribute.
"
" g:sparkupPreviousMapping (Default: '<c-p>') -
" Mapping used to jump to the previous empty tag/attribute.

if !exists('g:sparkupExecuteMapping')
  let g:sparkupExecuteMapping = '<c-e>'
endif

if !exists('g:sparkupNextMapping')
  let g:sparkupNextMapping = '<c-n>'
endif

if !exists('g:sparkupPreviousMapping')
  let g:sparkupPreviousMapping = '<c-p>'
endif

exec 'nnoremap <buffer> ' . g:sparkupExecuteMapping . ' :call <SID>Sparkup()<cr>'
exec 'inoremap <buffer> ' . g:sparkupExecuteMapping . ' <c-g>u<Esc>:call <SID>Sparkup()<cr>'
exec 'nnoremap <buffer> ' . g:sparkupNextMapping . ' :call <SID>SparkupNext()<cr>'
exec 'inoremap <buffer> ' . g:sparkupNextMapping . ' <c-g>u<Esc>:call <SID>SparkupNext()<cr>'
exec 'nnoremap <buffer> ' . g:sparkupPreviousMapping . ' :call <SID>SparkupPrevious()<cr>'
exec 'inoremap <buffer> ' . g:sparkupPreviousMapping . ' <c-g>u<Esc>:call <SID>SparkupPrevious()<cr>'

if exists('*s:Sparkup')
    finish
endif

function! s:Sparkup()
    if !exists('s:sparkup')
        let s:sparkup = exists('g:sparkup') ? g:sparkup : 'sparkup'
        let s:sparkupArgs = exists('g:sparkupArgs') ? g:sparkupArgs : '--no-last-newline'
" check the user's path first. if not found then search relative to
" sparkup.vim in the runtimepath.
        if !executable(s:sparkup)
            let paths = substitute(escape(&runtimepath, ' '), '\(,\|$\)', '/**\1', 'g')
            let s:sparkup = findfile('sparkup.py', paths)

            if !filereadable(s:sparkup)
                echohl WarningMsg
                echom 'Warning: could not find sparkup on your path or in your vim runtime path.'
                echohl None
                finish
            endif
        endif
        let s:sparkup = '"' . s:sparkup . '"'
        let s:sparkup .= printf(' %s --indent-spaces=%s', s:sparkupArgs, &shiftwidth)
        if has('win32') || has('win64')
            let s:sparkup = 'python ' . s:sparkup
        endif
    endif
    exec '.!' . s:sparkup
    call s:SparkupNext()
endfunction

function! s:SparkupNext()
" 1: empty tag, 2: empty attribute, 3: empty line
    let n = search('><\/\|\(""\)\|^\s*$', 'Wp')
    if n == 3
        startinsert!
    else
        execute 'normal l'
        startinsert
    endif
endfunction

function! s:SparkupPrevious()
" 1: empty tag, 2: empty attribute, 3: empty line
    let n = search('><\/\|\(""\)\|^\s*$', 'b', 'Wp')
    if n == 3
        startinsert!
    else
        execute 'normal l'
        startinsert
    endif
endfunction
Something went wrong with that request. Please try again.