Skip to content

Commit bbfcd01

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 3611fbf + bb09ceb commit bbfcd01

12 files changed

+147
-47
lines changed

src/auto/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12122,7 +12122,7 @@ for ac_func in bcmp fchdir fchown fsync getcwd getpseudotty \
1212212122
getpwent getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
1212312123
memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
1212412124
setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
12125-
sigvec strcasecmp strerror strftime stricmp strncasecmp \
12125+
sigprocmask sigvec strcasecmp strerror strftime stricmp strncasecmp \
1212612126
strnicmp strpbrk strtol tgetent towlower towupper iswupper \
1212712127
usleep utime utimes
1212812128
do :

src/config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
#undef HAVE_SIGSET
191191
#undef HAVE_SIGSETJMP
192192
#undef HAVE_SIGSTACK
193+
#undef HAVE_SIGPROCMASK
193194
#undef HAVE_SIGVEC
194195
#undef HAVE_SMACK
195196
#undef HAVE_STRCASECMP

src/configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3677,7 +3677,7 @@ AC_CHECK_FUNCS(bcmp fchdir fchown fsync getcwd getpseudotty \
36773677
getpwent getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
36783678
memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
36793679
setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
3680-
sigvec strcasecmp strerror strftime stricmp strncasecmp \
3680+
sigprocmask sigvec strcasecmp strerror strftime stricmp strncasecmp \
36813681
strnicmp strpbrk strtol tgetent towlower towupper iswupper \
36823682
usleep utime utimes)
36833683
AC_FUNC_FSEEKO

src/diff.c

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,7 @@ ex_diffsplit(exarg_T *eap)
11001100
if (bufref_valid(&old_curbuf))
11011101
/* Move the cursor position to that of the old window. */
11021102
curwin->w_cursor.lnum = diff_get_corresponding_line(
1103-
old_curbuf.br_buf,
1104-
old_curwin->w_cursor.lnum,
1105-
curbuf,
1106-
curwin->w_cursor.lnum);
1103+
old_curbuf.br_buf, old_curwin->w_cursor.lnum);
11071104
}
11081105
/* Now that lines are folded scroll to show the cursor at the same
11091106
* relative position. */
@@ -2524,21 +2521,22 @@ diff_move_to(int dir, long count)
25242521
return OK;
25252522
}
25262523

2527-
linenr_T
2528-
diff_get_corresponding_line(
2524+
/*
2525+
* Return the line number in the current window that is closest to "lnum1" in
2526+
* "buf1" in diff mode.
2527+
*/
2528+
static linenr_T
2529+
diff_get_corresponding_line_int(
25292530
buf_T *buf1,
2530-
linenr_T lnum1,
2531-
buf_T *buf2,
2532-
linenr_T lnum3)
2531+
linenr_T lnum1)
25332532
{
25342533
int idx1;
25352534
int idx2;
25362535
diff_T *dp;
25372536
int baseline = 0;
2538-
linenr_T lnum2;
25392537

25402538
idx1 = diff_buf_idx(buf1);
2541-
idx2 = diff_buf_idx(buf2);
2539+
idx2 = diff_buf_idx(curbuf);
25422540
if (idx1 == DB_COUNT || idx2 == DB_COUNT || curtab->tp_first_diff == NULL)
25432541
return lnum1;
25442542

@@ -2551,15 +2549,8 @@ diff_get_corresponding_line(
25512549
for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next)
25522550
{
25532551
if (dp->df_lnum[idx1] > lnum1)
2554-
{
2555-
lnum2 = lnum1 - baseline;
2556-
/* don't end up past the end of the file */
2557-
if (lnum2 > buf2->b_ml.ml_line_count)
2558-
lnum2 = buf2->b_ml.ml_line_count;
2559-
2560-
return lnum2;
2561-
}
2562-
else if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1)
2552+
return lnum1 - baseline;
2553+
if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1)
25632554
{
25642555
/* Inside the diffblock */
25652556
baseline = lnum1 - dp->df_lnum[idx1];
@@ -2568,29 +2559,40 @@ diff_get_corresponding_line(
25682559

25692560
return dp->df_lnum[idx2] + baseline;
25702561
}
2571-
else if ( (dp->df_lnum[idx1] == lnum1)
2572-
&& (dp->df_count[idx1] == 0)
2573-
&& (dp->df_lnum[idx2] <= lnum3)
2574-
&& ((dp->df_lnum[idx2] + dp->df_count[idx2]) > lnum3))
2562+
if ( (dp->df_lnum[idx1] == lnum1)
2563+
&& (dp->df_count[idx1] == 0)
2564+
&& (dp->df_lnum[idx2] <= curwin->w_cursor.lnum)
2565+
&& ((dp->df_lnum[idx2] + dp->df_count[idx2])
2566+
> curwin->w_cursor.lnum))
25752567
/*
25762568
* Special case: if the cursor is just after a zero-count
25772569
* block (i.e. all filler) and the target cursor is already
25782570
* inside the corresponding block, leave the target cursor
25792571
* unmoved. This makes repeated CTRL-W W operations work
25802572
* as expected.
25812573
*/
2582-
return lnum3;
2574+
return curwin->w_cursor.lnum;
25832575
baseline = (dp->df_lnum[idx1] + dp->df_count[idx1])
25842576
- (dp->df_lnum[idx2] + dp->df_count[idx2]);
25852577
}
25862578

