Hi Bram,
On Sun, Jan 8, 2017 at 9:12 AM, Bram Moolenaar <[email protected]> wrote:
>
> Yegappan wrote:
>
>> On Sun, Jan 8, 2017 at 4:26 AM, Bram Moolenaar <[email protected]> wrote:
>> >
>> > Patch 8.0.0151
>> > Problem: To pass buffer content to system() and systemlist() one has to
>> > first create a string or list.
>> > Solution: Allow passing a buffer number. (LemonBoy, closes #1240)
>> >
>>
>> Currently only the entire buffer can be used to the external command.
>> Does it make sense to also support specifying a range of lines to
>> be passed to the command? The default is the entire buffer.
>
> Yeah, I also wondered if that would be useful. In case it is, we could
> pass a dict argument with the range.
> {'bufnr': bufnr('%'), 'start': 2, 'end': line('$') - 1}
>
I was thinking more along the lines of
system("cmd", bufnr, begin_lnum, end_lnum)
The attached patch implements this.
- Yegappan
>
> Leaving out "start" would mean the first line.
> Leaving out "end" would mean the last line.
>
> This is more complicated to implement, and it's already possible to use
> a list from getline(), thus I would not do it unless one can give an
> example of where this would actually be used.
>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/evalfunc.c b/src/evalfunc.c
index f66fa9a..3c0ceb7 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -801,8 +801,8 @@ static struct fst
{"synIDtrans", 1, 1, f_synIDtrans},
{"synconcealed", 2, 2, f_synconcealed},
{"synstack", 2, 2, f_synstack},
- {"system", 1, 2, f_system},
- {"systemlist", 1, 2, f_systemlist},
+ {"system", 1, 4, f_system},
+ {"systemlist", 1, 4, f_systemlist},
{"tabpagebuflist", 0, 1, f_tabpagebuflist},
{"tabpagenr", 0, 1, f_tabpagenr},
{"tabpagewinnr", 1, 2, f_tabpagewinnr},
@@ -11848,6 +11848,7 @@ get_cmd_output_as_rettv(
if (argvars[1].v_type == VAR_NUMBER)
{
linenr_T lnum;
+ linenr_T begin_lnum, end_lnum;
buf_T *buf;
buf = buflist_findnr(argvars[1].vval.v_number);
@@ -11857,7 +11858,25 @@ get_cmd_output_as_rettv(
goto errret;
}
- for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++)
+ begin_lnum = 1;
+ end_lnum = buf->b_ml.ml_line_count;
+ if (argvars[2].v_type == VAR_NUMBER)
+ {
+ begin_lnum = get_tv_lnum_buf(&argvars[2], buf);
+ if (argvars[3].v_type == VAR_NUMBER)
+ {
+ end_lnum = get_tv_lnum_buf(&argvars[3], buf);
+ if (end_lnum > buf->b_ml.ml_line_count)
+ end_lnum = buf->b_ml.ml_line_count;
+ }
+ if (begin_lnum < 1 || end_lnum < begin_lnum)
+ {
+ EMSG(_(e_invarg));
+ goto errret;
+ }
+ }
+
+ for (lnum = begin_lnum; lnum <= end_lnum; lnum++)
{
for (p = ml_get_buf(buf, lnum, FALSE); *p != NUL; ++p)
if (putc(*p == '\n' ? NUL : *p, fd) == EOF)