Mercurial > vim
comparison src/ex_cmds2.c @ 14656:0d5726f2913b v8.1.0341
patch 8.1.0341: :argadd in empty buffer changes the buffer name
commit https://github.com/vim/vim/commit/32bbd00949c585ea1c9da13197279a175097eddd
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 31 23:06:22 2018 +0200
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Problem: :argadd in empty buffer changes the buffer name. (Pavol Juhas)
Solution: Don't re-use the current buffer when not going to edit the file.
(closes #3397) Do re-use the current buffer for :next.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 31 Aug 2018 23:15:04 +0200 |
parents | 96858d612aff |
children | 285b051979a6 |
comparison
equal
deleted
inserted
replaced
14655:f2d77602d8e2 | 14656:0d5726f2913b |
---|---|
2443 /* | 2443 /* |
2444 * Code to handle the argument list. | 2444 * Code to handle the argument list. |
2445 */ | 2445 */ |
2446 | 2446 |
2447 static char_u *do_one_arg(char_u *str); | 2447 static char_u *do_one_arg(char_u *str); |
2448 static int do_arglist(char_u *str, int what, int after); | 2448 static int do_arglist(char_u *str, int what, int after, int will_edit); |
2449 static void alist_check_arg_idx(void); | 2449 static void alist_check_arg_idx(void); |
2450 static int editing_arg_idx(win_T *win); | 2450 static int editing_arg_idx(win_T *win); |
2451 static int alist_add_list(int count, char_u **files, int after); | 2451 static void alist_add_list(int count, char_u **files, int after, int will_edit); |
2452 #define AL_SET 1 | 2452 #define AL_SET 1 |
2453 #define AL_ADD 2 | 2453 #define AL_ADD 2 |
2454 #define AL_DEL 3 | 2454 #define AL_DEL 3 |
2455 | 2455 |
2456 /* | 2456 /* |
2551 * Redefine the argument list. | 2551 * Redefine the argument list. |
2552 */ | 2552 */ |
2553 void | 2553 void |
2554 set_arglist(char_u *str) | 2554 set_arglist(char_u *str) |
2555 { | 2555 { |
2556 do_arglist(str, AL_SET, 0); | 2556 do_arglist(str, AL_SET, 0, FALSE); |
2557 } | 2557 } |
2558 | 2558 |
2559 /* | 2559 /* |
2560 * "what" == AL_SET: Redefine the argument list to 'str'. | 2560 * "what" == AL_SET: Redefine the argument list to 'str'. |
2561 * "what" == AL_ADD: add files in 'str' to the argument list after "after". | 2561 * "what" == AL_ADD: add files in 'str' to the argument list after "after". |
2565 */ | 2565 */ |
2566 static int | 2566 static int |
2567 do_arglist( | 2567 do_arglist( |
2568 char_u *str, | 2568 char_u *str, |
2569 int what, | 2569 int what, |
2570 int after UNUSED) /* 0 means before first one */ | 2570 int after UNUSED, // 0 means before first one |
2571 int will_edit) // will edit added argument | |
2571 { | 2572 { |
2572 garray_T new_ga; | 2573 garray_T new_ga; |
2573 int exp_count; | 2574 int exp_count; |
2574 char_u **exp_files; | 2575 char_u **exp_files; |
2575 int i; | 2576 int i; |
2650 return FAIL; | 2651 return FAIL; |
2651 } | 2652 } |
2652 | 2653 |
2653 if (what == AL_ADD) | 2654 if (what == AL_ADD) |
2654 { | 2655 { |
2655 (void)alist_add_list(exp_count, exp_files, after); | 2656 alist_add_list(exp_count, exp_files, after, will_edit); |
2656 vim_free(exp_files); | 2657 vim_free(exp_files); |
2657 } | 2658 } |
2658 else /* what == AL_SET */ | 2659 else /* what == AL_SET */ |
2659 alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0); | 2660 alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0); |
2660 } | 2661 } |
2661 | 2662 |
2662 alist_check_arg_idx(); | 2663 alist_check_arg_idx(); |
2663 | 2664 |
2664 return OK; | 2665 return OK; |
2930 | (eap->forceit ? CCGD_FORCEIT : 0) | 2931 | (eap->forceit ? CCGD_FORCEIT : 0) |
2931 | CCGD_EXCMD)) | 2932 | CCGD_EXCMD)) |
2932 { | 2933 { |
2933 if (*eap->arg != NUL) /* redefine file list */ | 2934 if (*eap->arg != NUL) /* redefine file list */ |
2934 { | 2935 { |
2935 if (do_arglist(eap->arg, AL_SET, 0) == FAIL) | 2936 if (do_arglist(eap->arg, AL_SET, 0, TRUE) == FAIL) |
2936 return; | 2937 return; |
2937 i = 0; | 2938 i = 0; |
2938 } | 2939 } |
2939 else | 2940 else |
2940 i = curwin->w_arg_idx + (int)eap->line2; | 2941 i = curwin->w_arg_idx + (int)eap->line2; |
2950 { | 2951 { |
2951 int i = eap->addr_count ? (int)eap->line2 : curwin->w_arg_idx + 1; | 2952 int i = eap->addr_count ? (int)eap->line2 : curwin->w_arg_idx + 1; |
2952 // Whether curbuf will be reused, curbuf->b_ffname will be set. | 2953 // Whether curbuf will be reused, curbuf->b_ffname will be set. |
2953 int curbuf_is_reusable = curbuf_reusable(); | 2954 int curbuf_is_reusable = curbuf_reusable(); |
2954 | 2955 |
2955 if (do_arglist(eap->arg, AL_ADD, i) == FAIL) | 2956 if (do_arglist(eap->arg, AL_ADD, i, TRUE) == FAIL) |
2956 return; | 2957 return; |
2957 #ifdef FEAT_TITLE | 2958 #ifdef FEAT_TITLE |
2958 maketitle(); | 2959 maketitle(); |
2959 #endif | 2960 #endif |
2960 | 2961 |
2972 */ | 2973 */ |
2973 void | 2974 void |
2974 ex_argadd(exarg_T *eap) | 2975 ex_argadd(exarg_T *eap) |
2975 { | 2976 { |
2976 do_arglist(eap->arg, AL_ADD, | 2977 do_arglist(eap->arg, AL_ADD, |
2977 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1); | 2978 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1, |
2979 FALSE); | |
2978 #ifdef FEAT_TITLE | 2980 #ifdef FEAT_TITLE |
2979 maketitle(); | 2981 maketitle(); |
2980 #endif | 2982 #endif |
2981 } | 2983 } |
2982 | 2984 |
3022 } | 3024 } |
3023 } | 3025 } |
3024 else if (*eap->arg == NUL) | 3026 else if (*eap->arg == NUL) |
3025 EMSG(_(e_argreq)); | 3027 EMSG(_(e_argreq)); |
3026 else | 3028 else |
3027 do_arglist(eap->arg, AL_DEL, 0); | 3029 do_arglist(eap->arg, AL_DEL, 0, FALSE); |
3028 #ifdef FEAT_TITLE | 3030 #ifdef FEAT_TITLE |
3029 maketitle(); | 3031 maketitle(); |
3030 #endif | 3032 #endif |
3031 } | 3033 } |
3032 | 3034 |
3267 | 3269 |
3268 /* | 3270 /* |
3269 * Add files[count] to the arglist of the current window after arg "after". | 3271 * Add files[count] to the arglist of the current window after arg "after". |
3270 * The file names in files[count] must have been allocated and are taken over. | 3272 * The file names in files[count] must have been allocated and are taken over. |
3271 * Files[] itself is not taken over. | 3273 * Files[] itself is not taken over. |
3272 * Returns index of first added argument. Returns -1 when failed (out of mem). | 3274 */ |
3273 */ | 3275 static void |
3274 static int | |
3275 alist_add_list( | 3276 alist_add_list( |
3276 int count, | 3277 int count, |
3277 char_u **files, | 3278 char_u **files, |
3278 int after) /* where to add: 0 = before first one */ | 3279 int after, // where to add: 0 = before first one |
3280 int will_edit) // will edit adding argument | |
3279 { | 3281 { |
3280 int i; | 3282 int i; |
3281 int old_argcount = ARGCOUNT; | 3283 int old_argcount = ARGCOUNT; |
3282 | 3284 |
3283 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK) | 3285 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK) |
3289 if (after < ARGCOUNT) | 3291 if (after < ARGCOUNT) |
3290 mch_memmove(&(ARGLIST[after + count]), &(ARGLIST[after]), | 3292 mch_memmove(&(ARGLIST[after + count]), &(ARGLIST[after]), |
3291 (ARGCOUNT - after) * sizeof(aentry_T)); | 3293 (ARGCOUNT - after) * sizeof(aentry_T)); |
3292 for (i = 0; i < count; ++i) | 3294 for (i = 0; i < count; ++i) |
3293 { | 3295 { |
3296 int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0); | |
3297 | |
3294 ARGLIST[after + i].ae_fname = files[i]; | 3298 ARGLIST[after + i].ae_fname = files[i]; |
3295 ARGLIST[after + i].ae_fnum = | 3299 ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags); |
3296 buflist_add(files[i], BLN_LISTED | BLN_CURBUF); | |
3297 } | 3300 } |
3298 ALIST(curwin)->al_ga.ga_len += count; | 3301 ALIST(curwin)->al_ga.ga_len += count; |
3299 if (old_argcount > 0 && curwin->w_arg_idx >= after) | 3302 if (old_argcount > 0 && curwin->w_arg_idx >= after) |
3300 curwin->w_arg_idx += count; | 3303 curwin->w_arg_idx += count; |
3301 return after; | 3304 return; |
3302 } | 3305 } |
3303 | 3306 |
3304 for (i = 0; i < count; ++i) | 3307 for (i = 0; i < count; ++i) |
3305 vim_free(files[i]); | 3308 vim_free(files[i]); |
3306 return -1; | |
3307 } | 3309 } |
3308 | 3310 |
3309 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | 3311 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
3310 /* | 3312 /* |
3311 * Function given to ExpandGeneric() to obtain the possible arguments of the | 3313 * Function given to ExpandGeneric() to obtain the possible arguments of the |