diff --git a/EXAMPLES.md b/EXAMPLES.md index b13c4ff..ed233ce 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -141,6 +141,31 @@ mysql: ``` +Formatting multi-line method chaining +------------------------------------- + +Try `.` or `*.` on the following lines. + +```ruby +my_object + .method1().chain() + .second_method().call() + .third().call() + .method_4().execute() +``` + +Notice that the indentation is adjusted to match the shortest one among those of +the lines starting with the delimiter. + +```ruby +my_object + .method1() .chain() + .second_method().call() + .third() .call() + .method_4() .execute() +``` + + Partial alignment in block-visual mode / Negative field index ------------------------------------------------------------- diff --git a/README.md b/README.md index 9c84dd0..0eae2fe 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ Notice that you can't append `\zs` to your regular expression to put delimiters on the left. It can be done by providing additional options in Vim dictionary format. -- `:EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'margin_left': '' }` +- `:EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'left_margin': '' }` Then we get: @@ -136,21 +136,21 @@ Then we get: Options keys are fuzzy-matched, so you can write as follows: -- `:EasyAlign * /[:;]\+/ { 'stl': 1, 'ml': '' }` +- `:EasyAlign * /[:;]\+/ { 'stl': 1, 'l': 0 }` You can even omit spaces between the arguments, so concisely (or cryptically): -- `:EasyAlign*/[:;]\+/{'stl':1,'ml':''}` +- `:EasyAlign*/[:;]\+/{'s':1,'l':0}` Available options for each alignment are as follows. -| Atrribute | Type | Default | -| ---------------- | ------- | ----------------------- | -| margin_left | string | `' '` | -| margin_right | string | `' '` | -| stick_to_left | boolean | 0 | -| ignore_unmatched | boolean | 1 | -| ignores | array | `['String', 'Comment']` | +| Atrribute | Type | Default | +| ---------------- | ---------------- | ----------------------- | +| left_margin | number or string | 0 | +| right_margin | number or string | 0 | +| stick_to_left | boolean | 0 | +| ignore_unmatched | boolean | 1 | +| ignores | array | `['String', 'Comment']` | (The last two options will be described shortly in the following sections.) @@ -331,14 +331,14 @@ let g:easy_align_delimiters = { \ '#': { 'pattern': '#\+', 'ignores': ['String'] }, \ ']': { \ 'pattern': '[\[\]]', -\ 'margin_left': '', -\ 'margin_right': '', +\ 'left_margin': 0, +\ 'right_margin': 0, \ 'stick_to_left': 0 \ }, \ ')': { \ 'pattern': '[()]', -\ 'margin_left': '', -\ 'margin_right': '', +\ 'left_margin': 0, +\ 'right_margin': 0, \ 'stick_to_left': 0 \ } \ } diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index 005fe37..3288f12 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -27,23 +27,24 @@ endif let g:loaded_easy_align = 1 let s:easy_align_delimiters_default = { -\ ' ': { 'pattern': ' ', 'margin_left': '', 'margin_right': '', 'stick_to_left': 0 }, +\ ' ': { 'pattern': ' ', 'left_margin': '', 'right_margin': '', 'stick_to_left': 0 }, \ '=': { 'pattern': '===\|<=>\|\(&&\|||\|<<\|>>\)=\|=\~\|=>\|[:+/*!%^=><&|-]\?=[#?]\?', -\ 'margin_left': ' ', 'margin_right': ' ', 'stick_to_left': 0 }, -\ ':': { 'pattern': ':', 'margin_left': '', 'margin_right': ' ', 'stick_to_left': 1 }, -\ ',': { 'pattern': ',', 'margin_left': '', 'margin_right': ' ', 'stick_to_left': 1 }, -\ '|': { 'pattern': '|', 'margin_left': ' ', 'margin_right': ' ', 'stick_to_left': 0 }, -\ '.': { 'pattern': '\.', 'margin_left': '', 'margin_right': '', 'stick_to_left': 0 }, +\ 'left_margin': ' ', 'right_margin': ' ', 'stick_to_left': 0 }, +\ ':': { 'pattern': ':', 'left_margin': '', 'right_margin': ' ', 'stick_to_left': 1 }, +\ ',': { 'pattern': ',', 'left_margin': '', 'right_margin': ' ', 'stick_to_left': 1 }, +\ '|': { 'pattern': '|', 'left_margin': ' ', 'right_margin': ' ', 'stick_to_left': 0 }, +\ '.': { 'pattern': '\.', 'left_margin': '', 'right_margin': '', 'stick_to_left': 0 }, \ '{': { 'pattern': '(\@")]) : 1, \ visualmode() == '' ? max([col("'<"), col("'>")]) : 0, \ get(dict, 'pattern', ch), \ nth, - \ get(dict, 'margin_left', ' '), - \ get(dict, 'margin_right', ' '), + \ ml, + \ mr, \ get(dict, 'stick_to_left', 0), \ get(dict, 'ignore_unmatched', get(g:, 'easy_align_ignore_unmatched', 1)), \ get(dict, 'ignores', s:ignored_syntax()), diff --git a/doc/easy_align.txt b/doc/easy_align.txt index d9d2417..c9c4e55 100644 --- a/doc/easy_align.txt +++ b/doc/easy_align.txt @@ -95,7 +95,7 @@ try these commands: Notice that you can't append `\zs` to your regular expression to put delimiters on the left. It can be done by providing additional options. -- :EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'margin_left': '' } +- :EasyAlign * /[:;]\+/ { 'stick_to_left': 1, 'left_margin': '' } Then we get: @@ -104,21 +104,21 @@ Then we get: Options keys are fuzzy-matched, so you can write as follows: -- :EasyAlign * /[:;]\+/ { 'stl': 1, 'ml': '' } +- :EasyAlign * /[:;]\+/ { 'stl': 1, 'l': '' } You can even omit spaces between the arguments, so concisely (or cryptically): -- :EasyAlign*/[:;]\+/{'stl':1,'ml':''} +- :EasyAlign*/[:;]\+/{'s':1,'l':''} Available options for each alignment are as follows. -| Atrribute | Type | Default | -| ---------------- | ------- | ----------------------- | -| margin_left | string | `' '` | -| margin_right | string | `' '` | -| stick_to_left | boolean | 0 | -| ignore_unmatched | boolean | 1 | -| ignores | array | `['String', 'Comment']` | +| Atrribute | Type | Default | +| ---------------- | ---------------- | ----------------------- | +| left_margin | number or string | 0 | +| right_margin | number or string | 0 | +| stick_to_left | boolean | 0 | +| ignore_unmatched | boolean | 1 | +| ignores | array | `['String', 'Comment']` | Partial alignment in blockwise-visual mode @@ -231,14 +231,14 @@ Extending alignment rules *g:easy_align_delimiters* \ '#': { 'pattern': '#\+' }, \ ']': { \ 'pattern': '[\[\]]', - \ 'margin_left': '', - \ 'margin_right': '', + \ 'left_margin': 0, + \ 'right_margin': 0, \ 'stick_to_left': 0 \ }, \ ')': { \ 'pattern': '[()]', - \ 'margin_left': '', - \ 'margin_right': '', + \ 'left_margin': 0, + \ 'right_margin': 0, \ 'stick_to_left': 0 \ } \ } diff --git a/test/basic.expected b/test/basic.expected index f02120a..e96978b 100644 --- a/test/basic.expected +++ b/test/basic.expected @@ -257,3 +257,102 @@ aa >= bb aaaaa /* bbbbb */ == ccccc /* != eeeee = */ === fffff ``` + +my_object + .method1 .chain + .second_method.call + .third .call + .method_4 .execute + +my_object + .method1 . chain + .second_method. call + .third . call + .method_4 .execute + +my_object + . method1.chain + .second_method.call + . third.call + . method_4.execute + +my_object + . method1.chain + .second_method.call + . third.call + . method_4.execute + +my_object + . method1. chain + .second_method. call + . third. call + . method_4.execute + +my_object + .method1 .chain + .second_method.call + .third .call + .method_4 .execute + +my_object + .method1.chain + .second_method.call + .third.call + .method_4.execute + +my_object . + method1 .chain. + second_method.call. + third .call. + method_4 .execute + + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + + |Option |Type |Default |Description | + |-- |-- |-- |-- | + |threads |Fixnum |1 |number of threads in the thread pool | + |queues |Fixnum |1 |number of concurrent queues | + |queue_size |Fixnum |1000 |size of each queue | + |interval |Numeric |0 |dispatcher interval for batch processing | + |batch |Boolean |false |enables batch processing mode | + |batch_size |Fixnum |nil |number of maximum items to be assigned at once | + |logger |Logger |nil |logger instance for debug logs | + + | Option <| Type <| Default<| Description <| + | -- <| -- <| -- <| -- <| + | threads <| Fixnum <| 1 <| number of threads in the thread pool <| + | queues <| Fixnum <| 1 <| number of concurrent queues <| + | queue_size<| Fixnum <| 1000 <| size of each queue <| + | interval <| Numeric<| 0 <| dispatcher interval for batch processing <| + | batch <| Boolean<| false <| enables batch processing mode <| + | batch_size<| Fixnum <| nil <| number of maximum items to be assigned at once<| + | logger <| Logger <| nil <| logger instance for debug logs <| + diff --git a/test/basic.md b/test/basic.md index 57dc5c8..c967c76 100644 --- a/test/basic.md +++ b/test/basic.md @@ -84,3 +84,26 @@ aa >= bb aaaaa /* bbbbb */ == ccccc /* != eeeee = */ === fffff ``` + +my_object + .method1.chain + .second_method.call + .third.call + .method_4.execute + +my_object. + method1.chain. + second_method.call. + third.call. + method_4.execute + + | Option| Type | Default | Description | + |--|--|--|--| + | threads | Fixnum | 1 | number of threads in the thread pool | + |queues |Fixnum | 1 | number of concurrent queues | + |queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + |batch | Boolean | false | enables batch processing mode | + |batch_size | Fixnum | nil | number of maximum items to be assigned at once | + |logger | Logger | nil | logger instance for debug logs | + diff --git a/test/basic.script b/test/basic.script index 8076d7e..b590950 100644 --- a/test/basic.script +++ b/test/basic.script @@ -1 +1 @@ -4Gvipjyvip Pvip 2 Pvip * Pvip Pvip 2 Pvip * Pvip ** Pvip - Pvip -2 Pvip -1 Pvip ** 60zzvipjyvip *|Pvip *|Pvip **|80zzvip **|gv 3|vip *|90zzvip *,100zzvipjyvip =Pvip *=Pvip **=Pvip =vip 2=198Gvipjyvip =Pvip -=Pf:jj3E =209Gvip - 214zzvipjyvip #P:let g:easy_align_delimiters = { '#': {'pattern': '#\+', 'ignores': ['String'] } } vip #227zzvip :239zzvip *=vipjyP:let g:easy_align_ignores = [] vip *=:unlet g:easy_align_delimiters 4Gvipy4GP7Gojkkvip:EasyAlign /1/{'ml':'{{', 'mrr':'}}'} vipjyPvip:EasyAlign */../ +4Gvipjyvip Pvip 2 Pvip * Pvip Pvip 2 Pvip * Pvip ** Pvip - Pvip -2 Pvip -1 Pvip ** 60zzvipjyvip *|Pvip *|Pvip **|80zzvip **|gv 3|vip *|90zzvip *,100zzvipjyvip =Pvip *=Pvip **=Pvip =vip 2=198Gvipjyvip =Pvip -=Pf:jj3E =209Gvip - 214zzvipjyvip #P:let g:easy_align_delimiters = { '#': {'pattern': '#\+', 'ignores': ['String'] } } vip #227zzvip :239zzvip *=vipjyP:let g:easy_align_ignores = [] vip *=:unlet g:easy_align_delimiters 4Gvipy4GP7Gojkkvip:EasyAlign /1/{'ml':'{{', 'mr-r':'}}'} vipjyPvip:EasyAlign */../ 263zzvipjygv .Pvip *.Pvip * .Pvip .vip 2.Pvip **.Pvip **.Pvip -.G303zzvip .310zzvipjygv *|Pvip *|Pvip |gv -|gv **|gv *|gv **|jji jjjhi vip ** |Gpvip:EasyAlign*|{'ml': 5, 'mrr': 0 } Gpvip:EasyAlign*/|/{'ml':'<', 'mrr': 4} diff --git a/test/regexp.script b/test/regexp.script index b735519..9e9d273 100644 --- a/test/regexp.script +++ b/test/regexp.script @@ -1 +1 @@ -4Gvipjyvip:EasyAlign: Pvip:EasyAlign*: Pvip:EasyAlign-: Pvip:EasyAlign * : Pvip:EasyAlign -2 : Pvip:EasyAlign -2: Pvip:easyA€kb€kb€kb€kb€kbEasAli€kb€kb€kbyAlign *: Pvip:EasyAlign; Pvip:EasyAlign /;/ Pvip:EasyAlign/;/ Pvip:EasyAlign*/;/ Pvip:e€kbEasyAlign/[:;]\+/ Pvip:EasyAlign*/[:;]\+/ Pvip:EasyAlign* /[:;]\+/ Pvip:EasyAlign */[:;]\+/ Pvip:EasyAlign * [:€kb€kb/[:;]\+/ Pvip:EasyAlign*[:;]\+€kb€kb€kb€kb€kb€kb€kb=/[€kb€kb€kb-/[:;]\+/ Pvip:EasyAlign-2/[:;\€kb\€kb]\+/ Pvip:EasyAlign/[:;]\+/{ 'ml': '<<<', 'mrr': '>>>'} Pvip:EasyAlign/[:;]\+/{'ml':''m€kb, 'stl': 1} Pvip:EasyAlign * /€kb /[:;]€kb\€kb]\+/ {'stick_to': 1, 'marl': '???', 'marr': '~~~'} Pvip:EasyAlign /../ Pvip:EasyAlign*/../ Pvip:EasyAlign ** €kb/[:;]/€kb€kb\+]/ Pvip:EasyAlign/[:;\€kb\€kb]\+/'€kb{'marginr':'____'} Pvip:EasyAlign**[€kb/[:;]\+/ Pvip:EasyAlign!**/[:;]\+/ Pfbjfm:EasyAlign/[:;]\+/ +4Gvipjyvip:EasyAlign: Pvip:EasyAlign*: Pvip:EasyAlign-: Pvip:EasyAlign * : Pvip:EasyAlign -2 : Pvip:EasyAlign -2: Pvip:easyA€kb€kb€kb€kb€kbEasAli€kb€kb€kbyAlign *: Pvip:EasyAlign; Pvip:EasyAlign /;/ Pvip:EasyAlign/;/ Pvip:EasyAlign*/;/ Pvip:e€kbEasyAlign/[:;]\+/ Pvip:EasyAlign*/[:;]\+/ Pvip:EasyAlign* /[:;]\+/ Pvip:EasyAlign */[:;]\+/ Pvip:EasyAlign * [:€kb€kb/[:;]\+/ Pvip:EasyAlign*[:;]\+€kb€kb€kb€kb€kb€kb€kb=/[€kb€kb€kb-/[:;]\+/ Pvip:EasyAlign-2/[:;\€kb\€kb]\+/ Pvip:EasyAlign/[:;]\+/{ 'l': '<<<', 'r': '>>>'} Pvip:EasyAlign/[:;]\+/{'l':''m€kb, 's': 1} Pvip:EasyAlign * /€kb /[:;]€kb\€kb]\+/ {'stick_to': 1, 'le': '???', 'marr': '~~~'} Pvip:EasyAlign /../ Pvip:EasyAlign*/../ Pvip:EasyAlign ** €kb/[:;]/€kb€kb\+]/ Pvip:EasyAlign/[:;\€kb\€kb]\+/'€kb{'rm':'____'} Pvip:EasyAlign**[€kb/[:;]\+/ Pvip:EasyAlign!**/[:;]\+/ Pfbjfm:EasyAlign/[:;]\+/ diff --git a/test/run.vim b/test/run.vim index 6712e5c..fb33a15 100644 --- a/test/run.vim +++ b/test/run.vim @@ -1,4 +1,5 @@ -source include.vim +e! +execute 'source '. expand('%:p:h') . '/include.vim' while line('.') < line('$') normal 30j @@ -6,7 +7,7 @@ while line('.') < line('$') endwhile normal gg -let @b=system('cat '. expand('%:r') . '.script') -let @a='@b:vert diffsplit ' . expand('%:r') . '.expected ' +let @b=system('cat '. expand('%:p:r') . '.script') +let @a='@b:vert diffsplit ' . expand('%:p:r') . '.expected ' " Syntax highlighting doesn't work echo "Press @a"