Skip to content

Commit fa4b303

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents dd0a84c + 0107f5b commit fa4b303

File tree

19 files changed

+662
-708
lines changed

19 files changed

+662
-708
lines changed

runtime/doc/eval.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 7.4. Last change: 2015 Dec 03
1+
*eval.txt* For Vim version 7.4. Last change: 2015 Dec 28
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -5228,21 +5228,28 @@ search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()*
52285228
move. No error message is given.
52295229

52305230
{flags} is a String, which can contain these character flags:
5231-
'b' search backward instead of forward
5232-
'c' accept a match at the cursor position
5231+
'b' search Backward instead of forward
5232+
'c' accept a match at the Cursor position
52335233
'e' move to the End of the match
52345234
'n' do Not move the cursor
5235-
'p' return number of matching sub-pattern (see below)
5236-
's' set the ' mark at the previous location of the cursor
5237-
'w' wrap around the end of the file
5238-
'W' don't wrap around the end of the file
5235+
'p' return number of matching sub-Pattern (see below)
5236+
's' Set the ' mark at the previous location of the cursor
5237+
'w' Wrap around the end of the file
5238+
'W' don't Wrap around the end of the file
5239+
'z' start searching at the cursor column instead of zero
52395240
If neither 'w' or 'W' is given, the 'wrapscan' option applies.
52405241

52415242
If the 's' flag is supplied, the ' mark is set, only if the
52425243
cursor is moved. The 's' flag cannot be combined with the 'n'
52435244
flag.
52445245

52455246
'ignorecase', 'smartcase' and 'magic' are used.
5247+
5248+
When the 'z' flag is not given seaching always starts in
5249+
column zero and then matches before the cursor are skipped.
5250+
When the 'c' flag is present in 'cpo' the next search starts
5251+
after the match. Without the 'c' flag the next search starts
5252+
one column further.
52465253

52475254
When the {stopline} argument is given then the search stops
52485255
after searching this line. This is useful to restrict the

src/eval.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16499,6 +16499,7 @@ f_reverse(argvars, rettv)
1649916499
#define SP_START 0x10 /* accept match at start position */
1650016500
#define SP_SUBPAT 0x20 /* return nr of matching sub-pattern */
1650116501
#define SP_END 0x40 /* leave cursor at end of match */
16502+
#define SP_COLUMN 0x80 /* start at cursor column */
1650216503

1650316504
static int get_search_arg __ARGS((typval_T *varp, int *flagsp));
1650416505

@@ -16540,6 +16541,7 @@ get_search_arg(varp, flagsp)
1654016541
case 'p': mask = SP_SUBPAT; break;
1654116542
case 'r': mask = SP_REPEAT; break;
1654216543
case 's': mask = SP_SETPCMARK; break;
16544+
case 'z': mask = SP_COLUMN; break;
1654316545
}
1654416546
if (mask == 0)
1654516547
{
@@ -16558,7 +16560,7 @@ get_search_arg(varp, flagsp)
1655816560
}
1655916561

1656016562
/*
16561-
* Shared by search() and searchpos() functions
16563+
* Shared by search() and searchpos() functions.
1656216564
*/
1656316565
static int
1656416566
search_cmn(argvars, match_pos, flagsp)
@@ -16590,6 +16592,8 @@ search_cmn(argvars, match_pos, flagsp)
1659016592
options |= SEARCH_START;
1659116593
if (flags & SP_END)
1659216594
options |= SEARCH_END;
16595+
if (flags & SP_COLUMN)
16596+
options |= SEARCH_COL;
1659316597

1659416598
/* Optional arguments: line number to stop searching and timeout. */
1659516599
if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN)
@@ -23119,7 +23123,11 @@ ex_function(eap)
2311923123

