Skip to content

Commit cb4aa03

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents cc99aa3 + f3757f0 commit cb4aa03

File tree

16 files changed

+403
-41
lines changed

16 files changed

+403
-41
lines changed

runtime/defaults.vim

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" The default vimrc file.
22
"
33
" Maintainer: Bram Moolenaar <[email protected]>
4-
" Last change: 2016 Sep 02
4+
" Last change: 2017 Mar 08
55
"
66
" This is loaded if no vimrc file was found.
77
" Except when Vim is run with "-u NONE" or "-C".
@@ -21,7 +21,10 @@ endif
2121

2222
" Use Vim settings, rather than Vi settings (much better!).
2323
" This must be first, because it changes other options as a side effect.
24-
set nocompatible
24+
" Avoid side effects when it was already reset.
25+
if &compatible
26+
set nocompatible
27+
endif
2528

2629
" Allow backspacing over everything in insert mode.
2730
set backspace=indent,eol,start

src/auto/configure

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10225,15 +10225,25 @@ fi
1022510225

1022610226

1022710227

10228-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for /proc/self/exe" >&5
10229-
$as_echo_n "checking for /proc/self/exe... " >&6; }
10228+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for /proc link to executable" >&5
10229+
$as_echo_n "checking for /proc link to executable... " >&6; }
1023010230
if test -L "/proc/self/exe"; then
10231-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
10232-
$as_echo "yes" >&6; }
10233-
$as_echo "#define HAVE_PROC_SELF_EXE 1" >>confdefs.h
10231+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: /proc/self/exe" >&5
10232+
$as_echo "/proc/self/exe" >&6; }
10233+
$as_echo "#define PROC_EXE_LINK \"/proc/self/exe\"" >>confdefs.h
10234+
10235+
elif test -L "/proc/self/path/a.out"; then
10236+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: /proc/self/path/a.out" >&5
10237+
$as_echo "/proc/self/path/a.out" >&6; }
10238+
$as_echo "#define PROC_EXE_LINK \"/proc/self/path/a.out\"" >>confdefs.h
10239+
10240+
elif test -L "/proc/curproc/file"; then
10241+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: /proc/curproc/file" >&5
10242+
$as_echo "/proc/curproc/file" >&6; }
10243+
$as_echo "#define PROC_EXE_LINK \"/proc/curproc/file\"" >>confdefs.h
1023410244

1023510245
else
10236-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
10246+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
1023710247
$as_echo "no" >&6; }
1023810248
fi
1023910249

src/config.h.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@
446446
/* Define if fcntl()'s F_SETFD command knows about FD_CLOEXEC */
447447
#undef HAVE_FD_CLOEXEC
448448

449-
/* Define if /proc/self/exe can be read */
450-
#undef HAVE_PROC_SELF_EXE
449+
/* Define if /proc/self/exe or similar can be read */
450+
#undef PROC_EXE_LINK
451451

452452
/* Define if you want Cygwin to use the WIN32 clipboard, not compatible with X11*/
453453
#undef FEAT_CYGWIN_WIN32_CLIPBOARD

src/configure.ac

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,12 +3105,21 @@ dnl ---------------------------------------------------------------------------
31053105
dnl end of GUI-checking
31063106
dnl ---------------------------------------------------------------------------
31073107

3108-
AC_MSG_CHECKING([for /proc/self/exe])
3108+
AC_MSG_CHECKING([for /proc link to executable])
31093109
if test -L "/proc/self/exe"; then
3110-
AC_MSG_RESULT(yes)
3111-
AC_DEFINE(HAVE_PROC_SELF_EXE)
3110+
dnl Linux
3111+
AC_MSG_RESULT([/proc/self/exe])
3112+
AC_DEFINE(PROC_EXE_LINK, "/proc/self/exe")
3113+
elif test -L "/proc/self/path/a.out"; then
3114+
dnl Solaris
3115+
AC_MSG_RESULT([/proc/self/path/a.out])
3116+
AC_DEFINE(PROC_EXE_LINK, "/proc/self/path/a.out")
3117+
elif test -L "/proc/curproc/file"; then
3118+
dnl FreeBSD
3119+
AC_MSG_RESULT([/proc/curproc/file])
3120+
AC_DEFINE(PROC_EXE_LINK, "/proc/curproc/file")
31123121
else
3113-
AC_MSG_RESULT(no)
3122+
AC_MSG_RESULT(no)
31143123
fi
31153124

