annotate src/arglist.c @ 17744:4a3dca734d36 v8.1.1869

patch 8.1.1869: code for the argument list is spread out commit https://github.com/vim/vim/commit/4ad62155a1015751a6645aaecd94b02c94c8934b Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 17 14:38:55 2019 +0200 patch 8.1.1869: code for the argument list is spread out Problem: Code for the argument list is spread out. Solution: Put argument list code in arglist.c. (Yegappan Lakshmanan, closes #4819)
author Bram Moolenaar <Bram@vim.org>
date Sat, 17 Aug 2019 14:45:04 +0200
parents
children 04245f071792
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * arglist.c: functions for dealing with the argument list
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #define AL_SET 1
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #define AL_ADD 2
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 #define AL_DEL 3
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 * Clear an argument list: free all file names and reset it to zero entries.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 alist_clear(alist_T *al)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 while (--al->al_ga.ga_len >= 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 vim_free(AARGLIST(al)[al->al_ga.ga_len].ae_fname);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 ga_clear(&al->al_ga);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 * Init an argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 alist_init(alist_T *al)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 ga_init2(&al->al_ga, (int)sizeof(aentry_T), 5);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 * Remove a reference from an argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 * Ignored when the argument list is the global one.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 * If the argument list is no longer used by any window, free it.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 alist_unlink(alist_T *al)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 if (al != &global_alist && --al->al_refcount <= 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 alist_clear(al);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 vim_free(al);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 * Create a new argument list and use it for the current window.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 alist_new(void)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 curwin->w_alist = ALLOC_ONE(alist_T);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 if (curwin->w_alist == NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 curwin->w_alist = &global_alist;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 ++global_alist.al_refcount;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 curwin->w_alist->al_refcount = 1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 curwin->w_alist->id = ++max_alist_id;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 alist_init(curwin->w_alist);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 #if !defined(UNIX) || defined(PROTO)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 * Expand the file names in the global argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 * If "fnum_list" is not NULL, use "fnum_list[fnum_len]" as a list of buffer
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 * numbers to be re-used.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 alist_expand(int *fnum_list, int fnum_len)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 char_u **old_arg_files;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 int old_arg_count;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 char_u **new_arg_files;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 int new_arg_file_count;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 char_u *save_p_su = p_su;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 // Don't use 'suffixes' here. This should work like the shell did the
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 // expansion. Also, the vimrc file isn't read yet, thus the user
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 // can't set the options.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 p_su = empty_option;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 old_arg_files = ALLOC_MULT(char_u *, GARGCOUNT);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 if (old_arg_files != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 for (i = 0; i < GARGCOUNT; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 old_arg_count = GARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 if (expand_wildcards(old_arg_count, old_arg_files,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 &new_arg_file_count, &new_arg_files,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 EW_FILE|EW_NOTFOUND|EW_ADDSLASH|EW_NOERROR) == OK
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 && new_arg_file_count > 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 alist_set(&global_alist, new_arg_file_count, new_arg_files,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 TRUE, fnum_list, fnum_len);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 FreeWild(old_arg_count, old_arg_files);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 p_su = save_p_su;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 * Set the argument list for the current window.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 * Takes over the allocated files[] and the allocated fnames in it.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 alist_set(
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 alist_T *al,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 int count,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 char_u **files,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 int use_curbuf,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 int *fnum_list,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 int fnum_len)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 static int recursive = 0;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 if (recursive)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 emsg(_(e_au_recursive));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 ++recursive;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 alist_clear(al);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 if (ga_grow(&al->al_ga, count) == OK)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 for (i = 0; i < count; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 if (got_int)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 // When adding many buffers this can take a long time. Allow
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 // interrupting here.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 while (i < count)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 vim_free(files[i++]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 // May set buffer name of a buffer previously used for the
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 // argument list, so that it's re-used by alist_add.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 if (fnum_list != NULL && i < fnum_len)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 buf_set_name(fnum_list[i], files[i]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 alist_add(al, files[i], use_curbuf ? 2 : 1);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 ui_breakcheck();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 vim_free(files);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 FreeWild(count, files);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 if (al == &global_alist)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 arg_had_last = FALSE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 --recursive;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 * Add file "fname" to argument list "al".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 * "fname" must have been allocated and "al" must have been checked for room.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 alist_add(
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 alist_T *al,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 char_u *fname,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 int set_fnum) // 1: set buffer number; 2: re-use curbuf
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 if (fname == NULL) // don't add NULL file names
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 #ifdef BACKSLASH_IN_FILENAME
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 slash_adjust(fname);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 AARGLIST(al)[al->al_ga.ga_len].ae_fname = fname;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 if (set_fnum > 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 AARGLIST(al)[al->al_ga.ga_len].ae_fnum =
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 buflist_add(fname, BLN_LISTED | (set_fnum == 2 ? BLN_CURBUF : 0));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 ++al->al_ga.ga_len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 * Adjust slashes in file names. Called after 'shellslash' was set.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 alist_slash_adjust(void)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 win_T *wp;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 tabpage_T *tp;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 for (i = 0; i < GARGCOUNT; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 if (GARGLIST[i].ae_fname != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 slash_adjust(GARGLIST[i].ae_fname);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 FOR_ALL_TAB_WINDOWS(tp, wp)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 if (wp->w_alist != &global_alist)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 for (i = 0; i < WARGCOUNT(wp); ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 if (WARGLIST(wp)[i].ae_fname != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 slash_adjust(WARGLIST(wp)[i].ae_fname);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 * Isolate one argument, taking backticks.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 * Changes the argument in-place, puts a NUL after it. Backticks remain.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 * Return a pointer to the start of the next argument.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 static char_u *
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 do_one_arg(char_u *str)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 char_u *p;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 int inbacktick;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 inbacktick = FALSE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 for (p = str; *str; ++str)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 // When the backslash is used for escaping the special meaning of a
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 // character we need to keep it until wildcard expansion.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 if (rem_backslash(str))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 *p++ = *str++;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 *p++ = *str;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 // An item ends at a space not in backticks
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 if (!inbacktick && vim_isspace(*str))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 if (*str == '`')
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 inbacktick ^= TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 *p++ = *str;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 str = skipwhite(str);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 *p = NUL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 return str;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 * Separate the arguments in "str" and return a list of pointers in the
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 * growarray "gap".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 static int
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 get_arglist(garray_T *gap, char_u *str, int escaped)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 ga_init2(gap, (int)sizeof(char_u *), 20);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 while (*str != NUL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 if (ga_grow(gap, 1) == FAIL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 ga_clear(gap);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 return FAIL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 ((char_u **)gap->ga_data)[gap->ga_len++] = str;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 // If str is escaped, don't handle backslashes or spaces
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 if (!escaped)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 return OK;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 // Isolate one argument, change it in-place, put a NUL after it.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 str = do_one_arg(str);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 return OK;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 #if defined(FEAT_QUICKFIX) || defined(FEAT_SYN_HL) || defined(PROTO)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 * Parse a list of arguments (file names), expand them and return in
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 * "fnames[fcountp]". When "wig" is TRUE, removes files matching 'wildignore'.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 * Return FAIL or OK.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 int
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 get_arglist_exp(
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 char_u *str,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 int *fcountp,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 char_u ***fnamesp,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 int wig)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 garray_T ga;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 if (get_arglist(&ga, str, TRUE) == FAIL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 return FAIL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 if (wig == TRUE)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 i = expand_wildcards(ga.ga_len, (char_u **)ga.ga_data,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 fcountp, fnamesp, EW_FILE|EW_NOTFOUND);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 i = gen_expand_wildcards(ga.ga_len, (char_u **)ga.ga_data,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 fcountp, fnamesp, EW_FILE|EW_NOTFOUND);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 ga_clear(&ga);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 return i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 * Check the validity of the arg_idx for each other window.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 static void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 alist_check_arg_idx(void)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 win_T *win;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 tabpage_T *tp;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 FOR_ALL_TAB_WINDOWS(tp, win)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 if (win->w_alist == curwin->w_alist)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 check_arg_idx(win);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 * Add files[count] to the arglist of the current window after arg "after".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 * The file names in files[count] must have been allocated and are taken over.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 * Files[] itself is not taken over.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 static void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 alist_add_list(
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 int count,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 char_u **files,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 int after, // where to add: 0 = before first one
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 int will_edit) // will edit adding argument
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 int old_argcount = ARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 if (ga_grow(&ALIST(curwin)->al_ga, count) == OK)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 if (after < 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 after = 0;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 if (after > ARGCOUNT)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 after = ARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 if (after < ARGCOUNT)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 mch_memmove(&(ARGLIST[after + count]), &(ARGLIST[after]),
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 (ARGCOUNT - after) * sizeof(aentry_T));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 for (i = 0; i < count; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 ARGLIST[after + i].ae_fname = files[i];
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 ALIST(curwin)->al_ga.ga_len += count;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 if (old_argcount > 0 && curwin->w_arg_idx >= after)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 curwin->w_arg_idx += count;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 for (i = 0; i < count; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 vim_free(files[i]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 * "what" == AL_SET: Redefine the argument list to 'str'.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 * "what" == AL_ADD: add files in 'str' to the argument list after "after".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 * "what" == AL_DEL: remove files in 'str' from the argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 *
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 * Return FAIL for failure, OK otherwise.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 static int
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 do_arglist(
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 char_u *str,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 int what,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 int after UNUSED, // 0 means before first one
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 int will_edit) // will edit added argument
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 garray_T new_ga;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 int exp_count;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 char_u **exp_files;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 char_u *p;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 int match;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 int arg_escaped = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 // Set default argument for ":argadd" command.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 if (what == AL_ADD && *str == NUL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 if (curbuf->b_ffname == NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 return FAIL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 str = curbuf->b_fname;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 arg_escaped = FALSE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 // Collect all file name arguments in "new_ga".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 if (get_arglist(&new_ga, str, arg_escaped) == FAIL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 return FAIL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 if (what == AL_DEL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 regmatch_T regmatch;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 int didone;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 // Delete the items: use each item as a regexp and find a match in the
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 // argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 regmatch.rm_ic = p_fic; // ignore case when 'fileignorecase' is set
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 for (i = 0; i < new_ga.ga_len && !got_int; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 p = ((char_u **)new_ga.ga_data)[i];
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 p = file_pat_to_reg_pat(p, NULL, NULL, FALSE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 if (p == NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 if (regmatch.regprog == NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 vim_free(p);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 didone = FALSE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 for (match = 0; match < ARGCOUNT; ++match)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 if (vim_regexec(&regmatch, alist_name(&ARGLIST[match]),
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 (colnr_T)0))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 didone = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 vim_free(ARGLIST[match].ae_fname);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 mch_memmove(ARGLIST + match, ARGLIST + match + 1,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 (ARGCOUNT - match - 1) * sizeof(aentry_T));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 --ALIST(curwin)->al_ga.ga_len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 if (curwin->w_arg_idx > match)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 --curwin->w_arg_idx;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 --match;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 vim_regfree(regmatch.regprog);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 vim_free(p);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 if (!didone)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 semsg(_(e_nomatch2), ((char_u **)new_ga.ga_data)[i]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 ga_clear(&new_ga);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 i = expand_wildcards(new_ga.ga_len, (char_u **)new_ga.ga_data,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 &exp_count, &exp_files, EW_DIR|EW_FILE|EW_ADDSLASH|EW_NOTFOUND);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 ga_clear(&new_ga);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 if (i == FAIL || exp_count == 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 emsg(_(e_nomatch));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 return FAIL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 if (what == AL_ADD)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 alist_add_list(exp_count, exp_files, after, will_edit);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 vim_free(exp_files);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 else // what == AL_SET
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 alist_check_arg_idx();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 return OK;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 * Redefine the argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 set_arglist(char_u *str)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 do_arglist(str, AL_SET, 0, FALSE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 * Return TRUE if window "win" is editing the file at the current argument
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 * index.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 int
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 editing_arg_idx(win_T *win)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 return !(win->w_arg_idx >= WARGCOUNT(win)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 || (win->w_buffer->b_fnum
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 != WARGLIST(win)[win->w_arg_idx].ae_fnum
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 && (win->w_buffer->b_ffname == NULL
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 || !(fullpathcmp(
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 alist_name(&WARGLIST(win)[win->w_arg_idx]),
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 win->w_buffer->b_ffname, TRUE, TRUE) & FPC_SAME))));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 * Check if window "win" is editing the w_arg_idx file in its argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 check_arg_idx(win_T *win)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 if (WARGCOUNT(win) > 1 && !editing_arg_idx(win))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 // We are not editing the current entry in the argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 // Set "arg_had_last" if we are editing the last one.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 win->w_arg_idx_invalid = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 if (win->w_arg_idx != WARGCOUNT(win) - 1
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 && arg_had_last == FALSE
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 && ALIST(win) == &global_alist
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 && GARGCOUNT > 0
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 && win->w_arg_idx < GARGCOUNT
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 && (win->w_buffer->b_fnum == GARGLIST[GARGCOUNT - 1].ae_fnum
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 || (win->w_buffer->b_ffname != NULL
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 && (fullpathcmp(alist_name(&GARGLIST[GARGCOUNT - 1]),
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 win->w_buffer->b_ffname, TRUE, TRUE) & FPC_SAME))))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 arg_had_last = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 // We are editing the current entry in the argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 // Set "arg_had_last" if it's also the last one
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 win->w_arg_idx_invalid = FALSE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 if (win->w_arg_idx == WARGCOUNT(win) - 1
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 && win->w_alist == &global_alist)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 arg_had_last = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 * ":args", ":argslocal" and ":argsglobal".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 ex_args(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 if (eap->cmdidx != CMD_args)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 alist_unlink(ALIST(curwin));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 if (eap->cmdidx == CMD_argglobal)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 ALIST(curwin) = &global_alist;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 else // eap->cmdidx == CMD_arglocal
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 alist_new();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 if (*eap->arg != NUL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 // ":args file ..": define new argument list, handle like ":next"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 // Also for ":argslocal file .." and ":argsglobal file ..".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 ex_next(eap);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 else if (eap->cmdidx == CMD_args)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 // ":args": list arguments.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 if (ARGCOUNT > 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 char_u **items = ALLOC_MULT(char_u *, ARGCOUNT);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 if (items != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 // Overwrite the command, for a short list there is no
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 // scrolling required and no wait_return().
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 gotocmdline(TRUE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 for (i = 0; i < ARGCOUNT; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 items[i] = alist_name(&ARGLIST[i]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 list_in_columns(items, ARGCOUNT, curwin->w_arg_idx);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 vim_free(items);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 else if (eap->cmdidx == CMD_arglocal)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 garray_T *gap = &curwin->w_alist->al_ga;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 // ":argslocal": make a local copy of the global argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 if (ga_grow(gap, GARGCOUNT) == OK)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 for (i = 0; i < GARGCOUNT; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 if (GARGLIST[i].ae_fname != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fname =
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 vim_strsave(GARGLIST[i].ae_fname);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 AARGLIST(curwin->w_alist)[gap->ga_len].ae_fnum =
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 GARGLIST[i].ae_fnum;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 ++gap->ga_len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 * ":previous", ":sprevious", ":Next" and ":sNext".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 ex_previous(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 // If past the last one already, go to the last one.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 if (curwin->w_arg_idx - (int)eap->line2 >= ARGCOUNT)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 do_argfile(eap, ARGCOUNT - 1);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 do_argfile(eap, curwin->w_arg_idx - (int)eap->line2);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 * ":rewind", ":first", ":sfirst" and ":srewind".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 ex_rewind(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 do_argfile(eap, 0);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 * ":last" and ":slast".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 ex_last(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 do_argfile(eap, ARGCOUNT - 1);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 * ":argument" and ":sargument".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 ex_argument(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 if (eap->addr_count > 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 i = eap->line2 - 1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 i = curwin->w_arg_idx;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 do_argfile(eap, i);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 * Edit file "argn" of the argument lists.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 do_argfile(exarg_T *eap, int argn)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 int other;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 char_u *p;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 int old_arg_idx = curwin->w_arg_idx;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 if (ERROR_IF_POPUP_WINDOW)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 if (argn < 0 || argn >= ARGCOUNT)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 if (ARGCOUNT <= 1)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 emsg(_("E163: There is only one file to edit"));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 else if (argn < 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 emsg(_("E164: Cannot go before first file"));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 emsg(_("E165: Cannot go beyond last file"));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 setpcmark();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 #ifdef FEAT_GUI
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 need_mouse_correct = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 // split window or create new tab page first
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 if (*eap->cmd == 's' || cmdmod.tab != 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 if (win_split(0, 0) == FAIL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 RESET_BINDING(curwin);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 // if 'hidden' set, only check for changed file when re-editing
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 // the same buffer
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 other = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 if (buf_hide(curbuf))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 p = fix_fname(alist_name(&ARGLIST[argn]));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 other = otherfile(p);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 vim_free(p);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 if ((!buf_hide(curbuf) || !other)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 && check_changed(curbuf, CCGD_AW
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 | (other ? 0 : CCGD_MULTWIN)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 | (eap->forceit ? CCGD_FORCEIT : 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 | CCGD_EXCMD))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 curwin->w_arg_idx = argn;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 arg_had_last = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 // Edit the file; always use the last known line number.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 // When it fails (e.g. Abort for already edited file) restore the
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 // argument index.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 eap, ECMD_LAST,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 (buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 curwin->w_arg_idx = old_arg_idx;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 // like Vi: set the mark where the cursor is in the file.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 else if (eap->cmdidx != CMD_argdo)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 setmark('\'');
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 * ":next", and commands that behave like it.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 ex_next(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 // check for changed buffer now, if this fails the argument list is not
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 // redefined.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 if ( buf_hide(curbuf)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 || eap->cmdidx == CMD_snext
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 || !check_changed(curbuf, CCGD_AW
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 | (eap->forceit ? CCGD_FORCEIT : 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 | CCGD_EXCMD))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 if (*eap->arg != NUL) // redefine file list
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 if (do_arglist(eap->arg, AL_SET, 0, TRUE) == FAIL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 i = 0;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 i = curwin->w_arg_idx + (int)eap->line2;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 do_argfile(eap, i);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 * ":argedit"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 ex_argedit(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 int i = eap->addr_count ? (int)eap->line2 : curwin->w_arg_idx + 1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 // Whether curbuf will be reused, curbuf->b_ffname will be set.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 int curbuf_is_reusable = curbuf_reusable();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 if (do_arglist(eap->arg, AL_ADD, i, TRUE) == FAIL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 #ifdef FEAT_TITLE
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 maketitle();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 if (curwin->w_arg_idx == 0
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 && (curbuf->b_ml.ml_flags & ML_EMPTY)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 && (curbuf->b_ffname == NULL || curbuf_is_reusable))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 i = 0;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 // Edit the argument.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 if (i < ARGCOUNT)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 do_argfile(eap, i);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 * ":argadd"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 ex_argadd(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 do_arglist(eap->arg, AL_ADD,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 FALSE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 #ifdef FEAT_TITLE
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 maketitle();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 * ":argdelete"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 ex_argdelete(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 int n;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 if (eap->addr_count > 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 // ":1,4argdel": Delete all arguments in the range.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 if (eap->line2 > ARGCOUNT)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 eap->line2 = ARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 n = eap->line2 - eap->line1 + 1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 if (*eap->arg != NUL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 // Can't have both a range and an argument.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 emsg(_(e_invarg));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 else if (n <= 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 // Don't give an error for ":%argdel" if the list is empty.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 if (eap->line1 != 1 || eap->line2 != 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 emsg(_(e_invrange));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 for (i = eap->line1; i <= eap->line2; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 vim_free(ARGLIST[i - 1].ae_fname);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 mch_memmove(ARGLIST + eap->line1 - 1, ARGLIST + eap->line2,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 (size_t)((ARGCOUNT - eap->line2) * sizeof(aentry_T)));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 ALIST(curwin)->al_ga.ga_len -= n;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 if (curwin->w_arg_idx >= eap->line2)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 curwin->w_arg_idx -= n;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 else if (curwin->w_arg_idx > eap->line1)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 curwin->w_arg_idx = eap->line1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 if (ARGCOUNT == 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 curwin->w_arg_idx = 0;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 else if (curwin->w_arg_idx >= ARGCOUNT)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 curwin->w_arg_idx = ARGCOUNT - 1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 else if (*eap->arg == NUL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 emsg(_(e_argreq));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 do_arglist(eap->arg, AL_DEL, 0, FALSE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 #ifdef FEAT_TITLE
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 maketitle();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 * Function given to ExpandGeneric() to obtain the possible arguments of the
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 * argedit and argdelete commands.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 char_u *
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 get_arglist_name(expand_T *xp UNUSED, int idx)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 if (idx >= ARGCOUNT)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 return NULL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 return alist_name(&ARGLIST[idx]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 * Get the file name for an argument list entry.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 char_u *
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 alist_name(aentry_T *aep)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 buf_T *bp;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 // Use the name from the associated buffer if it exists.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 bp = buflist_findnr(aep->ae_fnum);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 if (bp == NULL || bp->b_fname == NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 return aep->ae_fname;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 return bp->b_fname;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 * do_arg_all(): Open up to 'count' windows, one for each argument.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 static void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 do_arg_all(
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 int count,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 int forceit, // hide buffers in current windows
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 int keep_tabs) // keep current tabs, for ":tab drop file"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 int i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 win_T *wp, *wpnext;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 char_u *opened; // Array of weight for which args are open:
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 // 0: not opened
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 // 1: opened in other tab
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 // 2: opened in curtab
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 // 3: opened in curtab and curwin
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 //
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 int opened_len; // length of opened[]
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 int use_firstwin = FALSE; // use first window for arglist
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 int split_ret = OK;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 int p_ea_save;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 alist_T *alist; // argument list to be used
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 buf_T *buf;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 tabpage_T *tpnext;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 int had_tab = cmdmod.tab;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 win_T *old_curwin, *last_curwin;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 tabpage_T *old_curtab, *last_curtab;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 win_T *new_curwin = NULL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 tabpage_T *new_curtab = NULL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 if (ARGCOUNT <= 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 // Don't give an error message. We don't want it when the ":all"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 // command is in the .vimrc.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 setpcmark();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 opened_len = ARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 opened = alloc_clear(opened_len);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 if (opened == NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 return;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 // Autocommands may do anything to the argument list. Make sure it's not
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 // freed while we are working here by "locking" it. We still have to
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 // watch out for its size to be changed.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 alist = curwin->w_alist;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 ++alist->al_refcount;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 old_curwin = curwin;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 old_curtab = curtab;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 # ifdef FEAT_GUI
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 need_mouse_correct = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 # endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 // Try closing all windows that are not in the argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 // Also close windows that are not full width;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 // When 'hidden' or "forceit" set the buffer becomes hidden.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 // Windows that have a changed buffer and can't be hidden won't be closed.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 // When the ":tab" modifier was used do this for all tab pages.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 if (had_tab > 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 goto_tabpage_tp(first_tabpage, TRUE, TRUE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 for (;;)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 tpnext = curtab->tp_next;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 for (wp = firstwin; wp != NULL; wp = wpnext)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 wpnext = wp->w_next;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 buf = wp->w_buffer;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 if (buf->b_ffname == NULL
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 || (!keep_tabs && (buf->b_nwindows > 1
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 || wp->w_width != Columns)))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 i = opened_len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 // check if the buffer in this window is in the arglist
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 for (i = 0; i < opened_len; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 if (i < alist->al_ga.ga_len
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 && (AARGLIST(alist)[i].ae_fnum == buf->b_fnum
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 || fullpathcmp(alist_name(&AARGLIST(alist)[i]),
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 buf->b_ffname, TRUE, TRUE) & FPC_SAME))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 int weight = 1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 if (old_curtab == curtab)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 ++weight;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 if (old_curwin == wp)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 ++weight;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 if (weight > (int)opened[i])
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 opened[i] = (char_u)weight;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 if (i == 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 if (new_curwin != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 new_curwin->w_arg_idx = opened_len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 new_curwin = wp;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 new_curtab = curtab;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 else if (keep_tabs)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 i = opened_len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 if (wp->w_alist != alist)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 // Use the current argument list for all windows
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 // containing a file from it.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 alist_unlink(wp->w_alist);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 wp->w_alist = alist;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 ++wp->w_alist->al_refcount;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 wp->w_arg_idx = i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 if (i == opened_len && !keep_tabs)// close this window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 if (buf_hide(buf) || forceit || buf->b_nwindows > 1
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 || !bufIsChanged(buf))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 // If the buffer was changed, and we would like to hide it,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 // try autowriting.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 if (!buf_hide(buf) && buf->b_nwindows <= 1
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 && bufIsChanged(buf))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 bufref_T bufref;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 set_bufref(&bufref, buf);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 (void)autowrite(buf, FALSE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 // check if autocommands removed the window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 if (!win_valid(wp) || !bufref_valid(&bufref))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 wpnext = firstwin; // start all over...
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 continue;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 // don't close last window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 if (ONE_WINDOW
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 && (first_tabpage->tp_next == NULL || !had_tab))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 use_firstwin = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 win_close(wp, !buf_hide(buf) && !bufIsChanged(buf));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 // check if autocommands removed the next window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 if (!win_valid(wpnext))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 wpnext = firstwin; // start all over...
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 // Without the ":tab" modifier only do the current tab page.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 if (had_tab == 0 || tpnext == NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 // check if autocommands removed the next tab page
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 if (!valid_tabpage(tpnext))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 tpnext = first_tabpage; // start all over...
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 goto_tabpage_tp(tpnext, TRUE, TRUE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 // Open a window for files in the argument list that don't have one.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 // ARGCOUNT may change while doing this, because of autocommands.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 if (count > opened_len || count <= 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 count = opened_len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 // Don't execute Win/Buf Enter/Leave autocommands here.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 ++autocmd_no_enter;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 ++autocmd_no_leave;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 last_curwin = curwin;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 last_curtab = curtab;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 win_enter(lastwin, FALSE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 // ":drop all" should re-use an empty window to avoid "--remote-tab"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 // leaving an empty tab page when executed locally.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 if (keep_tabs && BUFEMPTY() && curbuf->b_nwindows == 1
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 && curbuf->b_ffname == NULL && !curbuf->b_changed)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 use_firstwin = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 for (i = 0; i < count && i < opened_len && !got_int; ++i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 if (alist == &global_alist && i == global_alist.al_ga.ga_len - 1)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 arg_had_last = TRUE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 if (opened[i] > 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 // Move the already present window to below the current window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 if (curwin->w_arg_idx != i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 for (wpnext = firstwin; wpnext != NULL; wpnext = wpnext->w_next)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 if (wpnext->w_arg_idx == i)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 if (keep_tabs)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 new_curwin = wpnext;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 new_curtab = curtab;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 else if (wpnext->w_frame->fr_parent
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 != curwin->w_frame->fr_parent)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 emsg(_("E249: window layout changed unexpectedly"));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 i = count;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 win_move_after(wpnext, curwin);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 else if (split_ret == OK)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 if (!use_firstwin) // split current window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 p_ea_save = p_ea;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 p_ea = TRUE; // use space from all windows
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 split_ret = win_split(0, WSP_ROOM | WSP_BELOW);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 p_ea = p_ea_save;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 if (split_ret == FAIL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 continue;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 else // first window: do autocmd for leaving this buffer
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 --autocmd_no_leave;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 // edit file "i"
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 curwin->w_arg_idx = i;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 if (i == 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 new_curwin = curwin;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 new_curtab = curtab;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 (void)do_ecmd(0, alist_name(&AARGLIST(alist)[i]), NULL, NULL,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 ECMD_ONE,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 ((buf_hide(curwin->w_buffer)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 + ECMD_OLDBUF, curwin);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 if (use_firstwin)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 ++autocmd_no_leave;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 use_firstwin = FALSE;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 ui_breakcheck();
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 // When ":tab" was used open a new tab for a new window repeatedly.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 cmdmod.tab = 9999;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 // Remove the "lock" on the argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 alist_unlink(alist);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 --autocmd_no_enter;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 // restore last referenced tabpage's curwin
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 if (last_curtab != new_curtab)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 if (valid_tabpage(last_curtab))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 goto_tabpage_tp(last_curtab, TRUE, TRUE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 if (win_valid(last_curwin))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 win_enter(last_curwin, FALSE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 // to window with first arg
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 if (valid_tabpage(new_curtab))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 goto_tabpage_tp(new_curtab, TRUE, TRUE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 if (win_valid(new_curwin))
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 win_enter(new_curwin, FALSE);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 --autocmd_no_leave;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 vim_free(opened);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 * ":all" and ":sall".
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 * Also used for ":tab drop file ..." after setting the argument list.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 ex_all(exarg_T *eap)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 if (eap->addr_count == 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 eap->line2 = 9999;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 do_arg_all((int)eap->line2, eap->forceit, eap->cmdidx == CMD_drop);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 * Concatenate all files in the argument list, separated by spaces, and return
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 * it in one allocated string.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 * Spaces and backslashes in the file names are escaped with a backslash.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 * Returns NULL when out of memory.
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 char_u *
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 arg_all(void)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 int len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 int idx;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 char_u *retval = NULL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 char_u *p;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 // Do this loop two times:
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 // first time: compute the total length
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 // second time: concatenate the names
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 for (;;)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 len = 0;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 for (idx = 0; idx < ARGCOUNT; ++idx)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 p = alist_name(&ARGLIST[idx]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 if (p != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 if (len > 0)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 // insert a space in between names
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 if (retval != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 retval[len] = ' ';
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 ++len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 for ( ; *p != NUL; ++p)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 if (*p == ' '
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 #ifndef BACKSLASH_IN_FILENAME
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 || *p == '\\'
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 #endif
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 || *p == '`')
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 // insert a backslash
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 if (retval != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 retval[len] = '\\';
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 ++len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 if (retval != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 retval[len] = *p;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 ++len;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 // second time: break here
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 if (retval != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 retval[len] = NUL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 // allocate memory
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 retval = alloc(len + 1);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 if (retval == NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 break;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 return retval;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 #if defined(FEAT_EVAL) || defined(PROTO)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 * "argc([window id])" function
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 f_argc(typval_T *argvars, typval_T *rettv)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 win_T *wp;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 if (argvars[0].v_type == VAR_UNKNOWN)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 // use the current window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 rettv->vval.v_number = ARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 else if (argvars[0].v_type == VAR_NUMBER
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 && tv_get_number(&argvars[0]) == -1)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 // use the global argument list
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 rettv->vval.v_number = GARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 // use the argument list of the specified window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 wp = find_win_by_nr_or_id(&argvars[0]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 if (wp != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 rettv->vval.v_number = WARGCOUNT(wp);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 rettv->vval.v_number = -1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 * "argidx()" function
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 f_argidx(typval_T *argvars UNUSED, typval_T *rettv)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 rettv->vval.v_number = curwin->w_arg_idx;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 * "arglistid()" function
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 f_arglistid(typval_T *argvars, typval_T *rettv)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 win_T *wp;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 rettv->vval.v_number = -1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 wp = find_tabwin(&argvars[0], &argvars[1], NULL);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 if (wp != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 rettv->vval.v_number = wp->w_alist->id;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 * Get the argument list for a given window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 static void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 get_arglist_as_rettv(aentry_T *arglist, int argcount, typval_T *rettv)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 int idx;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 if (rettv_list_alloc(rettv) == OK && arglist != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 for (idx = 0; idx < argcount; ++idx)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 list_append_string(rettv->vval.v_list,
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 alist_name(&arglist[idx]), -1);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 /*
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 * "argv(nr)" function
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 */
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 void
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 f_argv(typval_T *argvars, typval_T *rettv)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 int idx;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 aentry_T *arglist = NULL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 int argcount = -1;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 if (argvars[0].v_type != VAR_UNKNOWN)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 if (argvars[1].v_type == VAR_UNKNOWN)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 arglist = ARGLIST;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 argcount = ARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 else if (argvars[1].v_type == VAR_NUMBER
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 && tv_get_number(&argvars[1]) == -1)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 arglist = GARGLIST;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 argcount = GARGCOUNT;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 win_T *wp = find_win_by_nr_or_id(&argvars[1]);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 if (wp != NULL)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 {
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 // Use the argument list of the specified window
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 arglist = WARGLIST(wp);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 argcount = WARGCOUNT(wp);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 rettv->v_type = VAR_STRING;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 rettv->vval.v_string = NULL;
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 idx = tv_get_number_chk(&argvars[0], NULL);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 if (arglist != NULL && idx >= 0 && idx < argcount)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 rettv->vval.v_string = vim_strsave(alist_name(&arglist[idx]));
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 else if (idx == -1)
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 get_arglist_as_rettv(arglist, argcount, rettv);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 else
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 get_arglist_as_rettv(ARGLIST, ARGCOUNT, rettv);
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 }
4a3dca734d36 patch 8.1.1869: code for the argument list is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 #endif