Skip to content

Commit 7c69d81

Browse files
committed
Remove position and default file name options
Use window split modes instead of position
1 parent 930b7df commit 7c69d81

3 files changed

Lines changed: 16 additions & 69 deletions

File tree

autoload/extract.vim

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
" ==============================================================
88

99
func! extract#extract(selection, buffer_options) abort
10-
if exists('g:loaded_buffr')
11-
call s:extract(a:selection, a:buffer_options)
12-
else
10+
if !exists('g:loaded_buffr')
1311
call s:show_error('Please, install vim-buffr') | return
1412
endif
13+
14+
call s:extract(a:selection, a:buffer_options)
1515
endfunc
1616

1717
func! s:extract(selection, buffer_options) abort
@@ -37,23 +37,14 @@ func! s:extract(selection, buffer_options) abort
3737
endfunc
3838

3939
func! s:open_buffer(buffer_options) abort
40-
let l:buffer_options = s:buffer_options(a:buffer_options)
41-
call buffr#open_or_create_buffer(l:buffer_options)
42-
call s:set_buffer_defaults(l:buffer_options)
40+
call buffr#open_or_create_buffer(a:buffer_options.name, a:buffer_options.mods)
41+
call s:set_buffer_defaults(a:buffer_options)
4342
endfunc
4443

4544
func! s:close_buffer() abort
4645
silent exec 'close'
4746
endfunc
4847

49-
func! s:buffer_options(buffer_options) abort
50-
let l:default_buffer_options = {
51-
\ 'name': substitute(g:extract_buffer_name, '{filename}', expand('%:t'), 'g')
52-
\ }
53-
54-
return extend(l:default_buffer_options, a:buffer_options)
55-
endfunc
56-
5748
func! s:clear_buffer() abort
5849
call s:delete_lines(1, '$')
5950
endfunc
@@ -67,6 +58,7 @@ func! s:insert_selection(selection) abort
6758
call append(l:last_line, a:selection)
6859
silent exec 'normal! G'
6960
endif
61+
7062
endfunc
7163

7264
func! s:delete_lines(start_line, end_line) abort

doc/vim-extract.txt

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,17 @@ COMMANDS *vim-extract-commands*
5353

5454
*:Extr*
5555

56-
:[range]Extr[!] {position} {buffer-name}
56+
:[range]Extr[!] {buffer-name}
5757

5858
In the Visual mode - extracts selection to a new buffer, in the Normal
5959
mode - opens an extract buffer.
6060
If `!` is given buffer will be cleared before selection insert.
61-
Without 'position' argument an extract buffer will be opened with the last
62-
or default position.
63-
64-
Positions: -top, -bottom, -left, -right, -tab
65-
Default position: -top
61+
Window split modes (|leftabove|, |rightbelow|, |topleft|, |botright|,
62+
|vsplit|, |tab|, etc) are available.
6663

6764
===============================================================================
6865
OPTIONS *vim-extract-options*
6966

70-
*g:extract_default_position*
71-
72-
Default extract buffer position.
73-
74-
Possible values: 'top', 'bottom', 'left', 'right', 'tab'
75-
Default value: 'top'
76-
77-
*g:extract_buffer_name*
78-
79-
Extract buffer name pattern. {filename} string replaces with the current filename
80-
name. This option uses if :Extr command called without 'name' argument.
81-
82-
Default value: '_{filename}'
83-
84-
*g:extract_append*
85-
86-
Append selection to the end of the extract buffer (1) or clear the extract
87-
buffer before insert (0).
88-
89-
Default value: 1
90-
9167
*g:extract_hidden*
9268

9369
Extract selection without opening the extract buffer.

plugin/extract.vim

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,24 @@ if exists('g:loaded_extract') || &compatible || v:version < 700
1111
endif
1212
let g:loaded_extract = 1
1313

14-
if !exists('g:extract_buffer_name')
15-
let g:extract_buffer_name = '_{filename}'
16-
endif
17-
1814
if !exists('g:extract_hidden')
1915
let g:extract_hidden = 0
2016
endif
2117

22-
if !exists('g:extract_default_position')
23-
let g:extract_default_position = 'top'
24-
endif
25-
26-
let s:allowed_position_args = ['-top', '-bottom', '-left', '-right', '-tab']
27-
28-
func! s:autocompletion(input, command_line, cursor_position) abort
29-
return filter(s:allowed_args, 'v:val =~ a:input')
30-
endfunc
31-
32-
func! s:extract(start_line, end_line, count, clear, ...) abort
18+
func! s:extract(start_line, end_line, count, clear, mods, name) abort
3319
let l:selection = {
3420
\ 'start_line': a:start_line,
3521
\ 'end_line': a:end_line,
3622
\ 'count': a:count
3723
\ }
38-
let l:buffer_options = { 'clear': a:clear }
3924

40-
let l:name_args = filter(copy(a:000), 'index(s:allowed_position_args, v:val) < 0')
41-
if len(l:name_args)
42-
let l:buffer_options.name = join(l:name_args)
43-
endif
44-
45-
let l:buffer_options.position = g:extract_default_position
46-
let l:position_args = filter(copy(a:000), 'index(s:allowed_position_args, v:val) >= 0')
47-
if len(l:position_args)
48-
let l:buffer_options.position = substitute(l:position_args[-1], '-', '', 'g')
49-
endif
25+
let l:buffer_options = {
26+
\ 'name': a:name,
27+
\ 'clear': a:clear,
28+
\ 'mods': a:mods
29+
\ }
5030

5131
call extract#extract(l:selection, l:buffer_options)
5232
endfunc
5333

54-
comm! -nargs=* -range=0 -bang -complete=customlist,s:autocompletion Extr
55-
\ call s:extract(<line1>, <line2>, <count>, !empty('<bang>'), <f-args>)
34+
comm! -nargs=? -range=0 -bang Extr call s:extract(<line1>, <line2>, <count>, !empty('<bang>'), <q-mods>, <q-args>)

0 commit comments

Comments
 (0)