Skip to content

Commit 0102798

Browse files
committed
Version 0.3
vim-buffr plugin version 0.3 required * position and buffer name arguments were added to command * allow range * buffr#open_or_create arguments were changed to dictionary * command VExtract was renamed to Extr * g:extract_position option was removed
1 parent f9d67fd commit 0102798

File tree

3 files changed

+80
-42
lines changed

3 files changed

+80
-42
lines changed

autoload/extract.vim

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,47 @@
22
" Description: Extract selection to a new buffer
33
" Author: Alexander Skachko <[email protected]>
44
" Homepage: https://github.com/lucerion/vim-extract
5-
" Version: 0.2
5+
" Version: 0.3
66
" Licence: MIT
77
" ==============================================================
88

9-
func! extract#extract(start_line, end_line)
9+
func! extract#extract(start_line, end_line, count, buffer_options)
10+
let s:buffer_options = a:buffer_options
11+
1012
if exists('g:loaded_buffr')
11-
call s:extract(a:start_line, a:end_line)
13+
call s:extract(a:start_line, a:end_line, a:count)
1214
else
1315
call s:show_error('Please, install vim-buffr')
1416
return
1517
endif
1618
endfunc
1719

18-
func! s:extract(start_line, end_line)
20+
func! s:extract(start_line, end_line, count)
1921
let l:selection = getline(a:start_line, a:end_line)
20-
let l:in_visual_mode = s:in_visual_mode()
2122

22-
if l:in_visual_mode && len(l:selection)
23+
if a:count
2324
call s:delete_lines(a:start_line, a:end_line)
2425
endif
2526
call s:open_buffer()
26-
if l:in_visual_mode && len(l:selection)
27+
if a:count
2728
call s:clear_buffer()
2829
call s:insert_selection(l:selection)
2930
endif
3031
endfunc
3132

3233
func! s:open_buffer()
33-
let l:buffer_name = substitute(g:extract_name, '{filename}', expand('%:t'), 'g')
34-
call buffr#open_or_create_buffer(l:buffer_name, g:extract_position)
34+
call buffr#open_or_create_buffer(s:buffer_options())
3535
call s:set_buffer_defaults()
3636
endfunc
3737

38+
func! s:buffer_options()
39+
let l:default_buffer_options = {
40+
\ 'name': substitute(g:extract_name, '{filename}', expand('%:t'), 'g'),
41+
\ }
42+
43+
return extend(l:default_buffer_options, s:buffer_options)
44+
endfunc
45+
3846
func! s:clear_buffer()
3947
if !g:extract_append
4048
silent exec 'normal! ggVGd'
@@ -63,10 +71,6 @@ func! s:set_buffer_defaults()
6371
setlocal noswapfile
6472
endfunc
6573

66-
func! s:in_visual_mode()
67-
return visualmode(1) =~? '.*v'
68-
endfunc
69-
7074
func! s:show_error(message)
7175
echohl ErrorMsg | echomsg a:message | echohl None
7276
endfunc

doc/vim-extract.txt

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
Author: Alexander Skachko <[email protected]>
44
Homepage: https://github.com/lucerion/vim-extract
5-
Version: 0.2
6-
Licence: MIT
5+
Version: 0.3
6+
Licence: MIT (see LICENSE)
77

88
===============================================================================
99
CONTENTS *vim-extract*
@@ -17,25 +17,26 @@ License |vim-extract-license|
1717
===============================================================================
1818
INSTALL *vim-extract-install*
1919

