Skip to content

Commit

Permalink
Add b:lion_squeeze_spaces (#18)
Browse files Browse the repository at this point in the history
Add option to squeeze spaces when aligning

Fixes #15
  • Loading branch information
sudo-nice authored and tommcdo committed Jan 15, 2017
1 parent 9b1a923 commit 08d5e71
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,33 @@ git clone git://github.com/tommcdo/vim-lion.git

Once help tags have been generated, you can view the manual with
`:help lion`.

Options
-------

Option | Description | Default
--- | --- | ---
`g:lion_create_maps` | Whether to create mappings | `1`
`b:lion_squeeze_spaces`<br>`g:lion_squeeze_spaces` | Squeeze extra spaces | `0`
`g:lion_map_right` | Mapping for right-align operator | `gl`
`g:lion_map_left` | Mapping for left-align operator | `gL`

If you set: `let b:lion_squeeze_spaces = 1`, and hit `glip=`, you will turn

```php
$i = 5;
$user = 'tommcdo';
$stuff = array(1, 2, 3);
```
into:
```php
$i = 5;
$user = 'tommcdo';
$stuff = array(1, 2, 3);
```
instead of (`b:lion_squeeze_spaces = 0`):
```php
$i = 5;
$user = 'tommcdo';
$stuff = array(1, 2, 3);
```
12 changes: 7 additions & 5 deletions doc/lion.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ INTRODUCTION *lion*

This plugin provides operators for aligning text to a specific character.
The operators are designed to work as closely as possible to the built-in
Vim |operators|.
Vim |operators|.

MAPPINGS *lion-mappings*

Expand Down Expand Up @@ -50,11 +50,13 @@ CONFIGURATION *lion-configuration*

Mappings can be configured with the following options:

Option Description Default ~
Option Description Default ~

g:lion_create_maps Whether to create mappings 1
g:lion_map_right Mapping for right-align operator gl
g:lion_map_left Mapping for left-align operator gL
g:lion_create_maps Whether to create mappings 1
b:lion_squeeze_spaces,
g:lion_squeeze_spaces Whether to squeeze extra spaces 0
g:lion_map_right Mapping for right-align operator gl
g:lion_map_left Mapping for left-align operator gL

ISSUES AND TODO *lion-issues* *lion-todo*

Expand Down
16 changes: 16 additions & 0 deletions plugin/lion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ function! s:align(mode, type, vis, align_char)
endif
let [start_line, end_line, start_col, end_col, middle_start_col, middle_end_col] = pos

" Check for 'lion_squeeze_spaces' options
if exists('b:lion_squeeze_spaces')
let s:lion_squeeze_spaces = get(b:, 'lion_squeeze_spaces')
elseif exists('g:lion_squeeze_spaces')
let s:lion_squeeze_spaces = get(g:, 'lion_squeeze_spaces')
else
let s:lion_squeeze_spaces = 0
endif

" Squeeze extra spaces before aligning
if s:lion_squeeze_spaces
for lnum in range(start_line, end_line)
call setline(lnum, substitute(getline(lnum), '\(^\s*\)\@<! \{2,}', ' ', 'g'))
endfor
endif

" Align for each character up to count or maximum occurrences
let iteration = 1
while 1
Expand Down

0 comments on commit 08d5e71

Please sign in to comment.