31163125
dnl Check for Cygwin, which needs an extra source file if not using X11

src/dict.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ dict_add_list(dict_T *d, char *key, list_T *list)
356356
item->di_tv.v_lock = 0;
357357
item->di_tv.v_type = VAR_LIST;
358358
item->di_tv.vval.v_list = list;
359+
++list->lv_refcount;
359360
if (dict_add(d, item) == FAIL)
360361
{
361362
dictitem_free(item);
362363
return FAIL;
363364
}
364-
++list->lv_refcount;
365365
return OK;
366366
}
367367

@@ -380,12 +380,12 @@ dict_add_dict(dict_T *d, char *key, dict_T *dict)
380380
item->di_tv.v_lock = 0;
381381
item->di_tv.v_type = VAR_DICT;
382382
item->di_tv.vval.v_dict = dict;
383+
++dict->dv_refcount;
383384
if (dict_add(d, item) == FAIL)
384385
{
385386
dictitem_free(item);
386387
return FAIL;
387388
}
388-
++dict->dv_refcount;
389389
return OK;
390390
}
391391

src/ex_cmds.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -799,14 +799,8 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
799799
linenr_T num_lines; /* Num lines moved */
800800
linenr_T last_line; /* Last line in file after adding new text */
801801
#ifdef FEAT_FOLDING
802-
int isFolded;
803-
804-
/* Moving lines seems to corrupt the folds, delete folding info now
805-
* and recreate it when finished. Don't do this for manual folding, it
806-
* would delete all folds. */
807-
isFolded = hasAnyFolding(curwin) && !foldmethodIsManual(curwin);
808-
if (isFolded)
809-
deleteFoldRecurse(&curwin->w_folds);
802+
win_T *win;
803+
tabpage_T *tp;
810804
#endif
811805

812806
if (dest >= line1 && dest < line2)
@@ -851,24 +845,34 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
851845
* their final destination at the new text position -- webb
852846
*/
853847
last_line = curbuf->b_ml.ml_line_count;
854-
mark_adjust(line1, line2, last_line - line2, 0L);
855-
changed_lines(last_line - num_lines + 1, 0, last_line + 1, num_lines);
848+
mark_adjust_nofold(line1, line2, last_line - line2, 0L);
856849
if (dest >= line2)
857850
{
858-
mark_adjust(line2 + 1, dest, -num_lines, 0L);
851+
mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L);
852+
#ifdef FEAT_FOLDING
853+
FOR_ALL_TAB_WINDOWS(tp, win) {
854+
if (win->w_buffer == curbuf)
855+
foldMoveRange(&win->w_folds, line1, line2, dest);
856+
}
857+
#endif
859858
curbuf->b_op_start.lnum = dest - num_lines + 1;
860859
curbuf->b_op_end.lnum = dest;
861860
}
862861
else
863862
{
864-
mark_adjust(dest + 1, line1 - 1, num_lines, 0L);
863+
mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L);
864+
#ifdef FEAT_FOLDING
865+
FOR_ALL_TAB_WINDOWS(tp, win) {
866+
if (win->w_buffer == curbuf)
867+
foldMoveRange(&win->w_folds, dest + 1, line1 - 1, line2);
868+
}
869+
#endif
865870
curbuf->b_op_start.lnum = dest + 1;
866871
curbuf->b_op_end.lnum = dest + num_lines;
867872
}
868873
curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
869-
mark_adjust(last_line - num_lines + 1, last_line,
874+
mark_adjust_nofold(last_line - num_lines + 1, last_line,
870875
-(last_line - dest - extra), 0L);
871-
changed_lines(last_line - num_lines + 1, 0, last_line + 1, -extra);
872876

873877
/*
874878
* Now we delete the original text -- webb
@@ -906,12 +910,6 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
906910
else
907911
changed_lines(dest + 1, 0, line1 + num_lines, 0L);
908912

909-
#ifdef FEAT_FOLDING
910-
/* recreate folds */
911-
if (isFolded)
912-
foldUpdateAll(curwin);
913-
#endif
914-
915913
return OK;
916914
}
917915