25872579
/* If we get here then the cursor is after the last diff */
2588-
lnum2 = lnum1 - baseline;
2589-
/* don't end up past the end of the file */
2590-
if (lnum2 > buf2->b_ml.ml_line_count)
2591-
lnum2 = buf2->b_ml.ml_line_count;
2580+
return lnum1 - baseline;
2581+
}
25922582

2593-
return lnum2;
2583+
/*
2584+
* Return the line number in the current window that is closest to "lnum1" in
2585+
* "buf1" in diff mode. Checks the line number to be valid.
2586+
*/
2587+
linenr_T
2588+
diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1)
2589+
{
2590+
linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1);
2591+
2592+
/* don't end up past the end of the file */
2593+
if (lnum > curbuf->b_ml.ml_line_count)
2594+
return curbuf->b_ml.ml_line_count;
2595+
return lnum;
25942596
}
25952597

25962598
#if defined(FEAT_FOLDING) || defined(PROTO)

src/edit.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4648,14 +4648,19 @@ ins_compl_get_exp(pos_T *ini)
46484648
static void
46494649
ins_compl_delete(void)
46504650
{
4651-
int i;
4651+
int col;
46524652

46534653
/*
46544654
* In insert mode: Delete the typed part.
46554655
* In replace mode: Put the old characters back, if any.
46564656
*/
4657-
i = compl_col + (compl_cont_status & CONT_ADDING ? compl_length : 0);
4658-
backspace_until_column(i);
4657+
col = compl_col + (compl_cont_status & CONT_ADDING ? compl_length : 0);
4658+
if ((int)curwin->w_cursor.col > col)
4659+
{
4660+
if (stop_arrow() == FAIL)
4661+
return;
4662+
backspace_until_column(col);
4663+
}
46594664

46604665
/* TODO: is this sufficient for redrawing? Redrawing everything causes
46614666
* flicker, thus we can't do that. */
@@ -5073,8 +5078,11 @@ ins_complete(int c, int enable_pum)
50735078
colnr_T curs_col; /* cursor column */
50745079
int n;
50755080
int save_w_wrow;
5081+
int insert_match;
50765082

50775083
compl_direction = ins_compl_key2dir(c);
5084+
insert_match = ins_compl_use_match(c);
5085+
50785086
if (!compl_started)
50795087
{
50805088
/* First time we hit ^N or ^P (in a row, I mean) */
@@ -5500,6 +5508,8 @@ ins_complete(int c, int enable_pum)
55005508
edit_submode_extra = NULL;
55015509
out_flush();
55025510
}
5511+
else if (insert_match && stop_arrow() == FAIL)
5512+
return FAIL;
55035513

55045514
compl_shown_match = compl_curr_match;
55055515
compl_shows_dir = compl_direction;
@@ -5508,8 +5518,7 @@ ins_complete(int c, int enable_pum)
55085518
* Find next match (and following matches).
55095519
*/
55105520
save_w_wrow = curwin->w_wrow;
5511-
n = ins_compl_next(TRUE, ins_compl_key2count(c),
5512-
ins_compl_use_match(c), FALSE);
5521+
n = ins_compl_next(TRUE, ins_compl_key2count(c), insert_match, FALSE);
55135522

55145523
/* may undisplay the popup menu */
55155524
ins_compl_upd_pum();

src/move.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,11 +2853,8 @@ do_check_cursorbind(void)
28532853
{
28542854
# ifdef FEAT_DIFF
28552855
if (curwin->w_p_diff)
2856-
curwin->w_cursor.lnum
2857-
= diff_get_corresponding_line(old_curbuf,
2858-
line,
2859-
curbuf,
2860-
curwin->w_cursor.lnum);
2856+
curwin->w_cursor.lnum =
2857+
diff_get_corresponding_line(old_curbuf, line);
28612858
else
28622859
# endif
28632860
curwin->w_cursor.lnum = line;

src/os_unix.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ static RETSIGTYPE deathtrap SIGPROTOARG;
211211
static void catch_int_signal(void);
212212
static void set_signals(void);
213213
static void catch_signals(RETSIGTYPE (*func_deadly)(), RETSIGTYPE (*func_other)());
214+
#ifdef HAVE_SIGPROCMASK
215+
# define SIGSET_DECL(set) sigset_t set;
216+
# define BLOCK_SIGNALS(set) block_signals(set)
217+
# define UNBLOCK_SIGNALS(set) unblock_signals(set)
218+
#else
219+
# define SIGSET_DECL(set)
220+
# define BLOCK_SIGNALS(set) do { /**/ } while (0)
221+
# define UNBLOCK_SIGNALS(set) do { /**/ } while (0)
222+
#endif
214223
static int have_wildcard(int, char_u **);
215224
static int have_dollars(int, char_u **);
216225

@@ -1468,6 +1477,33 @@ catch_signals(
14681477
signal(signal_info[i].sig, func_other);
14691478
}
14701479

1480+
#ifdef HAVE_SIGPROCMASK
1481+
static void
1482+
block_signals(sigset_t *set)
1483+
{
1484+
sigset_t newset;
1485+
int i;
1486+
1487+
sigemptyset(&newset);
1488+
1489+
for (i = 0; signal_info[i].sig != -1; i++)
1490+
sigaddset(&newset, signal_info[i].sig);
1491+
1492+
# if defined(_REENTRANT) && defined(SIGCONT)
1493+
/* SIGCONT isn't in the list, because its default action is ignore */
1494+
sigaddset(&newset, SIGCONT);
1495+
# endif
1496+
1497+
sigprocmask(SIG_BLOCK, &newset, set);
1498+
}
1499+
1500+
static void
1501+
unblock_signals(sigset_t *set)
1502+
{
1503+
sigprocmask(SIG_SETMASK, set, NULL);
1504+
}
1505+
#endif
1506+
14711507
/*
14721508
* Handling of SIGHUP, SIGQUIT and SIGTERM:
14731509
* "when" == a signal: when busy, postpone and return FALSE, otherwise
@@ -4301,12 +4337,18 @@ mch_call_shell(
43014337

43024338
if (!pipe_error) /* pty or pipe opened or not used */
43034339
{
4340+
SIGSET_DECL(curset)
4341+
43044342
# ifdef __BEOS__
43054343
beos_cleanup_read_thread();
43064344
# endif
43074345

4308-
if ((pid = fork()) == -1) /* maybe we should use vfork() */
4346+
BLOCK_SIGNALS(&curset);
4347+
pid = fork(); /* maybe we should use vfork() */
4348+
if (pid == -1)
43094349
{
4350+
UNBLOCK_SIGNALS(&curset);
4351+
43104352
MSG_PUTS(_("\nCannot fork\n"));
43114353
if ((options & (SHELL_READ|SHELL_WRITE))
43124354
# ifdef FEAT_GUI
@@ -4333,6 +4375,7 @@ mch_call_shell(
43334375
else if (pid == 0) /* child */
43344376
{
43354377
reset_signals(); /* handle signals normally */
4378+
UNBLOCK_SIGNALS(&curset);
43364379

43374380
if (!show_shell_mess || (options & SHELL_EXPAND))
43384381
{
@@ -4476,6 +4519,7 @@ mch_call_shell(
44764519
*/
44774520
catch_signals(SIG_IGN, SIG_ERR);
44784521
catch_int_signal();
4522+
UNBLOCK_SIGNALS(&curset);
44794523

44804524
/*
44814525
* For the GUI we redirect stdin, stdout and stderr to our window.
@@ -5091,6 +5135,7 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
50915135
int use_file_for_out = options->jo_io[PART_OUT] == JIO_FILE;
50925136
int use_file_for_err = options->jo_io[PART_ERR] == JIO_FILE;
50935137
int use_out_for_err = options->jo_io[PART_ERR] == JIO_OUT;
5138+
SIGSET_DECL(curset)
50945139

50955140
if (use_out_for_err && use_null_for_out)
50965141
use_null_for_err = TRUE;
@@ -5162,20 +5207,22 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
51625207
goto failed;
51635208
}
51645209

5210+
BLOCK_SIGNALS(&curset);
51655211
pid = fork(); /* maybe we should use vfork() */
5166-
if (pid == -1)
5212+
if (pid == -1)
51675213
{
51685214
/* failed to fork */
5215+
UNBLOCK_SIGNALS(&curset);
51695216
goto failed;
51705217
}
5171-
51725218
if (pid == 0)
51735219
{
51745220
int null_fd = -1;
51755221
int stderr_works = TRUE;
51765222

51775223
/* child */
51785224
reset_signals(); /* handle signals normally */
5225+
UNBLOCK_SIGNALS(&curset);
51795226

51805227
# ifdef HAVE_SETSID
51815228
/* Create our own process group, so that the child and all its
@@ -5256,6 +5303,8 @@ mch_start_job(char **argv, job_T *job, jobopt_T *options UNUSED)
52565303
}
52575304

52585305
/* parent */
5306+
UNBLOCK_SIGNALS(&curset);
5307+
52595308
job->jv_pid = pid;
52605309
job->jv_status = JOB_STARTED;
52615310
job->jv_channel = channel; /* ch_refcount was set above */
@@ -5379,7 +5428,6 @@ mch_detect_ended_job(job_T *job_list)
53795428
}
53805429
}
53815430
return NULL;
5382-
53835431
}
53845432

53855433
int

src/proto/diff.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ void nv_diffgetput(int put, long count);
2222
void ex_diffgetput(exarg_T *eap);
2323
int diff_mode_buf(buf_T *buf);
2424
int diff_move_to(int dir, long count);
25-
linenr_T diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1, buf_T *buf2, linenr_T lnum3);
25+
linenr_T diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1);
2626
linenr_T diff_lnum_win(linenr_T lnum, win_T *wp);
2727
/* vim: set ft=c : */

src/testdir/test_channel.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,21 @@ func Test_job_start_invalid()
14331433
call assert_fails('call job_start("")', 'E474:')
14341434
endfunc
14351435

1436+
func Test_job_stop_immediately()
1437+
if !has('job')
1438+
return
1439+
endif
1440+
1441+
let job = job_start([s:python, '-c', 'import time;time.sleep(10)'])
1442+
try
1443+
call job_stop(job)
1444+
call WaitFor('"dead" == job_status(job)')
1445+
call assert_equal('dead', job_status(job))
1446+
finally
1447+
call job_stop(job, 'kill')
1448+
endtry
1449+
endfunc
1450+
14361451
" This was leaking memory.
14371452
func Test_partial_in_channel_cycle()
14381453
let d = {}

src/testdir/test_diffmode.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,20 @@ func Test_diffoff()
218218
bwipe!
219219
bwipe!
220220
endfunc
221+
222+
func Test_setting_cursor()
223+
new Xtest1
224+
put =range(1,90)
225+
wq
226+
new Xtest2
227+
put =range(1,100)
228+
wq
229+
230+
tabe Xtest2
231+
$
232+
diffsp Xtest1
233+
tabclose
234+
235+
call delete('Xtest1')
236+
call delete('Xtest2')
237+
endfunc

0 commit comments

Comments
 (0)