20-
vim-extract dependending on vim-buffr plugin
20+
This plugin depends on vim-buffr (https://github.com/lucerion/vim-buffr)
21+
plugin
2122

22-
Vundle https://github.com/VundleVim/Vundle.vim
23+
Vundle https://github.com/VundleVim/Vundle.vim
2324
>
2425
Plugin 'lucerion/vim-extract'
2526
Plugin 'lucerion/vim-buffr'
2627
<
27-
Pathogen https://github.com/tpope/vim-pathogen
28+
Pathogen https://github.com/tpope/vim-pathogen
2829
>
2930
cd ~/.vim/bundle
3031
git clone https://github.com/lucerion/vim-extract
3132
git clone https://github.com/lucerion/vim-buffr
3233
<
33-
NeoBundle https://github.com/Shougo/neobundle.vim
34+
NeoBundle https://github.com/Shougo/neobundle.vim
3435
>
3536
NeoBundle 'lucerion/vim-extract'
3637
NeoBundle 'lucerion/vim-buffr'
3738
<
38-
vim-plug https://github.com/junegunn/vim-plug
39+
vim-plug https://github.com/junegunn/vim-plug
3940
>
4041
Plug 'lucerion/vim-extract'
4142
Plug 'lucerion/vim-buffr'
@@ -50,41 +51,53 @@ Manual
5051
===============================================================================
5152
COMMANDS *vim-extract-commands*
5253

53-
*:VExtract*
54-
:VExtract In Visual mode - extract selection to a buffer,
55-
in Normal mode - open the extract buffer.
54+
*:Extr*
55+
:[range]Extr {name} {position} or :[range]Extr {position} {name}
56+
57+
In Visual mode - extract selection to a buffer, in Normal mode - open
58+
the extract buffer. Buffer will be opened with {name} at {position}
59+
'name' and 'position' arguments are optional
60+
Without 'position' argument buffer will open with last opened position or
61+
will be opened with default position
62+
Possible {position} values: -top, -bottom, -left, -right, -tab
63+
Default {position} value: -top
5664

5765
===============================================================================
5866
OPTIONS *vim-extract-options*
5967

6068
*g:extract_name*
6169

62-
The name of the extract buffer. {filename} pattern will be replaced with
63-
the current file name.
70+
Pattern of the extract buffer name. {filename} will be replaced with current
71+
file name. Will be used if :Extr command was called without 'name' argument
6472

6573
Default: '_{filename}'
6674

67-
*g:extract_position*
68-
69-
The extract buffer position.
70-
71-
Possible values: 'top', 'bottom', 'left', 'right', 'tab'
72-
Default: 'top'
73-
7475
*g:extract_append*
7576

76-
Append selected text to the end of the extract buffer or clear the extract
77-
buffer before insert.
77+
Append selected text to the end of the extract buffer (1) or clear the extract
78+
buffer and insert selection (0)
7879

7980
Default: 1
8081

8182
===============================================================================
8283
CHANGELOG *vim-extract-changelog*
8384

85+
0.3.0 (2016-03-27)~
86+
vim-buffr plugin version 0.3 required
87+
88+
Features
89+
* position and buffer name arguments were added to command
90+
* allow range
91+
Fixes
92+
* buffr#open_or_create arguments were changed to dictionary
93+
* command VExtract was renamed to Extr
94+
* g:extract_position option was removed
95+
8496
0.2.0 (2016-02-05)~
8597
Fixes
86-
Change buffr#open to buffr#open_or_create
87-
Rename Extract to VExtract command (vim-rails plugin conflict)
98+
* buffr#open to buffr#open_or_create was changed
99+
* command Extract was renamed to VExtract (vim-rails plugin conflict)
100+
88101
0.1.0 (2015-12-06)~
89102
First release
90103

plugin/extract.vim

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Description: Extract selection to a new buffer
33
" Author: Alexander Skachko <[email protected]>
44
" Homepage: https://github.com/lucerion/vim-extract
5-
" Version: 0.2
5+
" Version: 0.3
66
" Licence: MIT
77
" ==============================================================
88

@@ -14,14 +14,35 @@ if !exists('g:extract_name')
1414
let g:extract_name = '_{filename}'
1515
endif
1616

17-
if !exists('g:extract_position')
18-
let g:extract_position = 'top'
19-
endif
20-
2117
if !exists('g:extract_append')
2218
let g:extract_append = 1
2319
endif
2420

25-
comm! -nargs=0 -range=0 VExtract call extract#extract(<line1>, <line2>)
21+
let s:allowed_args = ['-top', '-bottom', '-left', '-right', '-tab']
22+
23+
func! s:autocompletion(A, L, C)
24+
return s:allowed_args
25+
endfunc
26+
27+
func! s:extract(start_line, end_line, count, ...)
28+
let l:name_args_filter = 'index(s:allowed_args, v:val) < 0'
29+
let l:position_args_filter = 'index(s:allowed_args, v:val) >= 0'
30+
let l:name_args = filter(copy(a:000), l:name_args_filter)
31+
let l:position_args = filter(copy(a:000), l:position_args_filter)
32+
33+
let l:buffer_options = {}
34+
if len(l:name_args)
35+
let l:buffer_options['name'] = join(l:name_args)
36+
endif
37+
if len(l:position_args)
38+
let l:position_arg = get(l:position_args, -1)
39+
let l:buffer_options['position'] = substitute(l:position_arg, '-', '', 'g')
40+
endif
41+
42+
call extract#extract(a:start_line, a:end_line, a:count, l:buffer_options)
43+
endfunc
44+
45+
comm! -nargs=* -range=0 -complete=customlist,s:autocompletion Extr
46+
\ call s:extract(<line1>, <line2>, <count>, <f-args>)
2647

2748
let g:loaded_extract = 1

0 commit comments

Comments
 (0)