src/fold.c

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,6 +2968,182 @@ foldRemove(garray_T *gap, linenr_T top, linenr_T bot)
29682968
}
29692969
}
29702970

2971+
/* foldReverseOrder() {{{2 */
2972+
static void
2973+
foldReverseOrder(garray_T *gap, linenr_T start, linenr_T end)
2974+
{
2975+
fold_T *left, *right;
2976+
fold_T tmp;
2977+
2978+
for (; start < end; start++, end--)
2979+
{
2980+
left = (fold_T *)gap->ga_data + start;
2981+
right = (fold_T *)gap->ga_data + end;
2982+
tmp = *left;
2983+
*left = *right;
2984+
*right = tmp;
2985+
}
2986+
}
2987+
2988+
/* foldMoveRange() {{{2 */
2989+
/*
2990+
* Move folds within the inclusive range "line1" to "line2" to after "dest"
2991+
* requires "line1" <= "line2" <= "dest"
2992+
*
2993+
* There are the following situations for the first fold at or below line1 - 1.
2994+
* 1 2 3 4
2995+
* 1 2 3 4
2996+
* line1 2 3 4
2997+
* 2 3 4 5 6 7
2998+
* line2 3 4 5 6 7
2999+
* 3 4 6 7 8 9
3000+
* dest 4 7 8 9
3001+
* 4 7 8 10
3002+
* 4 7 8 10
3003+
*
3004+
* In the following descriptions, "moved" means moving in the buffer, *and* in
3005+
* the fold array.
3006+
* Meanwhile, "shifted" just means moving in the buffer.
3007+
* 1. not changed
3008+
* 2. truncated above line1
3009+
* 3. length reduced by line2 - line1, folds starting between the end of 3 and
3010+
* dest are truncated and shifted up
3011+
* 4. internal folds moved (from [line1, line2] to dest)
3012+
* 5. moved to dest.
3013+
* 6. truncated below line2 and moved.
3014+
* 7. length reduced by line2 - dest, folds starting between line2 and dest are
3015+
* removed, top is moved down by move_len.
3016+
* 8. truncated below dest and shifted up.
3017+
* 9. shifted up
3018+
* 10. not changed
3019+
*/
3020+
3021+
static void
3022+
truncate_fold(fold_T *fp, linenr_T end)
3023+
{
3024+
foldRemove(&fp->fd_nested, end - fp->fd_top, MAXLNUM);
3025+
fp->fd_len = end - fp->fd_top + 1;
3026+
}
3027+
3028+
#define fold_end(fp) ((fp)->fd_top + (fp)->fd_len - 1)
3029+
#define valid_fold(fp, gap) ((fp) < ((fold_T *)(gap)->ga_data + (gap)->ga_len))
3030+
#define fold_index(fp, gap) ((size_t)(fp - ((fold_T *)(gap)->ga_data)))
3031+
3032+
void
3033+
foldMoveRange(garray_T *gap, linenr_T line1, linenr_T line2, linenr_T dest)
3034+
{
3035+
fold_T *fp;
3036+
linenr_T range_len = line2 - line1 + 1;
3037+
linenr_T move_len = dest - line2;
3038+
int at_start = foldFind(gap, line1 - 1, &fp);
3039+
size_t move_start = 0, move_end = 0, dest_index = 0;
3040+
3041+
if (at_start)
3042+
{
3043+
if (fold_end(fp) > dest)
3044+
{
3045+
/* Case 4
3046+
* don't have to change this fold, but have to move nested folds.
3047+
*/
3048+
foldMoveRange(&fp->fd_nested, line1 - fp->fd_top, line2 -
3049+
fp->fd_top, dest - fp->fd_top);
3050+
return;
3051+
}
3052+
else if (fold_end(fp) > line2)
3053+
{
3054+
/* Case 3
3055+
* Remove nested folds between line1 and line2 & reduce the
3056+
* length of fold by "range_len".
3057+
* Folds after this one must be dealt with.
3058+
*/
3059+
foldMarkAdjustRecurse(&fp->fd_nested, line1 - fp->fd_top, line2 -
3060+
fp->fd_top, MAXLNUM, -range_len);
3061+
fp->fd_len -= range_len;
3062+
}
3063+
else
3064+
/* Case 2 truncate fold, folds after this one must be dealt with. */
3065+
truncate_fold(fp, line1);
3066+
3067+
/* Look at the next fold, and treat that one as if it were the first
3068+
* after "line1" (because now it is). */
3069+
fp = fp + 1;
3070+
}
3071+
3072+
if (!valid_fold(fp, gap) || fp->fd_top > dest)
3073+
{
3074+
/* Case 10
3075+
* No folds after "line1" and before "dest"
3076+
*/
3077+
return;
3078+
}
3079+
else if (fp->fd_top > line2)
3080+
{
3081+
for (; valid_fold(fp, gap) && fold_end(fp) < dest; fp++)
3082+
/* Case 9. (for all case 9's) -- shift up. */
3083+
fp->fd_top -= range_len;
3084+
3085+
if (valid_fold(fp, gap) && fp->fd_top < dest)
3086+
{
3087+
/* Case 8. -- ensure truncated at dest, shift up */
3088+
truncate_fold(fp, dest);
3089+
fp->fd_top -= range_len;
3090+
}
3091+
return;
3092+
}
3093+
else if (fold_end(fp) > dest)
3094+
{
3095+
/* Case 7 -- remove nested folds and shrink */
3096+
foldMarkAdjustRecurse(&fp->fd_nested, line2 + 1 - fp->fd_top, dest -
3097+
fp->fd_top, MAXLNUM, -move_len);
3098+
fp->fd_len -= move_len;
3099+
fp->fd_top += move_len;
3100+
return;
3101+
}
3102+
3103+
/* Case 5 or 6
3104+
* changes rely on whether there are folds between the end of
3105+
* this fold and "dest".
3106+
*/
3107+
move_start = fold_index(fp, gap);
3108+
3109+
for (; valid_fold(fp, gap) && fp->fd_top <= dest; fp++)
3110+
{
3111+
if (fp->fd_top <= line2)
3112+
{
3113+
/* 1. 2. or 3. */
3114+
if (fold_end(fp) > line2)
3115+
/* 2. or 3., truncate before moving */
3116+
truncate_fold(fp, line2);
3117+
3118+
fp->fd_top += move_len;
3119+
continue;
3120+
}
3121+
3122+
/* Record index of the first fold after the moved range. */
3123+
if (move_end == 0)
3124+
move_end = fold_index(fp, gap);
3125+
3126+
if (fold_end(fp) > dest)
3127+
truncate_fold(fp, dest);
3128+
3129+
fp->fd_top -= range_len;
3130+
}
3131+
3132+
dest_index = fold_index(fp, gap);
3133+
3134+
/*
3135+
* All folds are now correct, but they are not necessarily in the correct
3136+
* order. We have to swap folds in the range [move_end, dest_index) with
3137+
* those in the range [move_start, move_end).
3138+
*/
3139+
foldReverseOrder(gap, move_start, dest_index - 1);
3140+
foldReverseOrder(gap, move_start, move_start + dest_index - move_end - 1);
3141+
foldReverseOrder(gap, move_start + dest_index - move_end, dest_index - 1);
3142+
}
3143+
#undef fold_end
3144+
#undef valid_fold
3145+
#undef fold_index
3146+
29713147
/* foldMerge() {{{2 */
29723148
/*
29733149
* Merge two adjacent folds (and the nested ones in them).

src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,11 +3623,11 @@ set_progpath(char_u *argv0)
36233623
{
36243624
char_u *val = argv0;
36253625

3626-
# ifdef HAVE_PROC_SELF_EXE
3626+
# ifdef PROC_EXE_LINK
36273627
char buf[PATH_MAX + 1];
36283628
ssize_t len;
36293629

3630-
len = readlink("/proc/self/exe", buf, PATH_MAX);
3630+
len = readlink(PROC_EXE_LINK, buf, PATH_MAX);
36313631
if (len > 0)
36323632
{
36333633
buf[len] = NUL;

0 commit comments

Comments
 (0)