Skip to content

Commit 96539b3

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 960696e + f7edf40 commit 96539b3

File tree

15 files changed

+387
-45
lines changed

15 files changed

+387
-45
lines changed

runtime/doc/change.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*change.txt* For Vim version 7.4. Last change: 2016 Jan 02
1+
*change.txt* For Vim version 7.4. Last change: 2016 Jan 19
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1745,18 +1745,26 @@ Vim has a sorting function and a sorting command. The sorting function can be
17451745
found here: |sort()|, |uniq()|.
17461746

17471747
*:sor* *:sort*
1748-
:[range]sor[t][!] [i][u][r][n][x][o][b] [/{pattern}/]
1748+
:[range]sor[t][!] [b][f][i][n][o][r][u][x] [/{pattern}/]
17491749
Sort lines in [range]. When no range is given all
17501750
lines are sorted.
17511751

17521752
With [!] the order is reversed.
17531753

17541754
With [i] case is ignored.
17551755

1756+
Options [n][f][x][o][b] are mutually exclusive.
1757+
17561758
With [n] sorting is done on the first decimal number
17571759
in the line (after or inside a {pattern} match).
17581760
One leading '-' is included in the number.
17591761

1762+
With [f] sorting is done on the Float in the line.
1763+
The value of Float is determined similar to passing
1764+
the text (after or inside a {pattern} match) to
1765+
str2float() function. This option is available only
1766+
if Vim was compiled with Floating point support.
1767+
17601768
With [x] sorting is done on the first hexadecimal
17611769
number in the line (after or inside a {pattern}
17621770
match). A leading "0x" or "0X" is ignored.
@@ -1768,10 +1776,10 @@ found here: |sort()|, |uniq()|.
17681776
With [b] sorting is done on the first binary number in
17691777
the line (after or inside a {pattern} match).
17701778

1771-
With [u] only keep the first of a sequence of
1772-
identical lines (ignoring case when [i] is used).
1773-
Without this flag, a sequence of identical lines
1774-
will be kept in their original order.
1779+
With [u] (u stands for unique) only keep the first of
1780+
a sequence of identical lines (ignoring case when [i]
1781+
is used). Without this flag, a sequence of identical
1782+
lines will be kept in their original order.
17751783
Note that leading and trailing white space may cause
17761784
lines to be different.
17771785

runtime/doc/options.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 7.4. Last change: 2016 Jan 09
1+
*options.txt* For Vim version 7.4. Last change: 2016 Jan 19
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -4599,6 +4599,8 @@ A jump table for the options with a short description can be found at |Q_op|.
45994599
'*', '"' and '|' (so that CTRL-] on a command finds the help for that
46004600
command).
46014601
When the 'lisp' option is on the '-' character is always included.
4602+
This option also influences syntax highlighting, unless the syntax
4603+
uses |:syn-iskeyword|.
46024604
NOTE: This option is set to the Vi default value when 'compatible' is
46034605
set and to the Vim default value when 'compatible' is reset.
46044606

runtime/doc/syntax.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*syntax.txt* For Vim version 7.4. Last change: 2015 Dec 19
1+
*syntax.txt* For Vim version 7.4. Last change: 2016 Jan 19
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -3438,6 +3438,32 @@ SPELL CHECKING *:syn-spell*
34383438

34393439
To activate spell checking the 'spell' option must be set.
34403440

3441+
SYNTAX ISKEYWORD SETTING *:syn-iskeyword*
3442+
3443+
:sy[ntax] iskeyword [clear | {option}]
3444+
This defines the keyword characters. It's like the 'iskeyword' option
3445+
for but only applies to syntax highlighting.
3446+
3447+
clear: Syntax specific iskeyword setting is disabled and the
3448+
buffer-local 'iskeyword' setting is used.
3449+
{option} Set the syntax 'iskeyword' option to a new value.
3450+
3451+
Example: >
3452+
:syntax iskeyword @,48-57,192-255,$,_
3453+
<
3454+
This would set the syntax specific iskeyword option to include all
3455+
alphabetic characters, plus the numeric characters, all accented
3456+
characters and also includes the "_" and the "$".
3457+
3458+
If no argument is given, the current value will be output.
3459+
3460+
Setting this option influences what |/\k| matches in syntax patterns
3461+
and also determines where |:syn-keywords| will be checked for a new
3462+
match.
3463+
3464+
It is recommended when writing syntax files, to use this command
3465+
to the correct value for the specific syntax language and not change
3466+
the 'iskeyword' option.
34413467

