Hi Bram!
On Mi, 25 Jun 2014, Bram Moolenaar wrote:
> > + /* pattern did not match in any line, skip sorting */
> > + if (skip_sort == eap->line2)
> > + goto sortend;
>
> I don't think this works when eap->line1 is not 1, sorting a range of
> lines.
Indeed. Here is the correct version.
Best,
Christian
--
Wußten Sie schon...
... daß Teigwaren Teigwaren heißen, weil Teigwaren vorher Teig waren?
--
--
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/ex_cmds.c b/src/ex_cmds.c
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -366,6 +366,7 @@ ex_sort(eap)
colnr_T end_col;
int sort_oct; /* sort on octal number */
int sort_hex; /* sort on hex number */
+ int skip_sort = FALSE;
/* Sorting one line is really quick! */
if (count <= 1)
@@ -495,8 +496,11 @@ ex_sort(eap)
if (s > p && s[-1] == '-')
--s; /* include preceding negative sign */
if (*s == NUL)
+ {
/* empty line should sort before any number */
nrs[lnum - eap->line1].start_col_nr = -MAXLNUM;
+ skip_sort += 1;
+ }
else
vim_str2nr(s, NULL, NULL, sort_oct, sort_hex,
&nrs[lnum - eap->line1].start_col_nr, NULL);
@@ -507,6 +511,7 @@ ex_sort(eap)
/* Store the column to sort at. */
nrs[lnum - eap->line1].start_col_nr = start_col;
nrs[lnum - eap->line1].end_col_nr = end_col;
+ skip_sort += (end_col == 0 && start_col == 0 ? 1 : 0);
}
nrs[lnum - eap->line1].lnum = lnum;
@@ -516,6 +521,9 @@ ex_sort(eap)
if (got_int)
goto sortend;
}
+ /* pattern did not match in any line, skip sorting */
+ if (skip_sort == eap->line2 - eap->line1 + 1)
+ goto sortend;
/* Allocate a buffer that can hold the longest line. */
sortbuf1 = alloc((unsigned)maxlen + 1);