Some fixes to s:sparkup handling in the Vim plugin #65

Merged
merged 8 commits into from Sep 1, 2013
View
@@ -34,6 +34,7 @@ textmate:
#cp ${README} TextMate/sparkup-readme.txt
vim:
- mkdir -p vim/ftplugin/html
+ mkdir -p vim/ftplugin/html vim/doc
cp ${SPARKUP_PY} vim/ftplugin/html/sparkup.py
- #cp ${README} vim/sparkup-readme.txt
+ # Add asteriks to title, so it gets matched by `:helptags`
+ sed '1s/.*/*\0*/' ${README} > vim/doc/sparkup.txt
@@ -17,6 +17,12 @@
"
" g:sparkupNextMapping (Default: '<c-n>') -
" Mapping used to jump to the next empty tag/attribute.
+"
+" g:sparkupMaps (Default: 1) -
+" Setup mappings?
+"
+" g:sparkupMapsNormal (Default: 0) -
+" Setup mappings for normal mode?
if !exists('g:sparkupExecuteMapping')
let g:sparkupExecuteMapping = '<c-e>'
@@ -26,10 +32,33 @@ if !exists('g:sparkupNextMapping')
let g:sparkupNextMapping = '<c-n>'
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>'
+if !exists('g:sparkupMaps')
+ let g:sparkupMaps = 1
+endif
+
+if !exists('g:sparkupMapsNormal')
+ let g:sparkupMapsNormal = 0
+endif
+
+inoremap <buffer> <Plug>SparkupExecute <c-g>u<Esc>:call <SID>Sparkup()<cr>
+inoremap <buffer> <Plug>SparkupNext <c-g>u<Esc>:call <SID>SparkupNext()<cr>
+
+if g:sparkupMaps
+ if ! hasmapto('<Plug>SparkupExecute', 'i')
+ exec 'inoremap <buffer> ' . g:sparkupExecuteMapping . ' <Plug>SparkupExecute'
+ endif
+ if ! hasmapto('<Plug>SparkupNext', 'i')
+ exec 'inoremap <buffer> ' . g:sparkupNextMapping . ' <Plug>SparkupNext'
+ endif
+ if g:sparkupMapsNormal
+ if ! hasmapto('<Plug>SparkupExecute', 'n')
+ exec 'nnoremap <buffer> ' . g:sparkupExecuteMapping . ' :call <SID>Sparkup()<cr>'
+ endif
+ if ! hasmapto('<Plug>SparkupNext', 'n')
+ exec 'nnoremap <buffer> ' . g:sparkupNextMapping . ' :call <SID>SparkupNext()<cr>'
+ endif
+ endif
+endif
if exists('*s:Sparkup')
finish
@@ -45,13 +74,14 @@ function! s:Sparkup()
" sparkup.vim in the runtimepath.
if !executable(s:sparkup)
let paths = substitute(escape(&runtimepath, ' '), '\(,\|$\)', '/**\1', 'g')
- let s:sparkup = findfile('sparkup.py', paths)
+ let s:sparkup = fnamemodify(findfile('sparkup.py', paths), ':p')
if !filereadable(s:sparkup)
echohl WarningMsg
- echom 'Warning: could not find sparkup on your path or in your vim runtime path.'
+ echom 'Warning: could not find sparkup/sparkup.py on your path or in your vim runtime path.'
echohl None
- finish
+ unlet s:sparkup
+ return
endif
endif
let s:sparkup = '"' . s:sparkup . '"'