34423468
DEFINING KEYWORDS *:syn-keyword*
34433469

@@ -3469,6 +3495,7 @@ DEFINING KEYWORDS *:syn-keyword*
34693495
isn't, the keyword will never be recognized.
34703496
Multi-byte characters can also be used. These do not have to be in
34713497
'iskeyword'.
3498+
See |:syn-iskeyword| for defining syntax specific iskeyword settings.
34723499

34733500
A keyword always has higher priority than a match or region, the
34743501
keyword is used if more than one item matches. Keywords do not nest

src/buffer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,7 @@ free_buf_options(buf, free_p_ff)
19591959
clear_string_option(&buf->b_p_nf);
19601960
#ifdef FEAT_SYN_HL
19611961
clear_string_option(&buf->b_p_syn);
1962+
clear_string_option(&buf->b_s.b_syn_isk);
19621963
#endif
19631964
#ifdef FEAT_SPELL
19641965
clear_string_option(&buf->b_s.b_p_spc);

src/eval.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,9 @@ static typval_T *alloc_tv __ARGS((void));
809809
static typval_T *alloc_string_tv __ARGS((char_u *string));
810810
static void init_tv __ARGS((typval_T *varp));
811811
static long get_tv_number __ARGS((typval_T *varp));
812+
#ifdef FEAT_FLOAT
813+
static float_T get_tv_float(typval_T *varp);
814+
#endif
812815
static linenr_T get_tv_lnum __ARGS((typval_T *argvars));
813816
static linenr_T get_tv_lnum_buf __ARGS((typval_T *argvars, buf_T *buf));
814817
static char_u *get_tv_string __ARGS((typval_T *varp));
@@ -18171,6 +18174,9 @@ typedef struct
1817118174
static int item_compare_ic;
1817218175
static int item_compare_numeric;
1817318176
static int item_compare_numbers;
18177+
#ifdef FEAT_FLOAT
18178+
static int item_compare_float;
18179+
#endif
1817418180
static char_u *item_compare_func;
1817518181
static dict_T *item_compare_selfdict;
1817618182
static int item_compare_func_err;
@@ -18210,6 +18216,16 @@ item_compare(s1, s2)
1821018216
return v1 == v2 ? 0 : v1 > v2 ? 1 : -1;
1821118217
}
1821218218

18219+
#ifdef FEAT_FLOAT
18220+
if (item_compare_float)
18221+
{
18222+
float_T v1 = get_tv_float(tv1);
18223+
float_T v2 = get_tv_float(tv2);
18224+
18225+
return v1 == v2 ? 0 : v1 > v2 ? 1 : -1;
18226+
}
18227+
#endif
18228+
1821318229
/* tv2string() puts quotes around a string and allocates memory. Don't do
1821418230
* that for string variables. Use a single quote when comparing with a
1821518231
* non-string to do what the docs promise. */
@@ -18344,6 +18360,9 @@ do_sort_uniq(argvars, rettv, sort)
1834418360
item_compare_ic = FALSE;
1834518361
item_compare_numeric = FALSE;
1834618362
item_compare_numbers = FALSE;
18363+
#ifdef FEAT_FLOAT
18364+
item_compare_float = FALSE;
18365+
#endif
1834718366
item_compare_func = NULL;
1834818367
item_compare_selfdict = NULL;
1834918368
if (argvars[1].v_type != VAR_UNKNOWN)
@@ -18374,6 +18393,13 @@ do_sort_uniq(argvars, rettv, sort)
1837418393
item_compare_func = NULL;
1837518394
item_compare_numbers = TRUE;
1837618395
}
18396+
#ifdef FEAT_FLOAT
18397+
else if (STRCMP(item_compare_func, "f") == 0)
18398+
{
18399+
item_compare_func = NULL;
18400+
item_compare_float = TRUE;
18401+
}
18402+
#endif
1837718403
else if (STRCMP(item_compare_func, "i") == 0)
1837818404
{
1837918405
item_compare_func = NULL;
@@ -21641,6 +21667,40 @@ get_tv_number_chk(varp, denote)
2164121667
return n;
2164221668
}
2164321669

