Skip to content

Commit

Permalink
Remove --filetype option; Vim: pass --xml properly
Browse files Browse the repository at this point in the history
vim/ftplugin/html/sparkup.vim:
 - pass `--xml`, if 'xml' is used in &filetype (might be several)
 - build args to sparkup on every call: its input is dynamic,
   especially the new &expandtab
 - use "python" workaround only for Windows (it is executable for
   Linux/Unix), and its shebang should be used

Fixes rstacruz#69, rstacruz#83.
  • Loading branch information
blueyed committed Oct 7, 2013
1 parent e234a4f commit b4bc30b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions sparkup.py
Expand Up @@ -302,7 +302,7 @@ def __init__(self, options=None, str=''):
self.tokens = []
self.str = str
self.options = options
if self.options.has("filetype") and self.options.get("filetype") == "xml":
if self.options.has("xml"):
self.dialect = XmlDialect()
else:
self.dialect = HtmlDialect()
Expand Down Expand Up @@ -1095,7 +1095,6 @@ def has(self, attr):
cmdline_keys = [
('h', 'help', 'Shows help'),
('v', 'version', 'Shows the version'),
('', 'filetype=', 'enable html attribute fillings unless filetype=xml'),
('', 'no-guides', 'Deprecated'),
('', 'post-tag-guides', 'Adds comments at the end of DIV tags'),
('', 'textmate', 'Adds snippet info (textmate mode)'),
Expand All @@ -1105,6 +1104,7 @@ def has(self, attr):
('', 'no-last-newline', 'Skip the trailing newline'),
('', 'start-guide-format=', 'To be documented'), # << TODO
('', 'end-guide-format=', 'To be documented'), # << TODO
('', 'xml', 'Skip html attribute fillings'),
('', 'no-html5-self-closing', 'Use HTML4 <br /> instead of HTML5 <br>'),
]

Expand Down
33 changes: 23 additions & 10 deletions vim/ftplugin/html/sparkup.vim
Expand Up @@ -67,12 +67,11 @@ 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'
let s:sparkupArgs = s:sparkupArgs . ' --filetype=' . &filetype

" check the user's path first. if not found then search relative to
" sparkup.vim in the runtimepath.
if !executable(s:sparkup)
" If g:sparkup is not configured (and/or not found in $PATH),
" look for sparkup.vim in Vim's runtimepath.
" XXX: quite expensive for a Pathogen-like environment (where &rtp is huge)
let paths = substitute(escape(&runtimepath, ' '), '\(,\|$\)', '/**\1', 'g')
let s:sparkup = fnamemodify(findfile('sparkup.py', paths), ':p')

Expand All @@ -85,14 +84,28 @@ function! s:Sparkup()
endif
endif
let s:sparkup = '"' . s:sparkup . '"'
let s:sparkup .= printf(' %s --indent-spaces=%s', s:sparkupArgs, &shiftwidth)
" If the user's settings are to indent with tabs, do so!
" TODO textmate version of this functionality
if !&expandtab
let s:sparkup .= ' --indent-tabs'
" Workaround for windows, where the Python file cannot be executed via shebang
if has('win32') || has('win64')
let s:sparkup = 'python ' . s:sparkup
endif
endif
exec '.!python ' . s:sparkup

" Build arguments list (not cached, g:sparkupArgs might change, also
" &filetype, &expandtab etc)
let sparkupArgs = exists('g:sparkupArgs') ? g:sparkupArgs : '--no-last-newline'
" Pass '--xml' option, if 'xml' is used as filetype (default: none/'html')
" NOTE: &filetype can contain multiple values, e.g. 'smarty.html'
if index(split(&filetype, '\.'), 'xml') >= 0
let sparkupArgs .= ' --xml'
endif
" If the user's settings are to indent with tabs, do so!
" TODO textmate version of this functionality
if !&expandtab
let sparkupArgs .= ' --indent-tabs'
endif

let sparkupCmd = s:sparkup . printf(' %s --indent-spaces=%s', sparkupArgs, &shiftwidth)
exec '.!' . sparkupCmd
call s:SparkupNext()
endfunction

Expand Down

0 comments on commit b4bc30b

Please sign in to comment.