2312023124
/* insert the new function in the function list */
2312123125
STRCPY(fp->uf_name, name);
23122-
hash_add(&func_hashtab, UF2HIKEY(fp));
23126+
if (hash_add(&func_hashtab, UF2HIKEY(fp)) == FAIL)
23127+
{
23128+
vim_free(fp);
23129+
goto erret;
23130+
}
2312323131
}
2312423132
fp->uf_args = newargs;
2312523133
fp->uf_lines = newlines;

src/if_ruby.c

Lines changed: 101 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
# define RUBY19_OR_LATER 1
8282
#endif
8383

84+
#if (defined(RUBY_VERSION) && RUBY_VERSION >= 20) \
85+
|| (defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 20)
86+
# define RUBY20_OR_LATER 1
87+
#endif
88+
8489
#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 19
8590
/* Ruby 1.9 defines a number of static functions which use rb_num2long and
8691
* rb_int2big */
@@ -103,7 +108,6 @@
103108
#endif
104109
#if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22
105110
# define rb_gc_writebarrier_unprotect rb_gc_writebarrier_unprotect_stub
106-
# define rb_check_type rb_check_type_stub
107111
#endif
108112

109113
#ifdef FEAT_GUI_MACVIM
@@ -130,6 +134,16 @@
130134
# define __OPENTRANSPORTPROVIDERS__
131135
#endif
132136

137+
/*
138+
* The TypedData_XXX macro family can be used since Ruby 1.9.2 but
139+
* rb_data_type_t changed in 1.9.3, therefore require at least 2.0.
140+
* The old Data_XXX macro family was deprecated on Ruby 2.2.
141+
* Use TypedData_XXX if available.
142+
*/
143+
#if defined(TypedData_Wrap_Struct) && defined(RUBY20_OR_LATER)
144+
# define USE_TYPEDDATA 1
145+
#endif
146+
133147
/*
134148
* Backward compatibility for Ruby 1.8 and earlier.
135149
* Ruby 1.9 does not provide STR2CSTR, instead StringValuePtr is provided.
@@ -192,11 +206,20 @@ static void ruby_vim_init(void);
192206
*/
193207
# define rb_assoc_new dll_rb_assoc_new
194208
# define rb_cObject (*dll_rb_cObject)
195-
# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER < 22
196-
# define rb_check_type dll_rb_check_type
209+
# define rb_check_type dll_rb_check_type
210+
# ifdef USE_TYPEDDATA
211+
# define rb_check_typeddata dll_rb_check_typeddata
197212
# endif
198213
# define rb_class_path dll_rb_class_path
199-
# define rb_data_object_alloc dll_rb_data_object_alloc
214+
# ifdef USE_TYPEDDATA
215+
# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23
216+
# define rb_data_typed_object_wrap dll_rb_data_typed_object_wrap
217+
# else
218+
# define rb_data_typed_object_alloc dll_rb_data_typed_object_alloc
219+
# endif
220+
# else
221+
# define rb_data_object_alloc dll_rb_data_object_alloc
222+
# endif
200223
# define rb_define_class_under dll_rb_define_class_under
201224
# define rb_define_const dll_rb_define_const
202225
# define rb_define_global_function dll_rb_define_global_function
@@ -305,8 +328,19 @@ static VALUE *dll_rb_cObject;
305328
VALUE *dll_rb_cSymbol;
306329
VALUE *dll_rb_cTrueClass;
307330
static void (*dll_rb_check_type) (VALUE,int);
331+
# ifdef USE_TYPEDDATA
332+
static void *(*dll_rb_check_typeddata) (VALUE,const rb_data_type_t *);
333+
# endif
308334
static VALUE (*dll_rb_class_path) (VALUE);
335+
# ifdef USE_TYPEDDATA
336+
# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23
337+
static VALUE (*dll_rb_data_typed_object_wrap) (VALUE, void*, const rb_data_type_t *);
338+
# else
339+
static VALUE (*dll_rb_data_typed_object_alloc) (VALUE, void*, const rb_data_type_t *);
340+
# endif
341+
# else
309342
static VALUE (*dll_rb_data_object_alloc) (VALUE, void*, RUBY_DATA_FUNC, RUBY_DATA_FUNC);
343+
# endif
310344
static VALUE (*dll_rb_define_class_under) (VALUE, const char*, VALUE);
311345
static void (*dll_rb_define_const) (VALUE,const char*,VALUE);
312346
static void (*dll_rb_define_global_function) (const char*,VALUE(*)(),int);
@@ -459,13 +493,6 @@ void rb_gc_writebarrier_unprotect_stub(VALUE obj)
459493
# endif
460494
# endif
461495