21670+
#ifdef FEAT_FLOAT
21671+
static float_T
21672+
get_tv_float(varp)
21673+
typval_T *varp;
21674+
{
21675+
switch (varp->v_type)
21676+
{
21677+
case VAR_NUMBER:
21678+
return (float_T)(varp->vval.v_number);
21679+
#ifdef FEAT_FLOAT
21680+
case VAR_FLOAT:
21681+
return varp->vval.v_float;
21682+
break;
21683+
#endif
21684+
case VAR_FUNC:
21685+
EMSG(_("E891: Using a Funcref as a Float"));
21686+
break;
21687+
case VAR_STRING:
21688+
EMSG(_("E892: Using a String as a Float"));
21689+
break;
21690+
case VAR_LIST:
21691+
EMSG(_("E893: Using a List as a Float"));
21692+
break;
21693+
case VAR_DICT:
21694+
EMSG(_("E894: Using a Dictionary as a Float"));
21695+
break;
21696+
default:
21697+
EMSG2(_(e_intern2), "get_tv_float()");
21698+
break;
21699+
}
21700+
return 0;
21701+
}
21702+
#endif
21703+
2164421704
/*
2164521705
* Get the lnum from the first argument.
2164621706
* Also accepts ".", "$", etc., but that only works for the current buffer.

src/ex_cmds.c

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,30 @@ linelen(has_tab)
275275
static char_u *sortbuf1;
276276
static char_u *sortbuf2;
277277

278-
static int sort_ic; /* ignore case */
279-
static int sort_nr; /* sort on number */
280-
static int sort_rx; /* sort on regex instead of skipping it */
278+
static int sort_ic; /* ignore case */
279+
static int sort_nr; /* sort on number */
280+
static int sort_rx; /* sort on regex instead of skipping it */
281+
#ifdef FEAT_FLOAT
282+
static int sort_flt; /* sort on floating number */
283+
#endif
281284

282-
static int sort_abort; /* flag to indicate if sorting has been interrupted */
285+
static int sort_abort; /* flag to indicate if sorting has been interrupted */
283286

284287
/* Struct to store info to be sorted. */
285288
typedef struct
286289
{
287290
linenr_T lnum; /* line number */
288-
long start_col_nr; /* starting column number or number */
289-
long end_col_nr; /* ending column number */
291+
union {
292+
struct
293+
{
294+
long start_col_nr; /* starting column number */
295+
long end_col_nr; /* ending column number */
296+
} line;
297+
long value; /* value if sorting by integer */
298+
#ifdef FEAT_FLOAT
299+
float_T value_flt; /* value if sorting by float */
300+
#endif
301+
} st_u;
290302
} sorti_T;
291303

