Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 0.0.2

- Single-line CSS declarations
- Various bugfixes and refactoring
  • Loading branch information...
commit ec2f8ed7913a5dcc5bcdd649a56095358b8069e3 1 parent 1a0097a
@AndrewRadev AndrewRadev authored committed
View
8 autoload/sideways.vim
@@ -1,5 +1,5 @@
-function! sideways#Left()
- let items = sideways#parsing#Parse()
+function! sideways#Left(definitions)
+ let items = sideways#parsing#Parse(a:definitions)
if empty(items)
return 0
end
@@ -25,8 +25,8 @@ function! sideways#Left()
return 1
endfunction
-function! sideways#Right()
- let items = sideways#parsing#Parse()
+function! sideways#Right(definitions)
+ let items = sideways#parsing#Parse(a:definitions)
if empty(items)
return 0
end
View
58 autoload/sideways/parsing.vim
@@ -11,40 +11,9 @@
"
" [ [14, 16], [19, 21] ]
"
-function! sideways#parsing#Parse()
- let definitions =
- \ [
- \ {
- \ 'start': '\k(',
- \ 'end': ')',
- \ 'delimiter': '^,\s*',
- \ 'skip': '^\s',
- \ 'brackets': ['([''"', ')]''"']
- \ },
- \ {
- \ 'start': '\[',
- \ 'end': '\]',
- \ 'delimiter': '^,\s*',
- \ 'skip': '^\s',
- \ 'brackets': ['([''"', ')]''"']
- \ },
- \ {
- \ 'start': '\k:\s*',
- \ 'end': ';',
- \ 'delimiter': '^\s',
- \ 'skip': '^\s',
- \ 'brackets': ['(''"', ')''"']
- \ },
- \ {
- \ 'start': '^\s*|',
- \ 'end': '|$',
- \ 'delimiter': '^|',
- \ 'skip': '^$',
- \ 'brackets': ['(''"', ')''"']
- \ },
- \ ]
-
- let items = []
+function! sideways#parsing#Parse(definitions)
+ let definitions = a:definitions
+ let items = []
for definition in definitions
let start_pattern = definition.start
@@ -54,7 +23,7 @@ function! sideways#parsing#Parse()
let [opening_brackets, closing_brackets] = definition.brackets
- normal! zR
+ silent! normal! zO
call sideways#util#PushCursor()
if searchpair(start_pattern, '', end_pattern, 'bW', '', line('.')) <= 0
@@ -67,34 +36,41 @@ function! sideways#parsing#Parse()
normal! l
let current_item = [col('.'), -1]
-
let remainder_of_line = s:RemainderOfLine()
+ " TODO (2012-09-07) Figure out how to work with RemainderOfLine
while s:RemainderOfLine() !~ '^'.end_pattern
let remainder_of_line = s:RemainderOfLine()
let bracket_match = s:BracketMatch(remainder_of_line, opening_brackets)
if bracket_match >= 0
+ " then try to jump to the closing bracket
+ let opening_bracket = opening_brackets[bracket_match]
let closing_bracket = closing_brackets[bracket_match]
- if search('\V'.closing_bracket, 'W', line('.')) <= 0
- continue
- else
- normal! l
- endif
+ call searchpair('\V'.opening_bracket, '', '\V'.closing_bracket, 'W', '', line('.'))
+ " move rightwards regardless of the result
+ normal! l
elseif remainder_of_line =~ delimiter_pattern
+ " then store the current item
let current_item[1] = col('.') - 1
call add(items, current_item)
normal! l
+
+ " skip some whitespace TODO consider removing
while s:RemainderOfLine() =~ skip_pattern
normal! l
endwhile
+
+ " initialize a new "current item"
let current_item = [col('.'), -1]
elseif col('.') == col('$') - 1
+ " then we're at the end of the line, finish up
let current_item[1] = col('$') - 1
break
else
+ " move rightwards
normal! l
endif
endwhile
View
6 doc/sideways.txt
@@ -23,7 +23,7 @@ The command is (provided you're in ~/.vim):
<
Another way is to simply copy all the essential directories inside the ~/.vim
-directory: plugin, ftplugin, autoload, doc.
+directory: plugin, autoload, doc.
==============================================================================
USAGE *sideways-usage* *SidewaysLeft* *SidewaysRight*
@@ -58,6 +58,10 @@ Apart from functions, it works for lists in CSS declarations:
>
border-radius: 20px 0 0 20px;
<
+Also for single-line CSS declarations:
+>
+ a { color: #fff; background: blue; text-decoration: underline; }
+<
And, it also works for cucumber tables:
>
Examples:
View
45 plugin/sideways.vim
@@ -2,12 +2,51 @@ if exists("g:loaded_sideways") || &cp
finish
endif
-let g:loaded_sideways = '0.0.1' " version number
+let g:loaded_sideways = '0.0.2' " version number
let s:keepcpo = &cpo
set cpo&vim
-command! SidewaysLeft call sideways#Left()
-command! SidewaysRight call sideways#Right()
+let g:sideways_definitions =
+ \ [
+ \ {
+ \ 'start': '(\s*',
+ \ 'end': '\s*)',
+ \ 'delimiter': '^,\s*',
+ \ 'skip': '^\s',
+ \ 'brackets': ['([''"', ')]''"']
+ \ },
+ \ {
+ \ 'start': '\[\s*',
+ \ 'end': '\s*\]',
+ \ 'delimiter': '^,\s*',
+ \ 'skip': '^\s',
+ \ 'brackets': ['([''"', ')]''"']
+ \ },
+ \ {
+ \ 'start': '\k:\s*',
+ \ 'end': ';',
+ \ 'delimiter': '^\s',
+ \ 'skip': '^\s',
+ \ 'brackets': ['(''"', ')''"']
+ \ },
+ \ {
+ \ 'start': '{\s*',
+ \ 'end': ';\=\s*}',
+ \ 'delimiter': '^;\s*',
+ \ 'skip': '^\s',
+ \ 'brackets': ['(''"', ')''"']
+ \ },
+ \ {
+ \ 'start': '^\s*|',
+ \ 'end': '|$',
+ \ 'delimiter': '^|',
+ \ 'skip': '^$',
+ \ 'brackets': ['(''"', ')''"']
+ \ },
+ \ ]
+
+command! SidewaysLeft call sideways#Left(g:sideways_definitions)
+command! SidewaysRight call sideways#Right(g:sideways_definitions)
let &cpo = s:keepcpo
unlet s:keepcpo
Please sign in to comment.
Something went wrong with that request. Please try again.