462-
# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 22
463-
void rb_check_type_stub(VALUE v, int i)
464-
{
465-
dll_rb_check_type(v, i);
466-
}
467-
# endif
468-
469496
static HINSTANCE hinstRuby = NULL; /* Instance of ruby.dll */
470497

471498
/*
@@ -488,8 +515,19 @@ static struct
488515
{"rb_cSymbol", (RUBY_PROC*)&dll_rb_cSymbol},
489516
{"rb_cTrueClass", (RUBY_PROC*)&dll_rb_cTrueClass},
490517
{"rb_check_type", (RUBY_PROC*)&dll_rb_check_type},
518+
# ifdef USE_TYPEDDATA
519+
{"rb_check_typeddata", (RUBY_PROC*)&dll_rb_check_typeddata},
520+
# endif
491521
{"rb_class_path", (RUBY_PROC*)&dll_rb_class_path},
522+
# ifdef USE_TYPEDDATA
523+
# if defined(DYNAMIC_RUBY_VER) && DYNAMIC_RUBY_VER >= 23
524+
{"rb_data_typed_object_wrap", (RUBY_PROC*)&dll_rb_data_typed_object_wrap},
525+
# else
526+
{"rb_data_typed_object_alloc", (RUBY_PROC*)&dll_rb_data_typed_object_alloc},
527+
# endif
528+
# else
492529
{"rb_data_object_alloc", (RUBY_PROC*)&dll_rb_data_object_alloc},
530+
# endif
493531
{"rb_define_class_under", (RUBY_PROC*)&dll_rb_define_class_under},
494532
{"rb_define_const", (RUBY_PROC*)&dll_rb_define_const},
495533
{"rb_define_global_function", (RUBY_PROC*)&dll_rb_define_global_function},
@@ -1034,6 +1072,24 @@ static VALUE vim_evaluate(VALUE self UNUSED, VALUE str)
10341072
#endif
10351073
}
10361074

1075+
#ifdef USE_TYPEDDATA
1076+
static size_t buffer_dsize(const void *buf);
1077+
1078+
static const rb_data_type_t buffer_type = {
1079+
"vim_buffer",
1080+
{0, 0, buffer_dsize, {0, 0}},
1081+
0, 0,
1082+
# ifdef RUBY_TYPED_FREE_IMMEDIATELY
1083+
0,
1084+
# endif
1085+
};
1086+
1087+
static size_t buffer_dsize(const void *buf UNUSED)
1088+
{
1089+
return sizeof(buf_T);
1090+
}
1091+
#endif
1092+
10371093
static VALUE buffer_new(buf_T *buf)
10381094
{
10391095
if (buf->b_ruby_ref)
@@ -1042,7 +1098,11 @@ static VALUE buffer_new(buf_T *buf)
10421098
}
10431099
else
10441100
{
1101+
#ifdef USE_TYPEDDATA
1102+
VALUE obj = TypedData_Wrap_Struct(cBuffer, &buffer_type, buf);
1103+
#else
10451104
VALUE obj = Data_Wrap_Struct(cBuffer, 0, 0, buf);
1105+
#endif
10461106
buf->b_ruby_ref = (void *) obj;
10471107
rb_hash_aset(objtbl, rb_obj_id(obj), obj);
10481108
return obj;
@@ -1053,7 +1113,11 @@ static buf_T *get_buf(VALUE obj)
10531113
{
10541114
buf_T *buf;
10551115

1116+
#ifdef USE_TYPEDDATA
1117+
TypedData_Get_Struct(obj, buf_T, &buffer_type, buf);
1118+
#else
10561119
Data_Get_Struct(obj, buf_T, buf);
1120+
#endif
10571121
if (buf == NULL)
10581122
rb_raise(eDeletedBufferError, "attempt to refer to deleted buffer");
10591123
return buf;
@@ -1250,6 +1314,24 @@ static VALUE buffer_append(VALUE self, VALUE num, VALUE str)
12501314
return str;
12511315
}
12521316

1317+
#ifdef USE_TYPEDDATA
1318+
static size_t window_dsize(const void *buf);
1319+
1320+
static const rb_data_type_t window_type = {
1321+
"vim_window",
1322+
{0, 0, window_dsize, {0, 0}},
1323+
0, 0,
1324+
# ifdef RUBY_TYPED_FREE_IMMEDIATELY
1325+
0,
1326+
# endif
1327+
};
1328+
1329+
static size_t window_dsize(const void *win UNUSED)
1330+
{
1331+
return sizeof(win_T);
1332+
}
1333+
#endif
1334+
12531335
static VALUE window_new(win_T *win)
12541336
{
12551337
if (win->w_ruby_ref)
@@ -1258,7 +1340,11 @@ static VALUE window_new(win_T *win)
12581340
}
12591341
else
12601342
{
1343+
#ifdef USE_TYPEDDATA
1344+
VALUE obj = TypedData_Wrap_Struct(cVimWindow, &window_type, win);
1345+
#else
12611346
VALUE obj = Data_Wrap_Struct(cVimWindow, 0, 0, win);
1347+
#endif
12621348
win->w_ruby_ref = (void *) obj;
12631349
rb_hash_aset(objtbl, rb_obj_id(obj), obj);
12641350
return obj;
@@ -1269,7 +1355,11 @@ static win_T *get_win(VALUE obj)
12691355
{
12701356
win_T *win;
12711357

1358+
#ifdef USE_TYPEDDATA
1359+
TypedData_Get_Struct(obj, win_T, &window_type, win);
1360+
#else
12721361
Data_Get_Struct(obj, win_T, win);
1362+
#endif
12731363
if (win == NULL)
12741364
rb_raise(eDeletedWindowError, "attempt to refer to deleted window");
12751365
return win;

src/search.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ last_pat_prog(regmatch)
587587
* if (options & SEARCH_KEEP) keep previous search pattern
588588
* if (options & SEARCH_FOLD) match only once in a closed fold
589589
* if (options & SEARCH_PEEK) check for typed char, cancel search
590+
* if (options & SEARCH_COL) start at pos->col instead of zero
590591
*
591592
* Return FAIL (zero) for failure, non-zero for success.
592593
* When FEAT_EVAL is defined, returns the index of the first matching
@@ -608,6 +609,7 @@ searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm)
608609
{
609610
int found;
610611
linenr_T lnum; /* no init to shut up Apollo cc */
612+
colnr_T col;
611613
regmmatch_T regmatch;
612614
char_u *ptr;
613615
colnr_T matchcol;
@@ -720,12 +722,14 @@ searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm)
720722
/*
721723
* Look for a match somewhere in line "lnum".
722724
*/
725+
col = at_first_line && (options & SEARCH_COL) ? pos->col
726+
: (colnr_T)0;
723727
nmatched = vim_regexec_multi(&regmatch, win, buf,
724-
lnum, (colnr_T)0,
728+
lnum, col,
725729
#ifdef FEAT_RELTIME
726-
tm
730+
tm
727731
#else
728-
NULL
732+
NULL
729733
#endif
730734
);
731735
/* Abort searching on an error (e.g., out of stack). */
@@ -1107,6 +1111,7 @@ set_vv_searchforward()
11071111

11081112
/*
11091113
* Return the number of the first subpat that matched.
1114+
* Return zero if none of them matched.
11101115
*/
11111116
static int
11121117
first_submatch(rp)

0 commit comments

Comments
 (0)