16 Commits
2.9.1 ... 2.9.3

Author SHA1 Message Date
Junegunn Choi
a9f593fdf8 Update test runner 2014-05-09 00:55:28 +09:00
Junegunn Choi
d87ea32cfe Update .travis.yml 2014-04-28 13:44:45 +09:00
Junegunn Choi
11a6b03e7e Add .travis.yml 2014-04-28 13:25:20 +09:00
Junegunn Choi
ba54df53ca Better handling of tab characters using strdisplaywidth 2014-04-11 10:39:39 +09:00
Junegunn Choi
d041e17bba Update README 2014-03-19 19:10:53 +09:00
Junegunn Choi
2ab86911cb Update README 2014-03-19 19:06:03 +09:00
Junegunn Choi
4929841a7a Remove +float dependency 2014-01-20 01:30:31 +09:00
Junegunn Choi
12792cd60f Simplify tests using Include: directive 2014-01-19 11:32:52 +09:00
Junegunn Choi
f7213f30f3 Update README
- Changed maps to LiveEasyAlign
2013-12-22 15:19:58 +09:00
Junegunn Choi
f44c325aa2 Merge branch 'master' of github.com:junegunn/vim-easy-align 2013-12-21 16:47:27 +09:00
Junegunn Choi
dc4786841e Workaround for Vim bug: using Float as a String in gvim (#27) 2013-12-19 10:20:04 +09:00
Junegunn Choi
46abd8fb92 Add set cpo&vim for compatible mode 2013-12-19 10:04:03 +09:00
Junegunn Choi
af39e544ca set cpo&vim for compatible mode 2013-12-19 00:53:05 +09:00
Junegunn Choi
49c7133328 Update documentation 2013-12-11 00:53:03 +09:00
Junegunn Choi
4298395085 Extract tags from code block as well 2013-12-08 19:11:43 +09:00
Junegunn Choi
e7fca89dde Update helpdoc
- Change heading format
2013-12-08 10:35:56 +09:00
14 changed files with 157 additions and 99 deletions

13
.travis.yml Normal file
View File

@@ -0,0 +1,13 @@
language: vim
before_script: |
git clone https://github.com/junegunn/vader.vim.git
script: |
vim -Nu <(cat << VIMRC
filetype off
set rtp+=vader.vim
set rtp+=.
set rtp+=after
filetype plugin indent on
VIMRC) -c 'Vader! test/*' > /dev/null

View File

@@ -65,9 +65,9 @@ nmap <Leader>a <Plug>(EasyAlign)
And with the following lines of text,
```
apple = red
grass=green
sky=blue
apple =red
grass+=green
sky-= blue
```
try these commands:
@@ -83,12 +83,7 @@ try these commands:
Notice that the commands are repeatable with `.` key if you have installed
[repeat.vim](https://github.com/tpope/vim-repeat). Install
[visualrepeat](https://github.com/vim-scripts/visualrepeat) as well if you want
to repeat in visual mode. Or you can add the following mapping to your .vimrc.
```vim
" Repeat alignment in visual mode with . key
vmap . <Plug>(EasyAlignRepeat)
```
to repeat in visual mode.
Usage
-----
@@ -253,8 +248,8 @@ the same parameters as `:EasyAlign`. I suggest you define mappings such as
follows in addition to the ones for `:EasyAlign` command.
```vim
vmap <Leader><Enter> <Plug>(LiveEasyAlign)
nmap <Leader>A <Plug>(LiveEasyAlign)
vmap <Leader><Enter> <Plug>(LiveEasyAlign)
nmap <Leader><Leader>a <Plug>(LiveEasyAlign)
```
In live interactive mode, you have to type in the same delimiter (or `CTRL-X` on
@@ -630,8 +625,6 @@ daisy = 4
eggplant = 5
```
Notice that `idt` is fuzzy-matched to `indentation`.
In interactive mode, you can change the option value with `CTRL-I` key.
### Alignments over multiple occurrences of delimiters

View File

@@ -26,6 +26,9 @@ if exists("g:loaded_easy_align")
endif
let g:loaded_easy_align = 1
let s:cpo_save = &cpo
set cpo&vim
let s:easy_align_delimiters_default = {
\ ' ': { 'pattern': ' ', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0 },
\ '=': { 'pattern': '===\|<=>\|\(&&\|||\|<<\|>>\)=\|=\~[#?]\?\|=>\|[:+/*!%^=><&|.-]\?=[#?]\?',
@@ -64,9 +67,9 @@ let s:shorthand = {
\ 'mode_sequence': 'm', 'ignores': 'ig', 'filter': 'f'
\ }
if exists("*strwidth")
if exists("*strdisplaywidth")
function! s:strwidth(str)
return strwidth(a:str) + len(matchstr(a:str, '^\t*')) * (&tabstop - 1)
return strdisplaywidth(a:str)
endfunction
else
function! s:strwidth(str)
@@ -74,6 +77,14 @@ else
endfunction
endif
function! s:ceil2(v)
return a:v % 2 == 0 ? a:v : a:v + 1
endfunction
function! s:floor2(v)
return a:v % 2 == 0 ? a:v : a:v - 1
endfunction
function! s:highlighted_as(line, col, groups)
if empty(a:groups) | return 0 | endif
let hl = synIDattr(synID(a:line, a:col, 0), 'name')
@@ -332,7 +343,7 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
let mode = a:modes[0]
let lines = {}
let min_indent = -1
let max = { 'pivot_len': 0.0, 'token_len': 0, 'just_len': 0, 'delim_len': 0,
let max = { 'pivot_len2': 0, 'token_len': 0, 'just_len': 0, 'delim_len': 0,
\ 'indent': 0, 'tokens': 0, 'strip_len': 0 }
let d = a:dict
let [f, fx] = s:parse_filter(d.filter)
@@ -410,8 +421,9 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
let max.delim_len = max([max.delim_len, s:strwidth(delim)])
if mode ==? 'c'
if max.pivot_len < pw + tw / 2.0
let max.pivot_len = pw + tw / 2.0
let pivot_len2 = pw * 2 + tw
if max.pivot_len2 < pivot_len2
let max.pivot_len2 = pivot_len2
endif
let max.strip_len = max([max.strip_len, s:strwidth(s:trim(token))])
endif
@@ -432,9 +444,9 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
end
if idt !=? 'k'
let max.just_len = 0
let max.token_len = 0
let max.pivot_len = 0
let max.just_len = 0
let max.token_len = 0
let max.pivot_len2 = 0
for [line, elems] in items(lines)
let [nth, prefix, token, delim] = elems
@@ -460,8 +472,9 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
let max.token_len = max([max.token_len, tw])
let max.just_len = max([max.just_len, pw + tw])
if mode ==? 'c'
if max.pivot_len < pw + tw / 2.0
let max.pivot_len = pw + tw / 2.0
let pivot_len2 = pw * 2 + tw
if max.pivot_len2 < pivot_len2
let max.pivot_len2 = pivot_len2
endif
endif
@@ -496,15 +509,15 @@ function! s:do_align(todo, modes, all_tokens, all_delims, fl, ll, fc, lc, nth, r
let indent = matchstr(token, '^\s*')
let token = indent . pad . s:ltrim(token)
elseif mode ==? 'c'
let p1 = max.pivot_len - (pw + tw / 2.0)
let p2 = (max.token_len - tw) / 2.0
let pf1 = floor(p1)
if pf1 < p1 | let p2 = ceil(p2)
else | let p2 = floor(p2)
let p1 = max.pivot_len2 - (pw * 2 + tw)
let p2 = max.token_len - tw
let pf1 = s:floor2(p1)
if pf1 < p1 | let p2 = s:ceil2(p2)
else | let p2 = s:floor2(p2)
endif
let strip = float2nr(ceil((max.token_len - max.strip_len) / 2.0))
let strip = s:ceil2(max.token_len - max.strip_len) / 2
let indent = matchstr(token, '^\s*')
let token = indent. repeat(' ', float2nr(pf1)) .s:ltrim(token). repeat(' ', float2nr(p2))
let token = indent. repeat(' ', pf1 / 2) .s:ltrim(token). repeat(' ', p2 / 2)
let token = substitute(token, repeat(' ', strip) . '$', '', '')
if d.stick_to_left
@@ -1093,3 +1106,6 @@ function! easy_align#align(bang, live, visualmode, expr) range
endtry
endfunction
let &cpo = s:cpo_save
unlet s:cpo_save

View File

@@ -1,4 +1,4 @@
easy-align.txt vim-easy-align Last change: December 8 2013
easy-align.txt vim-easy-align Last change: December 22 2013
VIM-EASY-ALIGN - TABLE OF CONTENTS *easyalign* *easy-align* *easy-align-toc*
==============================================================================
@@ -124,9 +124,9 @@ Add the following mappings to your .vimrc.
<
And with the following lines of text,
>
apple = red
grass=green
sky=blue
apple =red
grass+=green
sky-= blue
<
try these commands:
@@ -144,6 +144,8 @@ visual mode. Or you can add the following mapping to your .vimrc.
{8} https://github.com/tpope/vim-repeat
{9} https://github.com/vim-scripts/visualrepeat
*<Plug>(EasyAlignRepeat)*
>
" Repeat alignment in visual mode with . key
vmap . <Plug>(EasyAlignRepeat)
@@ -238,7 +240,7 @@ You can override these default rules or define your own rules with
(|easy-align-extending-alignment-rules|).
< Example command sequences >_________________________________________________~
Example command sequences~
*easy-align-example-command-sequences*
*easy-align-5-2-1*
@@ -259,7 +261,7 @@ You can override these default rules or define your own rules with
<Enter><Enter>**= | Right-left alternating around = | :'<,'>EasyAlign!**=
< Using regular expressions >_________________________________________________~
Using regular expressions~
*easy-align-using-regular-expressions*
*easy-align-5-2-2*
@@ -273,7 +275,7 @@ align text around all occurrences of numbers:
- `[0-9]\+`
< Alignment options in interactive mode >_____________________________________~
Alignment options in interactive mode~
*easy-align-alignment-options-in-interactive-mode*
*easy-align-5-2-3*
@@ -334,9 +336,11 @@ result of the alignment on-the-fly as you type in.
Live interactive mode can be started with `:LiveEasyAlign` command which takes
the same parameters as `:EasyAlign`. I suggest you define mappings such as
follows in addition to the ones for `:EasyAlign` command.
*<Plug>(LiveEasyAlign)*
>
vmap <Leader><Enter> <Plug>(LiveEasyAlign)
nmap <Leader>A <Plug>(LiveEasyAlign)
vmap <Leader><Enter> <Plug>(LiveEasyAlign)
nmap <Leader><Leader>a <Plug>(LiveEasyAlign)
<
In live interactive mode, you have to type in the same delimiter (or CTRL-X on
regular expression) again to finalize the alignment. This allows you to preview
@@ -504,7 +508,7 @@ given pattern. There are several ways to set the pattern.
(You don't need to escape '/'s in the regular expression)
< Examples >__________________________________________________________________~
Examples~
*easy-align-examples*
*easy-align-6-2-1*
>
@@ -787,7 +791,7 @@ You may refer to the definitions of the default alignment rules {here}{10}.
{10} https://github.com/junegunn/vim-easy-align/blob/2.9.0/autoload/easy_align.vim#L29
< Examples >__________________________________________________________________~
Examples~
*easy-align-examples-2*
*easy-align-6-8-1*
>
@@ -853,6 +857,9 @@ version first starts in right-alignment mode.
If you do not prefer this default mode transition, you can define your own
settings as follows.
*g:easy_align_interactive_modes*
*g:easy_align_bang_interactive_modes*
>
let g:easy_align_interactive_modes = ['l', 'r']
let g:easy_align_bang_interactive_modes = ['c', 'r']
@@ -937,8 +944,6 @@ be done with just two keystrokes: <Enter>:
"user:pass":"r00t:pa55"
};
<
*g:AlignSkip*
(To be fair, Align also can be configured to consider syntax highlighting with
`g:AlignSkip` function reference which should point to a custom function that
looks up the syntax group of a character on a certain position)

View File

@@ -31,8 +31,12 @@ command! -nargs=* -range -bang LiveEasyAlign <line1>,<line2>call easy_align#alig
let s:last_command = 'EasyAlign'
function! s:abs(v)
return a:v >= 0 ? a:v : - a:v
endfunction
function! s:remember_visual(mode)
let s:last_visual = [a:mode, abs(line("'>") - line("'<")), abs(col("'>") - col("'<"))]
let s:last_visual = [a:mode, s:abs(line("'>") - line("'<")), s:abs(col("'>") - col("'<"))]
endfunction
function! s:repeat_visual()

View File

@@ -7,7 +7,7 @@ Test cases for vim-easy-align
### Run
```vim
:Vader*
```
./run
```

View File

@@ -1,14 +1,4 @@
Execute (Clean up test environment):
Save g:easy_align_ignore_groups, g:easy_align_ignore_unmatched
Save g:easy_align_indentation, g:easy_align_delimiter_align
Save g:easy_align_interactive_modes, g:easy_align_bang_interactive_modes
Save g:easy_align_delimiters
let g:easy_align_delimiters = {}
silent! unlet g:easy_align_ignore_groups
silent! unlet g:easy_align_ignore_unmatched
silent! unlet g:easy_align_indentation
silent! unlet g:easy_align_delimiter_align
Include: include/setup.vader
Given (fruits):
apple;:;;banana::cake
@@ -161,5 +151,4 @@ Expect javascript:
"user: pass": "r00t: pa55"
};
Execute:
Restore
Include: include/teardown.vader

View File

@@ -1,5 +1,4 @@
Execute:
Save &tabstop
Include: include/setup.vader
Given (Table):
|a|b|c|d|
@@ -118,5 +117,26 @@ Expect:
n2gv = {}
n2vt = {}
Given (Tab-indented code (#20)):
class MyUnitTest(unittest.TestCase):
def test_base(self):
# n2f= {}
## n2v= {}
# f2v = {}
## n2gv = {}
# n2vt = {}
Execute:
Restore
set tabstop=12
%EasyAlign=
Expect:
class MyUnitTest(unittest.TestCase):
def test_base(self):
# n2f = {}
## n2v = {}
# f2v = {}
## n2gv = {}
# n2vt = {}
Include: include/teardown.vader

View File

@@ -1,3 +1,5 @@
Include: include/setup.vader
# It is currently possible that EasyAlign command incorrectly judges
# that it was executed in block-wise visual mode
Given:
@@ -18,3 +20,5 @@ Do (TODO Workaround: reset visualmode() on error):
Expect:
a | b | c
Include: include/teardown.vader

32
test/include/setup.vader Normal file
View File

@@ -0,0 +1,32 @@
Execute (Clean up test environment):
Save g:easy_align_ignore_groups, g:easy_align_ignore_unmatched
Save g:easy_align_indentation, g:easy_align_delimiter_align
Save g:easy_align_interactive_modes, g:easy_align_bang_interactive_modes
Save g:easy_align_delimiters, g:easy_align_bypass_fold
Save &tabstop, mapleader
unlet! g:easy_align_ignore_groups
unlet! g:easy_align_ignore_unmatched
unlet! g:easy_align_indentation
unlet! g:easy_align_delimiter_align
unlet! g:easy_align_interactive_modes
unlet! g:easy_align_bang_interactive_modes
unlet! g:easy_align_bypass_fold
let g:easy_align_delimiters = {}
let mapleader = ' '
vnoremap <silent> r<Enter> :EasyAlign!<Enter>
vnoremap <silent> <Leader>r<Enter> :LiveEasyAlign!<Enter>
" " Legacy
" vnoremap <silent> <Enter> :EasyAlign<Enter>
" vnoremap <silent> <Leader><Enter> :LiveEasyAlign<Enter>
" nmap <leader>A <Plug>(EasyAlignOperator)
set ts=2
vmap <Enter> <Plug>(EasyAlign)
vmap <leader><Enter> <Plug>(LiveEasyAlign)
nmap <leader>A <Plug>(EasyAlign)
vmap <leader>. <Plug>(EasyAlignRepeat)

View File

@@ -0,0 +1,3 @@
Execute:
Restore

View File

@@ -1,32 +1,4 @@
Execute (Clean up test environment):
Save g:easy_align_ignore_groups, g:easy_align_ignore_unmatched
Save g:easy_align_indentation, g:easy_align_delimiter_align
Save g:easy_align_interactive_modes, g:easy_align_bang_interactive_modes
Save g:easy_align_delimiters, &tabstop
Save mapleader
" TODO: revert after test
silent! unlet g:easy_align_ignore_groups
silent! unlet g:easy_align_ignore_unmatched
silent! unlet g:easy_align_indentation
silent! unlet g:easy_align_delimiter_align
silent! unlet g:easy_align_interactive_modes
silent! unlet g:easy_align_bang_interactive_modes
let g:easy_align_delimiters = {}
let mapleader = ' '
vnoremap <silent> r<Enter> :EasyAlign!<Enter>
vnoremap <silent> <Leader>r<Enter> :LiveEasyAlign!<Enter>
" " Legacy
" vnoremap <silent> <Enter> :EasyAlign<Enter>
" vnoremap <silent> <Leader><Enter> :LiveEasyAlign<Enter>
" nmap <leader>A <Plug>(EasyAlignOperator)
vmap <Enter> <Plug>(EasyAlign)
vmap <leader><Enter> <Plug>(LiveEasyAlign)
nmap <leader>A <Plug>(EasyAlign)
vmap <leader>. <Plug>(EasyAlignRepeat)
Include: include/setup.vader
###########################################################
@@ -1619,6 +1591,5 @@ Expect:
:: :: f : 6
###########################################################
Execute:
Restore
Include: include/teardown.vader

11
test/run Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
cd $(dirname $BASH_SOURCE)
vim -Nu <(cat << EOF
syntax on
for dep in ['vader.vim', 'vim-repeat']
execute 'set rtp+=' . finddir(dep, expand('~/.vim').'/**')
endfor
set rtp+=..
EOF) +Vader*

View File

@@ -1,8 +1,6 @@
# http://en.wikibooks.org/wiki/LaTeX/Tables
Execute:
Save g:easy_align_delimiters, g:easy_align_bypass_fold
let g:easy_align_delimiters = {}
silent! unlet g:easy_align_bypass_fold
Include: include/setup.vader
Given tex (table with escaped &):
\begin{tabular}{ l c r }
@@ -157,5 +155,4 @@ Expect tex:
8192 & 9.45\e2 & 0.0 & 4.51\e2 & 0.0 & & & & & & \\
\end{tabular}
Execute:
Restore
Include: include/teardown.vader