292304
static int
@@ -319,19 +331,24 @@ sort_compare(s1, s2)
319331
/* When sorting numbers "start_col_nr" is the number, not the column
320332
* number. */
321333
if (sort_nr)
322-
result = l1.start_col_nr == l2.start_col_nr ? 0
323-
: l1.start_col_nr > l2.start_col_nr ? 1 : -1;
334+
result = l1.st_u.value == l2.st_u.value ? 0
335+
: l1.st_u.value > l2.st_u.value ? 1 : -1;
336+
#ifdef FEAT_FLOAT
337+
else if (sort_flt)
338+
result = l1.st_u.value_flt == l2.st_u.value_flt ? 0
339+
: l1.st_u.value_flt > l2.st_u.value_flt ? 1 : -1;
340+
#endif
324341
else
325342
{
326343
/* We need to copy one line into "sortbuf1", because there is no
327344
* guarantee that the first pointer becomes invalid when obtaining the
328345
* second one. */
329-
STRNCPY(sortbuf1, ml_get(l1.lnum) + l1.start_col_nr,
330-
l1.end_col_nr - l1.start_col_nr + 1);
331-
sortbuf1[l1.end_col_nr - l1.start_col_nr] = 0;
332-
STRNCPY(sortbuf2, ml_get(l2.lnum) + l2.start_col_nr,
333-
l2.end_col_nr - l2.start_col_nr + 1);
334-
sortbuf2[l2.end_col_nr - l2.start_col_nr] = 0;
346+
STRNCPY(sortbuf1, ml_get(l1.lnum) + l1.st_u.line.start_col_nr,
347+
l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr + 1);
348+
sortbuf1[l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr] = 0;
349+
STRNCPY(sortbuf2, ml_get(l2.lnum) + l2.st_u.line.start_col_nr,
350+
l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr + 1);
351+
sortbuf2[l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr] = 0;
335352

336353
result = sort_ic ? STRICMP(sortbuf1, sortbuf2)
337354
: STRCMP(sortbuf1, sortbuf2);
@@ -382,6 +399,9 @@ ex_sort(eap)
382399
goto sortend;
383400

384401
sort_abort = sort_ic = sort_rx = sort_nr = 0;
402+
#ifdef FEAT_FLOAT
403+
sort_flt = 0;
404+
#endif
385405

386406
for (p = eap->arg; *p != NUL; ++p)
387407
{
@@ -393,9 +413,16 @@ ex_sort(eap)
393413
sort_rx = TRUE;
394414
else if (*p == 'n')
395415
{
396-
sort_nr = 2;
416+
sort_nr = 1;
397417
++format_found;
398418
}
419+
#ifdef FEAT_FLOAT
420+
else if (*p == 'f')
421+
{
422+
sort_flt = 1;
423+
++format_found;
424+
}
425+
#endif
399426
else if (*p == 'b')
400427
{
401428
sort_what = STR2NR_BIN + STR2NR_FORCE;
@@ -460,7 +487,8 @@ ex_sort(eap)
460487
goto sortend;
461488
}
462489

463-
/* From here on "sort_nr" is used as a flag for any number sorting. */
490+
/* From here on "sort_nr" is used as a flag for any integer number
491+
* sorting. */
464492
sort_nr += sort_what;
465493

466494
/*
@@ -494,7 +522,7 @@ ex_sort(eap)
494522
if (regmatch.regprog != NULL)
495523
end_col = 0;
496524

497-
if (sort_nr)
525+
if (sort_nr || sort_flt)
498526
{
499527
/* Make sure vim_str2nr doesn't read any digits past the end
500528
* of the match, by temporarily terminating the string there */
@@ -503,27 +531,45 @@ ex_sort(eap)
503531
*s2 = NUL;
504532
/* Sorting on number: Store the number itself. */
505533
p = s + start_col;
506-
if (sort_what & STR2NR_HEX)
507-
s = skiptohex(p);
508-
else if (sort_what & STR2NR_BIN)
509-
s = skiptobin(p);
510-
else
511-
s = skiptodigit(p);
512-
if (s > p && s[-1] == '-')
513-
--s; /* include preceding negative sign */
514-
if (*s == NUL)
515-
/* empty line should sort before any number */
516-
nrs[lnum - eap->line1].start_col_nr = -MAXLNUM;
534+
if (sort_nr)
535+
{
536+
if (sort_what & STR2NR_HEX)
537+
s = skiptohex(p);
538+
else if (sort_what & STR2NR_BIN)
539+
s = skiptobin(p);
540+
else
541+
s = skiptodigit(p);
542+
if (s > p && s[-1] == '-')
543+
--s; /* include preceding negative sign */
544+
if (*s == NUL)
545+
/* empty line should sort before any number */
546+
nrs[lnum - eap->line1].st_u.value = -MAXLNUM;
547+
else
548+
vim_str2nr(s, NULL, NULL, sort_what,
549+
&nrs[lnum - eap->line1].st_u.value, NULL, 0);
550+
}
551+
#ifdef FEAT_FLOAT
517552
else
518-
vim_str2nr(s, NULL, NULL, sort_what,
519-
&nrs[lnum - eap->line1].start_col_nr, NULL, 0);
553+
{
554+
s = skipwhite(p);
555+
if (*s == '+')
556+
s = skipwhite(s + 1);
557+
558+
if (*s == NUL)
559+
/* empty line should sort before any number */
560+
nrs[lnum - eap->line1].st_u.value_flt = -DBL_MAX;
561+
else
562+
nrs[lnum - eap->line1].st_u.value_flt =
563+
strtod((char *)s, NULL);
564+
}
565+
#endif
520566
*s2 = c;
521567
}
522568
else
523569
{
524570
/* Store the column to sort at. */
525-
nrs[lnum - eap->line1].start_col_nr = start_col;
526-
nrs[lnum - eap->line1].end_col_nr = end_col;
571+
nrs[lnum - eap->line1].st_u.line.start_col_nr = start_col;
572+
nrs[lnum - eap->line1].st_u.line.end_col_nr = end_col;
527573
}
528574

529575
nrs[lnum - eap->line1].lnum = lnum;

0 commit comments

Comments
 (0)