Mercurial > vim
annotate src/quickfix.c @ 9175:d415c079f84e v7.4.1871
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 2 13:40:04 2016 +0200
patch 7.4.1871
Problem: Appending to the quickfix list while the quickfix window is open
is very slow.
Solution: Do not delete all the lines, only append the new ones. Avoid
using a window while updating the list. (closes #841)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 02 Jun 2016 13:45:05 +0200 |
parents | f221aec7fcca |
children | 543f068f3706 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * quickfix.c: functions for quickfix mode, using a file with error messages | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 #if defined(FEAT_QUICKFIX) || defined(PROTO) | |
17 | |
18 struct dir_stack_T | |
19 { | |
20 struct dir_stack_T *next; | |
21 char_u *dirname; | |
22 }; | |
23 | |
24 static struct dir_stack_T *dir_stack = NULL; | |
25 | |
26 /* | |
230 | 27 * For each error the next struct is allocated and linked in a list. |
7 | 28 */ |
230 | 29 typedef struct qfline_S qfline_T; |
30 struct qfline_S | |
7 | 31 { |
230 | 32 qfline_T *qf_next; /* pointer to next error in the list */ |
33 qfline_T *qf_prev; /* pointer to previous error in the list */ | |
34 linenr_T qf_lnum; /* line number where the error occurred */ | |
35 int qf_fnum; /* file number for the line */ | |
36 int qf_col; /* column where the error occurred */ | |
37 int qf_nr; /* error number */ | |
38 char_u *qf_pattern; /* search pattern for the error */ | |
39 char_u *qf_text; /* description of the error */ | |
40 char_u qf_viscol; /* set to TRUE if qf_col is screen column */ | |
41 char_u qf_cleared; /* set to TRUE if line has been deleted */ | |
42 char_u qf_type; /* type of the error (mostly 'E'); 1 for | |
7 | 43 :helpgrep */ |
230 | 44 char_u qf_valid; /* valid error message detected */ |
7 | 45 }; |
46 | |
47 /* | |
48 * There is a stack of error lists. | |
49 */ | |
50 #define LISTCOUNT 10 | |
51 | |
644 | 52 typedef struct qf_list_S |
7 | 53 { |
230 | 54 qfline_T *qf_start; /* pointer to the first error */ |
55 qfline_T *qf_ptr; /* pointer to the current error */ | |
56 int qf_count; /* number of errors (0 means no error list) */ | |
57 int qf_index; /* current index in the error list */ | |
58 int qf_nonevalid; /* TRUE if not a single valid entry found */ | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
59 char_u *qf_title; /* title derived from the command that created |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
60 * the error list */ |
644 | 61 } qf_list_T; |
62 | |
63 struct qf_info_S | |
64 { | |
65 /* | |
66 * Count of references to this list. Used only for location lists. | |
67 * When a location list window reference this list, qf_refcount | |
68 * will be 2. Otherwise, qf_refcount will be 1. When qf_refcount | |
69 * reaches 0, the list is freed. | |
70 */ | |
71 int qf_refcount; | |
72 int qf_listcount; /* current number of lists */ | |
73 int qf_curlist; /* current error list */ | |
74 qf_list_T qf_lists[LISTCOUNT]; | |
75 }; | |
76 | |
77 static qf_info_T ql_info; /* global quickfix list */ | |
7 | 78 |
230 | 79 #define FMT_PATTERNS 10 /* maximum number of % recognized */ |
7 | 80 |
81 /* | |
82 * Structure used to hold the info of one part of 'errorformat' | |
83 */ | |
789 | 84 typedef struct efm_S efm_T; |
85 struct efm_S | |
7 | 86 { |
87 regprog_T *prog; /* pre-formatted part of 'errorformat' */ | |
789 | 88 efm_T *next; /* pointer to next (NULL if last) */ |
7 | 89 char_u addr[FMT_PATTERNS]; /* indices of used % patterns */ |
90 char_u prefix; /* prefix of this format line: */ | |
91 /* 'D' enter directory */ | |
92 /* 'X' leave directory */ | |
93 /* 'A' start of multi-line message */ | |
94 /* 'E' error message */ | |
95 /* 'W' warning message */ | |
96 /* 'I' informational message */ | |
97 /* 'C' continuation line */ | |
98 /* 'Z' end of multi-line message */ | |
99 /* 'G' general, unspecific message */ | |
100 /* 'P' push file (partial) message */ | |
101 /* 'Q' pop/quit file (partial) message */ | |
102 /* 'O' overread (partial) message */ | |
103 char_u flags; /* additional flags given in prefix */ | |
104 /* '-' do not include this line */ | |
625 | 105 /* '+' include whole line in message */ |
789 | 106 int conthere; /* %> used */ |
7 | 107 }; |
108 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
109 static int qf_init_ext(qf_info_T *qi, char_u *efile, buf_T *buf, typval_T *tv, char_u *errorformat, int newlist, linenr_T lnumfirst, linenr_T lnumlast, char_u *qf_title); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
110 static void qf_store_title(qf_info_T *qi, char_u *title); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
111 static void qf_new_list(qf_info_T *qi, char_u *qf_title); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
112 static void ll_free_all(qf_info_T **pqi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
113 static int qf_add_entry(qf_info_T *qi, qfline_T **prevp, char_u *dir, char_u *fname, int bufnum, char_u *mesg, long lnum, int col, int vis_col, char_u *pattern, int nr, int type, int valid); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
114 static qf_info_T *ll_new_list(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
115 static void qf_msg(qf_info_T *qi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
116 static void qf_free(qf_info_T *qi, int idx); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
117 static char_u *qf_types(int, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
118 static int qf_get_fnum(char_u *, char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
119 static char_u *qf_push_dir(char_u *, struct dir_stack_T **); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
120 static char_u *qf_pop_dir(struct dir_stack_T **); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
121 static char_u *qf_guess_filepath(char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
122 static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
123 static void qf_clean_dir_stack(struct dir_stack_T **); |
7 | 124 #ifdef FEAT_WINDOWS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
125 static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
126 static int is_qf_win(win_T *win, qf_info_T *qi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
127 static win_T *qf_find_win(qf_info_T *qi); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
128 static buf_T *qf_find_buf(qf_info_T *qi); |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
129 static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
130 static void qf_set_title_var(qf_info_T *qi); |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
131 static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last); |
7 | 132 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
133 static char_u *get_mef_name(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
134 static void restore_start_dir(char_u *dirname_start); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
135 static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
136 static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
137 static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7710
diff
changeset
|
138 static qf_info_T *ll_get_or_alloc_list(win_T *); |
7 | 139 |
644 | 140 /* Quickfix window check helper macro */ |
141 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL) | |
142 /* Location list window check helper macro */ | |
143 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL) | |
144 /* | |
145 * Return location list for window 'wp' | |
146 * For location list window, return the referenced location list | |
147 */ | |
148 #define GET_LOC_LIST(wp) (IS_LL_WINDOW(wp) ? wp->w_llist_ref : wp->w_llist) | |
149 | |
7 | 150 /* |
41 | 151 * Read the errorfile "efile" into memory, line by line, building the error |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
152 * list. Set the error list's title to qf_title. |
7 | 153 * Return -1 for error, number of errors for success. |
154 */ | |
155 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
156 qf_init( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
157 win_T *wp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
158 char_u *efile, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
159 char_u *errorformat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
160 int newlist, /* TRUE: start a new error list */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
161 char_u *qf_title) |
7 | 162 { |
644 | 163 qf_info_T *qi = &ql_info; |
164 | |
165 if (wp != NULL) | |
665 | 166 { |
167 qi = ll_get_or_alloc_list(wp); | |
168 if (qi == NULL) | |
169 return FAIL; | |
170 } | |
644 | 171 |
172 return qf_init_ext(qi, efile, curbuf, NULL, errorformat, newlist, | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
173 (linenr_T)0, (linenr_T)0, |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
174 qf_title); |
41 | 175 } |
176 | |
177 /* | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
178 * Maximum number of bytes allowed per line while reading a errorfile. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
179 */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
180 #define LINE_MAXLEN 4096 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
181 |
9114
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
182 static char_u * |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
183 qf_grow_linebuf(char_u **growbuf, int *growbufsiz, int newsz, int *allocsz) |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
184 { |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
185 /* |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
186 * If the line exceeds LINE_MAXLEN exclude the last |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
187 * byte since it's not a NL character. |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
188 */ |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
189 *allocsz = newsz > LINE_MAXLEN ? LINE_MAXLEN - 1 : newsz; |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
190 if (*growbuf == NULL) |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
191 { |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
192 *growbuf = alloc(*allocsz + 1); |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
193 if (*growbuf == NULL) |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
194 return NULL; |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
195 *growbufsiz = *allocsz; |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
196 } |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
197 else if (*allocsz > *growbufsiz) |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
198 { |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
199 *growbuf = vim_realloc(*growbuf, *allocsz + 1); |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
200 if (*growbuf == NULL) |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
201 return NULL; |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
202 *growbufsiz = *allocsz; |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
203 } |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
204 return *growbuf; |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
205 } |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
206 |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
207 /* |
41 | 208 * Read the errorfile "efile" into memory, line by line, building the error |
209 * list. | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
210 * Alternative: when "efile" is NULL read errors from buffer "buf". |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
211 * Alternative: when "tv" is not NULL get errors from the string or list. |
41 | 212 * Always use 'errorformat' from "buf" if there is a local value. |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
213 * Then "lnumfirst" and "lnumlast" specify the range of lines to use. |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
214 * Set the title of the list to "qf_title". |
41 | 215 * Return -1 for error, number of errors for success. |
216 */ | |
217 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
218 qf_init_ext( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
219 qf_info_T *qi, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
220 char_u *efile, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
221 buf_T *buf, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
222 typval_T *tv, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
223 char_u *errorformat, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
224 int newlist, /* TRUE: start a new error list */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
225 linenr_T lnumfirst, /* first line number to use */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
226 linenr_T lnumlast, /* last line number to use */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
227 char_u *qf_title) |
41 | 228 { |
7 | 229 char_u *namebuf; |
230 char_u *errmsg; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
231 int errmsglen; |
230 | 232 char_u *pattern; |
7 | 233 char_u *fmtstr = NULL; |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
234 char_u *growbuf = NULL; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
235 int growbuflen; |
9060
616793d0412b
commit https://github.com/vim/vim/commit/9a3b3311d26c990208150255ad65472bb4eefaa4
Christian Brabandt <cb@256bit.org>
parents:
9056
diff
changeset
|
236 int growbufsiz = 0; |
616793d0412b
commit https://github.com/vim/vim/commit/9a3b3311d26c990208150255ad65472bb4eefaa4
Christian Brabandt <cb@256bit.org>
parents:
9056
diff
changeset
|
237 char_u *linebuf = NULL; |
616793d0412b
commit https://github.com/vim/vim/commit/9a3b3311d26c990208150255ad65472bb4eefaa4
Christian Brabandt <cb@256bit.org>
parents:
9056
diff
changeset
|
238 int linelen = 0; |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
239 int discard; |
7 | 240 int col = 0; |
170 | 241 char_u use_viscol = FALSE; |
7 | 242 int type = 0; |
243 int valid; | |
41 | 244 linenr_T buflnum = lnumfirst; |
7 | 245 long lnum = 0L; |
246 int enr = 0; | |
41 | 247 FILE *fd = NULL; |
230 | 248 qfline_T *qfprev = NULL; /* init to make SASC shut up */ |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
249 #ifdef FEAT_WINDOWS |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
250 qfline_T *old_last = NULL; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
251 #endif |
7 | 252 char_u *efmp; |
789 | 253 efm_T *fmt_first = NULL; |
254 efm_T *fmt_last = NULL; | |
255 efm_T *fmt_ptr; | |
256 efm_T *fmt_start = NULL; | |
7 | 257 char_u *efm; |
258 char_u *ptr; | |
259 char_u *srcptr; | |
260 int len; | |
261 int i; | |
262 int round; | |
263 int idx = 0; | |
264 int multiline = FALSE; | |
265 int multiignore = FALSE; | |
266 int multiscan = FALSE; | |
267 int retval = -1; /* default: return error flag */ | |
268 char_u *directory = NULL; | |
269 char_u *currfile = NULL; | |
270 char_u *tail = NULL; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
271 char_u *p_buf = NULL; |
446 | 272 char_u *p_str = NULL; |
273 listitem_T *p_li = NULL; | |
7 | 274 struct dir_stack_T *file_stack = NULL; |
275 regmatch_T regmatch; | |
276 static struct fmtpattern | |
277 { | |
278 char_u convchar; | |
279 char *pattern; | |
280 } fmt_pat[FMT_PATTERNS] = | |
281 { | |
502 | 282 {'f', ".\\+"}, /* only used when at end */ |
7 | 283 {'n', "\\d\\+"}, |
284 {'l', "\\d\\+"}, | |
285 {'c', "\\d\\+"}, | |
286 {'t', "."}, | |
287 {'m', ".\\+"}, | |
288 {'r', ".*"}, | |
3555 | 289 {'p', "[- .]*"}, |
230 | 290 {'v', "\\d\\+"}, |
291 {'s', ".\\+"} | |
7 | 292 }; |
293 | |
7558
9a4c9dccd603
commit https://github.com/vim/vim/commit/b86a343280b08d6701da68ee0651e960a0a7a61c
Christian Brabandt <cb@256bit.org>
parents:
7515
diff
changeset
|
294 namebuf = alloc_id(CMDBUFFSIZE + 1, aid_qf_namebuf); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
295 errmsglen = CMDBUFFSIZE + 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
296 errmsg = alloc_id(errmsglen, aid_qf_errmsg); |
7558
9a4c9dccd603
commit https://github.com/vim/vim/commit/b86a343280b08d6701da68ee0651e960a0a7a61c
Christian Brabandt <cb@256bit.org>
parents:
7515
diff
changeset
|
297 pattern = alloc_id(CMDBUFFSIZE + 1, aid_qf_pattern); |
230 | 298 if (namebuf == NULL || errmsg == NULL || pattern == NULL) |
7 | 299 goto qf_init_end; |
300 | |
41 | 301 if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL) |
7 | 302 { |
303 EMSG2(_(e_openerrf), efile); | |
304 goto qf_init_end; | |
305 } | |
306 | |
644 | 307 if (newlist || qi->qf_curlist == qi->qf_listcount) |
7 | 308 /* make place for a new list */ |
3965 | 309 qf_new_list(qi, qf_title); |
644 | 310 else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
311 { |
7 | 312 /* Adding to existing list, find last entry. */ |
644 | 313 for (qfprev = qi->qf_lists[qi->qf_curlist].qf_start; |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
314 qfprev->qf_next != qfprev; qfprev = qfprev->qf_next) |
7 | 315 ; |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
316 old_last = qfprev; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
317 } |
7 | 318 |
319 /* | |
320 * Each part of the format string is copied and modified from errorformat to | |
321 * regex prog. Only a few % characters are allowed. | |
322 */ | |
323 /* Use the local value of 'errorformat' if it's set. */ | |
446 | 324 if (errorformat == p_efm && tv == NULL && *buf->b_p_efm != NUL) |
41 | 325 efm = buf->b_p_efm; |
7 | 326 else |
327 efm = errorformat; | |
328 /* | |
329 * Get some space to modify the format string into. | |
330 */ | |
331 i = (FMT_PATTERNS * 3) + ((int)STRLEN(efm) << 2); | |
332 for (round = FMT_PATTERNS; round > 0; ) | |
333 i += (int)STRLEN(fmt_pat[--round].pattern); | |
334 #ifdef COLON_IN_FILENAME | |
335 i += 12; /* "%f" can become twelve chars longer */ | |
336 #else | |
337 i += 2; /* "%f" can become two chars longer */ | |
338 #endif | |
339 if ((fmtstr = alloc(i)) == NULL) | |
340 goto error2; | |
341 | |
789 | 342 while (efm[0] != NUL) |
7 | 343 { |
344 /* | |
345 * Allocate a new eformat structure and put it at the end of the list | |
346 */ | |
789 | 347 fmt_ptr = (efm_T *)alloc_clear((unsigned)sizeof(efm_T)); |
7 | 348 if (fmt_ptr == NULL) |
349 goto error2; | |
350 if (fmt_first == NULL) /* first one */ | |
351 fmt_first = fmt_ptr; | |
352 else | |
353 fmt_last->next = fmt_ptr; | |
354 fmt_last = fmt_ptr; | |
355 | |
356 /* | |
357 * Isolate one part in the 'errorformat' option | |
358 */ | |
359 for (len = 0; efm[len] != NUL && efm[len] != ','; ++len) | |
360 if (efm[len] == '\\' && efm[len + 1] != NUL) | |
361 ++len; | |
362 | |
363 /* | |
364 * Build regexp pattern from current 'errorformat' option | |
365 */ | |
366 ptr = fmtstr; | |
367 *ptr++ = '^'; | |
789 | 368 round = 0; |
7 | 369 for (efmp = efm; efmp < efm + len; ++efmp) |
370 { | |
371 if (*efmp == '%') | |
372 { | |
373 ++efmp; | |
374 for (idx = 0; idx < FMT_PATTERNS; ++idx) | |
375 if (fmt_pat[idx].convchar == *efmp) | |
376 break; | |
377 if (idx < FMT_PATTERNS) | |
378 { | |
379 if (fmt_ptr->addr[idx]) | |
380 { | |
381 sprintf((char *)errmsg, | |
382 _("E372: Too many %%%c in format string"), *efmp); | |
383 EMSG(errmsg); | |
384 goto error2; | |
385 } | |
386 if ((idx | |
387 && idx < 6 | |
388 && vim_strchr((char_u *)"DXOPQ", | |
389 fmt_ptr->prefix) != NULL) | |
390 || (idx == 6 | |
391 && vim_strchr((char_u *)"OPQ", | |
392 fmt_ptr->prefix) == NULL)) | |
393 { | |
394 sprintf((char *)errmsg, | |
395 _("E373: Unexpected %%%c in format string"), *efmp); | |
396 EMSG(errmsg); | |
397 goto error2; | |
398 } | |
399 fmt_ptr->addr[idx] = (char_u)++round; | |
400 *ptr++ = '\\'; | |
401 *ptr++ = '('; | |
402 #ifdef BACKSLASH_IN_FILENAME | |
403 if (*efmp == 'f') | |
404 { | |
405 /* Also match "c:" in the file name, even when | |
406 * checking for a colon next: "%f:". | |
407 * "\%(\a:\)\=" */ | |
408 STRCPY(ptr, "\\%(\\a:\\)\\="); | |
409 ptr += 10; | |
410 } | |
411 #endif | |
502 | 412 if (*efmp == 'f' && efmp[1] != NUL) |
7 | 413 { |
502 | 414 if (efmp[1] != '\\' && efmp[1] != '%') |
415 { | |
416 /* A file name may contain spaces, but this isn't | |
417 * in "\f". For "%f:%l:%m" there may be a ":" in | |
418 * the file name. Use ".\{-1,}x" instead (x is | |
419 * the next character), the requirement that :999: | |
420 * follows should work. */ | |
421 STRCPY(ptr, ".\\{-1,}"); | |
422 ptr += 7; | |
423 } | |
424 else | |
425 { | |
426 /* File name followed by '\\' or '%': include as | |
427 * many file name chars as possible. */ | |
428 STRCPY(ptr, "\\f\\+"); | |
429 ptr += 4; | |
430 } | |
7 | 431 } |
432 else | |
433 { | |
434 srcptr = (char_u *)fmt_pat[idx].pattern; | |
435 while ((*ptr = *srcptr++) != NUL) | |
436 ++ptr; | |
437 } | |
438 *ptr++ = '\\'; | |
439 *ptr++ = ')'; | |
440 } | |
441 else if (*efmp == '*') | |
442 { | |
443 if (*++efmp == '[' || *efmp == '\\') | |
444 { | |
445 if ((*ptr++ = *efmp) == '[') /* %*[^a-z0-9] etc. */ | |
446 { | |
447 if (efmp[1] == '^') | |
448 *ptr++ = *++efmp; | |
449 if (efmp < efm + len) | |
450 { | |
451 *ptr++ = *++efmp; /* could be ']' */ | |
452 while (efmp < efm + len | |
453 && (*ptr++ = *++efmp) != ']') | |
454 /* skip */; | |
455 if (efmp == efm + len) | |
456 { | |
457 EMSG(_("E374: Missing ] in format string")); | |
458 goto error2; | |
459 } | |
460 } | |
461 } | |
462 else if (efmp < efm + len) /* %*\D, %*\s etc. */ | |
463 *ptr++ = *++efmp; | |
464 *ptr++ = '\\'; | |
465 *ptr++ = '+'; | |
466 } | |
467 else | |
468 { | |
469 /* TODO: scanf()-like: %*ud, %*3c, %*f, ... ? */ | |
470 sprintf((char *)errmsg, | |
471 _("E375: Unsupported %%%c in format string"), *efmp); | |
472 EMSG(errmsg); | |
473 goto error2; | |
474 } | |
475 } | |
476 else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL) | |
477 *ptr++ = *efmp; /* regexp magic characters */ | |
478 else if (*efmp == '#') | |
479 *ptr++ = '*'; | |
789 | 480 else if (*efmp == '>') |
481 fmt_ptr->conthere = TRUE; | |
7 | 482 else if (efmp == efm + 1) /* analyse prefix */ |
483 { | |
484 if (vim_strchr((char_u *)"+-", *efmp) != NULL) | |
485 fmt_ptr->flags = *efmp++; | |
486 if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL) | |
487 fmt_ptr->prefix = *efmp; | |
488 else | |
489 { | |
490 sprintf((char *)errmsg, | |
491 _("E376: Invalid %%%c in format string prefix"), *efmp); | |
492 EMSG(errmsg); | |
493 goto error2; | |
494 } | |
495 } | |
496 else | |
497 { | |
498 sprintf((char *)errmsg, | |
499 _("E377: Invalid %%%c in format string"), *efmp); | |
500 EMSG(errmsg); | |
501 goto error2; | |
502 } | |
503 } | |
504 else /* copy normal character */ | |
505 { | |
506 if (*efmp == '\\' && efmp + 1 < efm + len) | |
507 ++efmp; | |
508 else if (vim_strchr((char_u *)".*^$~[", *efmp) != NULL) | |
509 *ptr++ = '\\'; /* escape regexp atoms */ | |
510 if (*efmp) | |
511 *ptr++ = *efmp; | |
512 } | |
513 } | |
514 *ptr++ = '$'; | |
515 *ptr = NUL; | |
516 if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL) | |
517 goto error2; | |
518 /* | |
519 * Advance to next part | |
520 */ | |
521 efm = skip_to_option_part(efm + len); /* skip comma and spaces */ | |
522 } | |
523 if (fmt_first == NULL) /* nothing found */ | |
524 { | |
525 EMSG(_("E378: 'errorformat' contains no pattern")); | |
526 goto error2; | |
527 } | |
528 | |
529 /* | |
530 * got_int is reset here, because it was probably set when killing the | |
531 * ":make" command, but we still want to read the errorfile then. | |
532 */ | |
533 got_int = FALSE; | |
534 | |
535 /* Always ignore case when looking for a matching error. */ | |
536 regmatch.rm_ic = TRUE; | |
537 | |
446 | 538 if (tv != NULL) |
539 { | |
540 if (tv->v_type == VAR_STRING) | |
541 p_str = tv->vval.v_string; | |
542 else if (tv->v_type == VAR_LIST) | |
543 p_li = tv->vval.v_list->lv_first; | |
544 } | |
545 | |
7 | 546 /* |
547 * Read the lines in the error file one by one. | |
548 * Try to recognize one of the error formats in each line. | |
549 */ | |
41 | 550 while (!got_int) |
7 | 551 { |
41 | 552 /* Get the next line. */ |
553 if (fd == NULL) | |
554 { | |
446 | 555 if (tv != NULL) |
556 { | |
557 if (tv->v_type == VAR_STRING) | |
558 { | |
559 /* Get the next line from the supplied string */ | |
560 char_u *p; | |
561 | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
562 if (*p_str == NUL) /* Reached the end of the string */ |
446 | 563 break; |
564 | |
565 p = vim_strchr(p_str, '\n'); | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
566 if (p != NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
567 len = (int)(p - p_str) + 1; |
446 | 568 else |
835 | 569 len = (int)STRLEN(p_str); |
446 | 570 |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
571 if (len > IOSIZE - 2) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
572 { |
9114
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
573 linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len, |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
574 &linelen); |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
575 if (linebuf == NULL) |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
576 goto qf_init_end; |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
577 } |
446 | 578 else |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
579 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
580 linebuf = IObuff; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
581 linelen = len; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
582 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
583 vim_strncpy(linebuf, p_str, linelen); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
584 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
585 /* |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
586 * Increment using len in order to discard the rest of the |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
587 * line if it exceeds LINE_MAXLEN. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
588 */ |
446 | 589 p_str += len; |
590 } | |
591 else if (tv->v_type == VAR_LIST) | |
592 { | |
593 /* Get the next line from the supplied list */ | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
594 while (p_li != NULL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
595 && (p_li->li_tv.v_type != VAR_STRING |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
596 || p_li->li_tv.vval.v_string == NULL)) |
446 | 597 p_li = p_li->li_next; /* Skip non-string items */ |
598 | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
599 if (p_li == NULL) /* End of the list */ |
446 | 600 break; |
601 | |
835 | 602 len = (int)STRLEN(p_li->li_tv.vval.v_string); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
603 if (len > IOSIZE - 2) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
604 { |
9114
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
605 linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len, |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
606 &linelen); |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
607 if (linebuf == NULL) |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
608 goto qf_init_end; |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
609 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
610 else |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
611 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
612 linebuf = IObuff; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
613 linelen = len; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
614 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
615 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
616 vim_strncpy(linebuf, p_li->li_tv.vval.v_string, linelen); |
446 | 617 |
618 p_li = p_li->li_next; /* next item */ | |
619 } | |
620 } | |
621 else | |
622 { | |
623 /* Get the next line from the supplied buffer */ | |
624 if (buflnum > lnumlast) | |
625 break; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
626 p_buf = ml_get_buf(buf, buflnum++, FALSE); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
627 linelen = (int)STRLEN(p_buf); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
628 if (linelen > IOSIZE - 2) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
629 { |
9114
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
630 linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len, |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
631 &linelen); |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
632 if (linebuf == NULL) |
f221aec7fcca
commit https://github.com/vim/vim/commit/2b2b8ae5ab37b04584633c469265d85825166905
Christian Brabandt <cb@256bit.org>
parents:
9077
diff
changeset
|
633 goto qf_init_end; |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
634 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
635 else |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
636 linebuf = IObuff; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
637 vim_strncpy(linebuf, p_buf, linelen); |
446 | 638 } |
41 | 639 } |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
640 else |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
641 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
642 if (fgets((char *)IObuff, IOSIZE, fd) == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
643 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
644 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
645 discard = FALSE; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
646 linelen = (int)STRLEN(IObuff); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
647 if (linelen == IOSIZE - 1 && (IObuff[linelen - 1] != '\n' |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
648 #ifdef USE_CRNL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
649 || IObuff[linelen - 1] != '\r' |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
650 #endif |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
651 )) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
652 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
653 /* |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
654 * The current line exceeds IObuff, continue reading using |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
655 * growbuf until EOL or LINE_MAXLEN bytes is read. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
656 */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
657 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
658 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
659 growbufsiz = 2 * (IOSIZE - 1); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
660 growbuf = alloc(growbufsiz); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
661 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
662 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
663 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
664 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
665 /* Copy the read part of the line, excluding null-terminator */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
666 memcpy(growbuf, IObuff, IOSIZE - 1); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
667 growbuflen = linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
668 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
669 for (;;) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
670 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
671 if (fgets((char *)growbuf + growbuflen, |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
672 growbufsiz - growbuflen, fd) == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
673 break; |
9077
a2441f2ff85d
commit https://github.com/vim/vim/commit/d9db8b448c214eb583e84c598bca0688b9202ba7
Christian Brabandt <cb@256bit.org>
parents:
9060
diff
changeset
|
674 linelen = (int)STRLEN(growbuf + growbuflen); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
675 growbuflen += linelen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
676 if (growbuf[growbuflen - 1] == '\n' |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
677 #ifdef USE_CRNL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
678 || growbuf[growbuflen - 1] == '\r' |
3002 | 679 #endif |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
680 ) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
681 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
682 if (growbufsiz == LINE_MAXLEN) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
683 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
684 discard = TRUE; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
685 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
686 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
687 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
688 growbufsiz = 2 * growbufsiz < LINE_MAXLEN |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
689 ? 2 * growbufsiz : LINE_MAXLEN; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
690 growbuf = vim_realloc(growbuf, 2 * growbufsiz); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
691 if (growbuf == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
692 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
693 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
694 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
695 while (discard) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
696 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
697 /* |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
698 * The current line is longer than LINE_MAXLEN, continue |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
699 * reading but discard everything until EOL or EOF is |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
700 * reached. |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
701 */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
702 if (fgets((char *)IObuff, IOSIZE, fd) == NULL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
703 || (int)STRLEN(IObuff) < IOSIZE - 1 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
704 || IObuff[IOSIZE - 1] == '\n' |
7 | 705 #ifdef USE_CRNL |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
706 || IObuff[IOSIZE - 1] == '\r' |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
707 #endif |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
708 ) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
709 break; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
710 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
711 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
712 linebuf = growbuf; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
713 linelen = growbuflen; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
714 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
715 else |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
716 linebuf = IObuff; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
717 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
718 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
719 if (linelen > 0 && linebuf[linelen - 1] == '\n') |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
720 linebuf[linelen - 1] = NUL; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
721 #ifdef USE_CRNL |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
722 if (linelen > 0 && linebuf[linelen - 1] == '\r') |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
723 linebuf[linelen - 1] = NUL; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
724 #endif |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
725 |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
726 #ifdef FEAT_MBYTE |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
727 remove_bom(linebuf); |
7 | 728 #endif |
729 | |
789 | 730 /* If there was no %> item start at the first pattern */ |
731 if (fmt_start == NULL) | |
732 fmt_ptr = fmt_first; | |
733 else | |
734 { | |
735 fmt_ptr = fmt_start; | |
736 fmt_start = NULL; | |
737 } | |
738 | |
7 | 739 /* |
740 * Try to match each part of 'errorformat' until we find a complete | |
741 * match or no match. | |
742 */ | |
743 valid = TRUE; | |
744 restofline: | |
789 | 745 for ( ; fmt_ptr != NULL; fmt_ptr = fmt_ptr->next) |
7 | 746 { |
6450 | 747 int r; |
748 | |
7 | 749 idx = fmt_ptr->prefix; |
750 if (multiscan && vim_strchr((char_u *)"OPQ", idx) == NULL) | |
751 continue; | |
752 namebuf[0] = NUL; | |
230 | 753 pattern[0] = NUL; |
7 | 754 if (!multiscan) |
755 errmsg[0] = NUL; | |
756 lnum = 0; | |
757 col = 0; | |
170 | 758 use_viscol = FALSE; |
7 | 759 enr = -1; |
760 type = 0; | |
761 tail = NULL; | |
762 | |
763 regmatch.regprog = fmt_ptr->prog; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
764 r = vim_regexec(®match, linebuf, (colnr_T)0); |
6450 | 765 fmt_ptr->prog = regmatch.regprog; |
766 if (r) | |
7 | 767 { |
768 if ((idx == 'C' || idx == 'Z') && !multiline) | |
769 continue; | |
770 if (vim_strchr((char_u *)"EWI", idx) != NULL) | |
771 type = idx; | |
772 else | |
773 type = 0; | |
774 /* | |
895 | 775 * Extract error message data from matched line. |
776 * We check for an actual submatch, because "\[" and "\]" in | |
777 * the 'errorformat' may cause the wrong submatch to be used. | |
7 | 778 */ |
779 if ((i = (int)fmt_ptr->addr[0]) > 0) /* %f */ | |
780 { | |
895 | 781 int c; |
782 | |
783 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) | |
784 continue; | |
277 | 785 |
786 /* Expand ~/file and $HOME/file to full path. */ | |
895 | 787 c = *regmatch.endp[i]; |
277 | 788 *regmatch.endp[i] = NUL; |
789 expand_env(regmatch.startp[i], namebuf, CMDBUFFSIZE); | |
790 *regmatch.endp[i] = c; | |
791 | |
7 | 792 if (vim_strchr((char_u *)"OPQ", idx) != NULL |
277 | 793 && mch_getperm(namebuf) == -1) |
7 | 794 continue; |
795 } | |
796 if ((i = (int)fmt_ptr->addr[1]) > 0) /* %n */ | |
895 | 797 { |
798 if (regmatch.startp[i] == NULL) | |
799 continue; | |
7 | 800 enr = (int)atol((char *)regmatch.startp[i]); |
895 | 801 } |
7 | 802 if ((i = (int)fmt_ptr->addr[2]) > 0) /* %l */ |
895 | 803 { |
804 if (regmatch.startp[i] == NULL) | |
805 continue; | |
7 | 806 lnum = atol((char *)regmatch.startp[i]); |
895 | 807 } |
7 | 808 if ((i = (int)fmt_ptr->addr[3]) > 0) /* %c */ |
895 | 809 { |
810 if (regmatch.startp[i] == NULL) | |
811 continue; | |
7 | 812 col = (int)atol((char *)regmatch.startp[i]); |
895 | 813 } |
7 | 814 if ((i = (int)fmt_ptr->addr[4]) > 0) /* %t */ |
895 | 815 { |
816 if (regmatch.startp[i] == NULL) | |
817 continue; | |
7 | 818 type = *regmatch.startp[i]; |
895 | 819 } |
625 | 820 if (fmt_ptr->flags == '+' && !multiscan) /* %+ */ |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
821 { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
822 if (linelen > errmsglen) { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
823 /* linelen + null terminator */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
824 if ((errmsg = vim_realloc(errmsg, linelen + 1)) == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
825 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
826 errmsglen = linelen + 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
827 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
828 vim_strncpy(errmsg, linebuf, linelen); |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
829 } |
7 | 830 else if ((i = (int)fmt_ptr->addr[5]) > 0) /* %m */ |
831 { | |
895 | 832 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
833 continue; | |
7 | 834 len = (int)(regmatch.endp[i] - regmatch.startp[i]); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
835 if (len > errmsglen) { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
836 /* len + null terminator */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
837 if ((errmsg = vim_realloc(errmsg, len + 1)) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
838 == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
839 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
840 errmsglen = len + 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
841 } |
418 | 842 vim_strncpy(errmsg, regmatch.startp[i], len); |
7 | 843 } |
844 if ((i = (int)fmt_ptr->addr[6]) > 0) /* %r */ | |
895 | 845 { |
846 if (regmatch.startp[i] == NULL) | |
847 continue; | |
7 | 848 tail = regmatch.startp[i]; |
895 | 849 } |
7 | 850 if ((i = (int)fmt_ptr->addr[7]) > 0) /* %p */ |
851 { | |
3555 | 852 char_u *match_ptr; |
853 | |
895 | 854 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
855 continue; | |
3555 | 856 col = 0; |
857 for (match_ptr = regmatch.startp[i]; | |
858 match_ptr != regmatch.endp[i]; ++match_ptr) | |
859 { | |
860 ++col; | |
861 if (*match_ptr == TAB) | |
862 { | |
863 col += 7; | |
864 col -= col % 8; | |
865 } | |
866 } | |
867 ++col; | |
868 use_viscol = TRUE; | |
7 | 869 } |
870 if ((i = (int)fmt_ptr->addr[8]) > 0) /* %v */ | |
871 { | |
895 | 872 if (regmatch.startp[i] == NULL) |
873 continue; | |
7 | 874 col = (int)atol((char *)regmatch.startp[i]); |
170 | 875 use_viscol = TRUE; |
7 | 876 } |
230 | 877 if ((i = (int)fmt_ptr->addr[9]) > 0) /* %s */ |
878 { | |
895 | 879 if (regmatch.startp[i] == NULL || regmatch.endp[i] == NULL) |
880 continue; | |
230 | 881 len = (int)(regmatch.endp[i] - regmatch.startp[i]); |
882 if (len > CMDBUFFSIZE - 5) | |
883 len = CMDBUFFSIZE - 5; | |
884 STRCPY(pattern, "^\\V"); | |
885 STRNCAT(pattern, regmatch.startp[i], len); | |
886 pattern[len + 3] = '\\'; | |
887 pattern[len + 4] = '$'; | |
888 pattern[len + 5] = NUL; | |
889 } | |
7 | 890 break; |
891 } | |
892 } | |
893 multiscan = FALSE; | |
789 | 894 |
625 | 895 if (fmt_ptr == NULL || idx == 'D' || idx == 'X') |
7 | 896 { |
625 | 897 if (fmt_ptr != NULL) |
7 | 898 { |
899 if (idx == 'D') /* enter directory */ | |
900 { | |
901 if (*namebuf == NUL) | |
902 { | |
903 EMSG(_("E379: Missing or empty directory name")); | |
904 goto error2; | |
905 } | |
906 if ((directory = qf_push_dir(namebuf, &dir_stack)) == NULL) | |
907 goto error2; | |
908 } | |
909 else if (idx == 'X') /* leave directory */ | |
910 directory = qf_pop_dir(&dir_stack); | |
911 } | |
912 namebuf[0] = NUL; /* no match found, remove file name */ | |
913 lnum = 0; /* don't jump to this line */ | |
914 valid = FALSE; | |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
915 if (linelen > errmsglen) { |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
916 /* linelen + null terminator */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
917 if ((errmsg = vim_realloc(errmsg, linelen + 1)) == NULL) |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
918 goto qf_init_end; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
919 errmsglen = linelen + 1; |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
920 } |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
921 /* copy whole line to error message */ |
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
922 vim_strncpy(errmsg, linebuf, linelen); |
625 | 923 if (fmt_ptr == NULL) |
7 | 924 multiline = multiignore = FALSE; |
925 } | |
625 | 926 else if (fmt_ptr != NULL) |
7 | 927 { |
789 | 928 /* honor %> item */ |
929 if (fmt_ptr->conthere) | |
930 fmt_start = fmt_ptr; | |
931 | |
7 | 932 if (vim_strchr((char_u *)"AEWI", idx) != NULL) |
5716 | 933 { |
7 | 934 multiline = TRUE; /* start of a multi-line message */ |
5716 | 935 multiignore = FALSE; /* reset continuation */ |
936 } | |
7 | 937 else if (vim_strchr((char_u *)"CZ", idx) != NULL) |
938 { /* continuation of multi-line msg */ | |
939 if (qfprev == NULL) | |
940 goto error2; | |
941 if (*errmsg && !multiignore) | |
942 { | |
943 len = (int)STRLEN(qfprev->qf_text); | |
944 if ((ptr = alloc((unsigned)(len + STRLEN(errmsg) + 2))) | |
945 == NULL) | |
946 goto error2; | |
947 STRCPY(ptr, qfprev->qf_text); | |
948 vim_free(qfprev->qf_text); | |
949 qfprev->qf_text = ptr; | |
950 *(ptr += len) = '\n'; | |
951 STRCPY(++ptr, errmsg); | |
952 } | |
953 if (qfprev->qf_nr == -1) | |
954 qfprev->qf_nr = enr; | |
955 if (vim_isprintc(type) && !qfprev->qf_type) | |
956 qfprev->qf_type = type; /* only printable chars allowed */ | |
957 if (!qfprev->qf_lnum) | |
958 qfprev->qf_lnum = lnum; | |
959 if (!qfprev->qf_col) | |
960 qfprev->qf_col = col; | |
170 | 961 qfprev->qf_viscol = use_viscol; |
7 | 962 if (!qfprev->qf_fnum) |
963 qfprev->qf_fnum = qf_get_fnum(directory, | |
964 *namebuf || directory ? namebuf | |
965 : currfile && valid ? currfile : 0); | |
966 if (idx == 'Z') | |
967 multiline = multiignore = FALSE; | |
968 line_breakcheck(); | |
969 continue; | |
970 } | |
971 else if (vim_strchr((char_u *)"OPQ", idx) != NULL) | |
972 { | |
973 /* global file names */ | |
974 valid = FALSE; | |
975 if (*namebuf == NUL || mch_getperm(namebuf) >= 0) | |
976 { | |
977 if (*namebuf && idx == 'P') | |
978 currfile = qf_push_dir(namebuf, &file_stack); | |
979 else if (idx == 'Q') | |
980 currfile = qf_pop_dir(&file_stack); | |
981 *namebuf = NUL; | |
982 if (tail && *tail) | |
983 { | |
1668 | 984 STRMOVE(IObuff, skipwhite(tail)); |
7 | 985 multiscan = TRUE; |
986 goto restofline; | |
987 } | |
988 } | |
989 } | |
990 if (fmt_ptr->flags == '-') /* generally exclude this line */ | |
991 { | |
992 if (multiline) | |
993 multiignore = TRUE; /* also exclude continuation lines */ | |
994 continue; | |
995 } | |
996 } | |
997 | |
644 | 998 if (qf_add_entry(qi, &qfprev, |
7 | 999 directory, |
129 | 1000 (*namebuf || directory) |
7 | 1001 ? namebuf |
129 | 1002 : ((currfile && valid) ? currfile : (char_u *)NULL), |
1065 | 1003 0, |
7 | 1004 errmsg, |
1005 lnum, | |
1006 col, | |
170 | 1007 use_viscol, |
230 | 1008 pattern, |
7 | 1009 enr, |
1010 type, | |
1011 valid) == FAIL) | |
1012 goto error2; | |
1013 line_breakcheck(); | |
1014 } | |
41 | 1015 if (fd == NULL || !ferror(fd)) |
7 | 1016 { |
644 | 1017 if (qi->qf_lists[qi->qf_curlist].qf_index == 0) |
7 | 1018 { |
644 | 1019 /* no valid entry found */ |
1020 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
1021 qi->qf_lists[qi->qf_curlist].qf_start; | |
1022 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
1023 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; | |
7 | 1024 } |
1025 else | |
1026 { | |
644 | 1027 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
1028 if (qi->qf_lists[qi->qf_curlist].qf_ptr == NULL) | |
1029 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
1030 qi->qf_lists[qi->qf_curlist].qf_start; | |
7 | 1031 } |
644 | 1032 /* return number of matches */ |
1033 retval = qi->qf_lists[qi->qf_curlist].qf_count; | |
7 | 1034 goto qf_init_ok; |
1035 } | |
1036 EMSG(_(e_readerrf)); | |
1037 error2: | |
644 | 1038 qf_free(qi, qi->qf_curlist); |
1039 qi->qf_listcount--; | |
1040 if (qi->qf_curlist > 0) | |
1041 --qi->qf_curlist; | |
7 | 1042 qf_init_ok: |
41 | 1043 if (fd != NULL) |
1044 fclose(fd); | |
7 | 1045 for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first) |
1046 { | |
1047 fmt_first = fmt_ptr->next; | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
1048 vim_regfree(fmt_ptr->prog); |
7 | 1049 vim_free(fmt_ptr); |
1050 } | |
1051 qf_clean_dir_stack(&dir_stack); | |
1052 qf_clean_dir_stack(&file_stack); | |
1053 qf_init_end: | |
1054 vim_free(namebuf); | |
1055 vim_free(errmsg); | |
230 | 1056 vim_free(pattern); |
7 | 1057 vim_free(fmtstr); |
9033
0536d1469b67
commit https://github.com/vim/vim/commit/6be8c8e165204b8aa4eeb8a52be87a58d8b41b9e
Christian Brabandt <cb@256bit.org>
parents:
8932
diff
changeset
|
1058 vim_free(growbuf); |
7 | 1059 |
1060 #ifdef FEAT_WINDOWS | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
1061 qf_update_buffer(qi, old_last); |
7 | 1062 #endif |
1063 | |
1064 return retval; | |
1065 } | |
1066 | |
6079 | 1067 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1068 qf_store_title(qf_info_T *qi, char_u *title) |
6079 | 1069 { |
1070 if (title != NULL) | |
1071 { | |
1072 char_u *p = alloc((int)STRLEN(title) + 2); | |
1073 | |
1074 qi->qf_lists[qi->qf_curlist].qf_title = p; | |
1075 if (p != NULL) | |
1076 sprintf((char *)p, ":%s", (char *)title); | |
1077 } | |
1078 } | |
1079 | |
7 | 1080 /* |
1081 * Prepare for adding a new quickfix list. | |
1082 */ | |
1083 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1084 qf_new_list(qf_info_T *qi, char_u *qf_title) |
7 | 1085 { |
1086 int i; | |
1087 | |
1088 /* | |
6079 | 1089 * If the current entry is not the last entry, delete entries beyond |
7 | 1090 * the current entry. This makes it possible to browse in a tree-like |
1091 * way with ":grep'. | |
1092 */ | |
644 | 1093 while (qi->qf_listcount > qi->qf_curlist + 1) |
1094 qf_free(qi, --qi->qf_listcount); | |
7 | 1095 |
1096 /* | |
1097 * When the stack is full, remove to oldest entry | |
1098 * Otherwise, add a new entry. | |
1099 */ | |
644 | 1100 if (qi->qf_listcount == LISTCOUNT) |
7 | 1101 { |
644 | 1102 qf_free(qi, 0); |
7 | 1103 for (i = 1; i < LISTCOUNT; ++i) |
644 | 1104 qi->qf_lists[i - 1] = qi->qf_lists[i]; |
1105 qi->qf_curlist = LISTCOUNT - 1; | |
7 | 1106 } |
1107 else | |
644 | 1108 qi->qf_curlist = qi->qf_listcount++; |
3259 | 1109 vim_memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T))); |
6079 | 1110 qf_store_title(qi, qf_title); |
7 | 1111 } |
1112 | |
644 | 1113 /* |
1114 * Free a location list | |
1115 */ | |
1116 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1117 ll_free_all(qf_info_T **pqi) |
359 | 1118 { |
1119 int i; | |
644 | 1120 qf_info_T *qi; |
1121 | |
1122 qi = *pqi; | |
1123 if (qi == NULL) | |
1124 return; | |
1125 *pqi = NULL; /* Remove reference to this list */ | |
1126 | |
1127 qi->qf_refcount--; | |
1128 if (qi->qf_refcount < 1) | |
1129 { | |
1130 /* No references to this location list */ | |
1131 for (i = 0; i < qi->qf_listcount; ++i) | |
1132 qf_free(qi, i); | |
1133 vim_free(qi); | |
1134 } | |
359 | 1135 } |
644 | 1136 |
1137 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1138 qf_free_all(win_T *wp) |
644 | 1139 { |
1140 int i; | |
1141 qf_info_T *qi = &ql_info; | |
1142 | |
1143 if (wp != NULL) | |
1144 { | |
1145 /* location list */ | |
1146 ll_free_all(&wp->w_llist); | |
1147 ll_free_all(&wp->w_llist_ref); | |
1148 } | |
1149 else | |
1150 /* quickfix list */ | |
1151 for (i = 0; i < qi->qf_listcount; ++i) | |
1152 qf_free(qi, i); | |
1153 } | |
359 | 1154 |
7 | 1155 /* |
1156 * Add an entry to the end of the list of errors. | |
1157 * Returns OK or FAIL. | |
1158 */ | |
1159 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1160 qf_add_entry( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1161 qf_info_T *qi, /* quickfix list */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1162 qfline_T **prevp, /* pointer to previously added entry or NULL */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1163 char_u *dir, /* optional directory name */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1164 char_u *fname, /* file name or NULL */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1165 int bufnum, /* buffer number or zero */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1166 char_u *mesg, /* message */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1167 long lnum, /* line number */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1168 int col, /* column */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1169 int vis_col, /* using visual column */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1170 char_u *pattern, /* search pattern */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1171 int nr, /* error number */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1172 int type, /* type character */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1173 int valid) /* valid entry */ |
7 | 1174 { |
230 | 1175 qfline_T *qfp; |
7 | 1176 |
230 | 1177 if ((qfp = (qfline_T *)alloc((unsigned)sizeof(qfline_T))) == NULL) |
7 | 1178 return FAIL; |
1065 | 1179 if (bufnum != 0) |
1180 qfp->qf_fnum = bufnum; | |
1181 else | |
1182 qfp->qf_fnum = qf_get_fnum(dir, fname); | |
7 | 1183 if ((qfp->qf_text = vim_strsave(mesg)) == NULL) |
1184 { | |
1185 vim_free(qfp); | |
1186 return FAIL; | |
1187 } | |
1188 qfp->qf_lnum = lnum; | |
1189 qfp->qf_col = col; | |
170 | 1190 qfp->qf_viscol = vis_col; |
230 | 1191 if (pattern == NULL || *pattern == NUL) |
1192 qfp->qf_pattern = NULL; | |
1193 else if ((qfp->qf_pattern = vim_strsave(pattern)) == NULL) | |
1194 { | |
1195 vim_free(qfp->qf_text); | |
1196 vim_free(qfp); | |
1197 return FAIL; | |
1198 } | |
7 | 1199 qfp->qf_nr = nr; |
1200 if (type != 1 && !vim_isprintc(type)) /* only printable chars allowed */ | |
1201 type = 0; | |
1202 qfp->qf_type = type; | |
1203 qfp->qf_valid = valid; | |
1204 | |
644 | 1205 if (qi->qf_lists[qi->qf_curlist].qf_count == 0) |
1206 /* first element in the list */ | |
7 | 1207 { |
644 | 1208 qi->qf_lists[qi->qf_curlist].qf_start = qfp; |
8716
4ce26276caeb
commit https://github.com/vim/vim/commit/8b20179c657b4266dff115486ca68c6a50324071
Christian Brabandt <cb@256bit.org>
parents:
8702
diff
changeset
|
1209 qi->qf_lists[qi->qf_curlist].qf_ptr = qfp; |
4ce26276caeb
commit https://github.com/vim/vim/commit/8b20179c657b4266dff115486ca68c6a50324071
Christian Brabandt <cb@256bit.org>
parents:
8702
diff
changeset
|
1210 qi->qf_lists[qi->qf_curlist].qf_index = 0; |
7 | 1211 qfp->qf_prev = qfp; /* first element points to itself */ |
1212 } | |
1213 else | |
1214 { | |
1215 qfp->qf_prev = *prevp; | |
1216 (*prevp)->qf_next = qfp; | |
1217 } | |
1218 qfp->qf_next = qfp; /* last element points to itself */ | |
1219 qfp->qf_cleared = FALSE; | |
1220 *prevp = qfp; | |
644 | 1221 ++qi->qf_lists[qi->qf_curlist].qf_count; |
1222 if (qi->qf_lists[qi->qf_curlist].qf_index == 0 && qfp->qf_valid) | |
1223 /* first valid entry */ | |
7 | 1224 { |
644 | 1225 qi->qf_lists[qi->qf_curlist].qf_index = |
1226 qi->qf_lists[qi->qf_curlist].qf_count; | |
1227 qi->qf_lists[qi->qf_curlist].qf_ptr = qfp; | |
7 | 1228 } |
1229 | |
1230 return OK; | |
1231 } | |
1232 | |
1233 /* | |
659 | 1234 * Allocate a new location list |
644 | 1235 */ |
659 | 1236 static qf_info_T * |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1237 ll_new_list(void) |
644 | 1238 { |
659 | 1239 qf_info_T *qi; |
1240 | |
1241 qi = (qf_info_T *)alloc((unsigned)sizeof(qf_info_T)); | |
1242 if (qi != NULL) | |
1243 { | |
1244 vim_memset(qi, 0, (size_t)(sizeof(qf_info_T))); | |
1245 qi->qf_refcount++; | |
1246 } | |
1247 | |
1248 return qi; | |
644 | 1249 } |
1250 | |
1251 /* | |
1252 * Return the location list for window 'wp'. | |
1253 * If not present, allocate a location list | |
1254 */ | |
1255 static qf_info_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1256 ll_get_or_alloc_list(win_T *wp) |
644 | 1257 { |
1258 if (IS_LL_WINDOW(wp)) | |
1259 /* For a location list window, use the referenced location list */ | |
1260 return wp->w_llist_ref; | |
1261 | |
1262 /* | |
1263 * For a non-location list window, w_llist_ref should not point to a | |
1264 * location list. | |
1265 */ | |
1266 ll_free_all(&wp->w_llist_ref); | |
1267 | |
1268 if (wp->w_llist == NULL) | |
659 | 1269 wp->w_llist = ll_new_list(); /* new location list */ |
644 | 1270 return wp->w_llist; |
1271 } | |
1272 | |
1273 /* | |
1274 * Copy the location list from window "from" to window "to". | |
1275 */ | |
1276 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1277 copy_loclist(win_T *from, win_T *to) |
644 | 1278 { |
1279 qf_info_T *qi; | |
1280 int idx; | |
1281 int i; | |
1282 | |
1283 /* | |
1284 * When copying from a location list window, copy the referenced | |
1285 * location list. For other windows, copy the location list for | |
1286 * that window. | |
1287 */ | |
1288 if (IS_LL_WINDOW(from)) | |
1289 qi = from->w_llist_ref; | |
1290 else | |
1291 qi = from->w_llist; | |
1292 | |
1293 if (qi == NULL) /* no location list to copy */ | |
1294 return; | |
1295 | |
659 | 1296 /* allocate a new location list */ |
1297 if ((to->w_llist = ll_new_list()) == NULL) | |
644 | 1298 return; |
1299 | |
1300 to->w_llist->qf_listcount = qi->qf_listcount; | |
1301 | |
1302 /* Copy the location lists one at a time */ | |
1303 for (idx = 0; idx < qi->qf_listcount; idx++) | |
1304 { | |
1305 qf_list_T *from_qfl; | |
1306 qf_list_T *to_qfl; | |
1307 | |
1308 to->w_llist->qf_curlist = idx; | |
1309 | |
1310 from_qfl = &qi->qf_lists[idx]; | |
1311 to_qfl = &to->w_llist->qf_lists[idx]; | |
1312 | |
1313 /* Some of the fields are populated by qf_add_entry() */ | |
1314 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid; | |
1315 to_qfl->qf_count = 0; | |
1316 to_qfl->qf_index = 0; | |
1317 to_qfl->qf_start = NULL; | |
1318 to_qfl->qf_ptr = NULL; | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1319 if (from_qfl->qf_title != NULL) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1320 to_qfl->qf_title = vim_strsave(from_qfl->qf_title); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1321 else |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
1322 to_qfl->qf_title = NULL; |
644 | 1323 |
1324 if (from_qfl->qf_count) | |
1325 { | |
1326 qfline_T *from_qfp; | |
1327 qfline_T *prevp = NULL; | |
1328 | |
1329 /* copy all the location entries in this list */ | |
1330 for (i = 0, from_qfp = from_qfl->qf_start; i < from_qfl->qf_count; | |
1331 ++i, from_qfp = from_qfp->qf_next) | |
1332 { | |
1333 if (qf_add_entry(to->w_llist, &prevp, | |
1334 NULL, | |
1335 NULL, | |
1065 | 1336 0, |
644 | 1337 from_qfp->qf_text, |
1338 from_qfp->qf_lnum, | |
1339 from_qfp->qf_col, | |
1340 from_qfp->qf_viscol, | |
1341 from_qfp->qf_pattern, | |
1342 from_qfp->qf_nr, | |
1343 0, | |
1344 from_qfp->qf_valid) == FAIL) | |
1345 { | |
1346 qf_free_all(to); | |
1347 return; | |
1348 } | |
1349 /* | |
1350 * qf_add_entry() will not set the qf_num field, as the | |
1351 * directory and file names are not supplied. So the qf_fnum | |
1352 * field is copied here. | |
1353 */ | |
1354 prevp->qf_fnum = from_qfp->qf_fnum; /* file number */ | |
1355 prevp->qf_type = from_qfp->qf_type; /* error type */ | |
1356 if (from_qfl->qf_ptr == from_qfp) | |
1357 to_qfl->qf_ptr = prevp; /* current location */ | |
1358 } | |
1359 } | |
1360 | |
1361 to_qfl->qf_index = from_qfl->qf_index; /* current index in the list */ | |
1362 | |
1363 /* When no valid entries are present in the list, qf_ptr points to | |
1364 * the first item in the list */ | |
2795 | 1365 if (to_qfl->qf_nonevalid) |
5060
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1366 { |
644 | 1367 to_qfl->qf_ptr = to_qfl->qf_start; |
5060
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1368 to_qfl->qf_index = 1; |
30910831e5b0
updated for version 7.3.1273
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1369 } |
644 | 1370 } |
1371 | |
1372 to->w_llist->qf_curlist = qi->qf_curlist; /* current list */ | |
1373 } | |
1374 | |
1375 /* | |
7 | 1376 * get buffer number for file "dir.name" |
1377 */ | |
1378 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1379 qf_get_fnum(char_u *directory, char_u *fname) |
7 | 1380 { |
1381 if (fname == NULL || *fname == NUL) /* no file name */ | |
1382 return 0; | |
1383 { | |
1384 char_u *ptr; | |
1385 int fnum; | |
1386 | |
2823 | 1387 #ifdef VMS |
7 | 1388 vms_remove_version(fname); |
2823 | 1389 #endif |
1390 #ifdef BACKSLASH_IN_FILENAME | |
7 | 1391 if (directory != NULL) |
1392 slash_adjust(directory); | |
1393 slash_adjust(fname); | |
2823 | 1394 #endif |
7 | 1395 if (directory != NULL && !vim_isAbsName(fname) |
1396 && (ptr = concat_fnames(directory, fname, TRUE)) != NULL) | |
1397 { | |
1398 /* | |
1399 * Here we check if the file really exists. | |
1400 * This should normally be true, but if make works without | |
1401 * "leaving directory"-messages we might have missed a | |
1402 * directory change. | |
1403 */ | |
1404 if (mch_getperm(ptr) < 0) | |
1405 { | |
1406 vim_free(ptr); | |
1407 directory = qf_guess_filepath(fname); | |
1408 if (directory) | |
1409 ptr = concat_fnames(directory, fname, TRUE); | |
1410 else | |
1411 ptr = vim_strsave(fname); | |
1412 } | |
1413 /* Use concatenated directory name and file name */ | |
1414 fnum = buflist_add(ptr, 0); | |
1415 vim_free(ptr); | |
1416 return fnum; | |
1417 } | |
1418 return buflist_add(fname, 0); | |
1419 } | |
1420 } | |
1421 | |
1422 /* | |
1423 * push dirbuf onto the directory stack and return pointer to actual dir or | |
1424 * NULL on error | |
1425 */ | |
1426 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1427 qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr) |
7 | 1428 { |
1429 struct dir_stack_T *ds_new; | |
1430 struct dir_stack_T *ds_ptr; | |
1431 | |
1432 /* allocate new stack element and hook it in */ | |
1433 ds_new = (struct dir_stack_T *)alloc((unsigned)sizeof(struct dir_stack_T)); | |
1434 if (ds_new == NULL) | |
1435 return NULL; | |
1436 | |
1437 ds_new->next = *stackptr; | |
1438 *stackptr = ds_new; | |
1439 | |
1440 /* store directory on the stack */ | |
1441 if (vim_isAbsName(dirbuf) | |
1442 || (*stackptr)->next == NULL | |
1443 || (*stackptr && dir_stack != *stackptr)) | |
1444 (*stackptr)->dirname = vim_strsave(dirbuf); | |
1445 else | |
1446 { | |
1447 /* Okay we don't have an absolute path. | |
1448 * dirbuf must be a subdir of one of the directories on the stack. | |
1449 * Let's search... | |
1450 */ | |
1451 ds_new = (*stackptr)->next; | |
1452 (*stackptr)->dirname = NULL; | |
1453 while (ds_new) | |
1454 { | |
1455 vim_free((*stackptr)->dirname); | |
1456 (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, | |
1457 TRUE); | |
1458 if (mch_isdir((*stackptr)->dirname) == TRUE) | |
1459 break; | |
1460 | |
1461 ds_new = ds_new->next; | |
1462 } | |
1463 | |
1464 /* clean up all dirs we already left */ | |
1465 while ((*stackptr)->next != ds_new) | |
1466 { | |
1467 ds_ptr = (*stackptr)->next; | |
1468 (*stackptr)->next = (*stackptr)->next->next; | |
1469 vim_free(ds_ptr->dirname); | |
1470 vim_free(ds_ptr); | |
1471 } | |
1472 | |
1473 /* Nothing found -> it must be on top level */ | |
1474 if (ds_new == NULL) | |
1475 { | |
1476 vim_free((*stackptr)->dirname); | |
1477 (*stackptr)->dirname = vim_strsave(dirbuf); | |
1478 } | |
1479 } | |
1480 | |
1481 if ((*stackptr)->dirname != NULL) | |
1482 return (*stackptr)->dirname; | |
1483 else | |
1484 { | |
1485 ds_ptr = *stackptr; | |
1486 *stackptr = (*stackptr)->next; | |
1487 vim_free(ds_ptr); | |
1488 return NULL; | |
1489 } | |
1490 } | |
1491 | |
1492 | |
1493 /* | |
1494 * pop dirbuf from the directory stack and return previous directory or NULL if | |
1495 * stack is empty | |
1496 */ | |
1497 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1498 qf_pop_dir(struct dir_stack_T **stackptr) |
7 | 1499 { |
1500 struct dir_stack_T *ds_ptr; | |
1501 | |
1502 /* TODO: Should we check if dirbuf is the directory on top of the stack? | |
1503 * What to do if it isn't? */ | |
1504 | |
1505 /* pop top element and free it */ | |
1506 if (*stackptr != NULL) | |
1507 { | |
1508 ds_ptr = *stackptr; | |
1509 *stackptr = (*stackptr)->next; | |
1510 vim_free(ds_ptr->dirname); | |
1511 vim_free(ds_ptr); | |
1512 } | |
1513 | |
1514 /* return NEW top element as current dir or NULL if stack is empty*/ | |
1515 return *stackptr ? (*stackptr)->dirname : NULL; | |
1516 } | |
1517 | |
1518 /* | |
1519 * clean up directory stack | |
1520 */ | |
1521 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1522 qf_clean_dir_stack(struct dir_stack_T **stackptr) |
7 | 1523 { |
1524 struct dir_stack_T *ds_ptr; | |
1525 | |
1526 while ((ds_ptr = *stackptr) != NULL) | |
1527 { | |
1528 *stackptr = (*stackptr)->next; | |
1529 vim_free(ds_ptr->dirname); | |
1530 vim_free(ds_ptr); | |
1531 } | |
1532 } | |
1533 | |
1534 /* | |
1535 * Check in which directory of the directory stack the given file can be | |
1536 * found. | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
1537 * Returns a pointer to the directory name or NULL if not found. |
7 | 1538 * Cleans up intermediate directory entries. |
1539 * | |
1540 * TODO: How to solve the following problem? | |
1541 * If we have the this directory tree: | |
1542 * ./ | |
1543 * ./aa | |
1544 * ./aa/bb | |
1545 * ./bb | |
1546 * ./bb/x.c | |
1547 * and make says: | |
1548 * making all in aa | |
1549 * making all in bb | |
1550 * x.c:9: Error | |
1551 * Then qf_push_dir thinks we are in ./aa/bb, but we are in ./bb. | |
1552 * qf_guess_filepath will return NULL. | |
1553 */ | |
1554 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1555 qf_guess_filepath(char_u *filename) |
7 | 1556 { |
1557 struct dir_stack_T *ds_ptr; | |
1558 struct dir_stack_T *ds_tmp; | |
1559 char_u *fullname; | |
1560 | |
1561 /* no dirs on the stack - there's nothing we can do */ | |
1562 if (dir_stack == NULL) | |
1563 return NULL; | |
1564 | |
1565 ds_ptr = dir_stack->next; | |
1566 fullname = NULL; | |
1567 while (ds_ptr) | |
1568 { | |
1569 vim_free(fullname); | |
1570 fullname = concat_fnames(ds_ptr->dirname, filename, TRUE); | |
1571 | |
1572 /* If concat_fnames failed, just go on. The worst thing that can happen | |
1573 * is that we delete the entire stack. | |
1574 */ | |
1575 if ((fullname != NULL) && (mch_getperm(fullname) >= 0)) | |
1576 break; | |
1577 | |
1578 ds_ptr = ds_ptr->next; | |
1579 } | |
1580 | |
1581 vim_free(fullname); | |
1582 | |
1583 /* clean up all dirs we already left */ | |
1584 while (dir_stack->next != ds_ptr) | |
1585 { | |
1586 ds_tmp = dir_stack->next; | |
1587 dir_stack->next = dir_stack->next->next; | |
1588 vim_free(ds_tmp->dirname); | |
1589 vim_free(ds_tmp); | |
1590 } | |
1591 | |
1592 return ds_ptr==NULL? NULL: ds_ptr->dirname; | |
1593 | |
1594 } | |
1595 | |
1596 /* | |
8702
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1597 * When loading a file from the quickfix, the auto commands may modify it. |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1598 * This may invalidate the current quickfix entry. This function checks |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1599 * whether a entry is still present in the quickfix. |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1600 * Similar to location list. |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1601 */ |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1602 static int |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1603 is_qf_entry_present(qf_info_T *qi, qfline_T *qf_ptr) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1604 { |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1605 qf_list_T *qfl; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1606 qfline_T *qfp; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1607 int i; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1608 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1609 qfl = &qi->qf_lists[qi->qf_curlist]; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1610 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1611 /* Search for the entry in the current list */ |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1612 for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1613 ++i, qfp = qfp->qf_next) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1614 if (qfp == qf_ptr) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1615 break; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1616 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1617 if (i == qfl->qf_count) /* Entry is not found */ |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1618 return FALSE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1619 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1620 return TRUE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1621 } |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1622 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
1623 /* |
7 | 1624 * jump to a quickfix line |
1625 * if dir == FORWARD go "errornr" valid entries forward | |
1626 * if dir == BACKWARD go "errornr" valid entries backward | |
1627 * if dir == FORWARD_FILE go "errornr" valid entries files backward | |
1628 * if dir == BACKWARD_FILE go "errornr" valid entries files backward | |
1629 * else if "errornr" is zero, redisplay the same line | |
1630 * else go to entry "errornr" | |
1631 */ | |
1632 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1633 qf_jump( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1634 qf_info_T *qi, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1635 int dir, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1636 int errornr, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1637 int forceit) |
7 | 1638 { |
644 | 1639 qf_info_T *ll_ref; |
230 | 1640 qfline_T *qf_ptr; |
1641 qfline_T *old_qf_ptr; | |
7 | 1642 int qf_index; |
1643 int old_qf_fnum; | |
1644 int old_qf_index; | |
1645 int prev_index; | |
1646 static char_u *e_no_more_items = (char_u *)N_("E553: No more items"); | |
1647 char_u *err = e_no_more_items; | |
1648 linenr_T i; | |
1649 buf_T *old_curbuf; | |
1650 linenr_T old_lnum; | |
1651 colnr_T screen_col; | |
1652 colnr_T char_col; | |
1653 char_u *line; | |
1654 #ifdef FEAT_WINDOWS | |
639 | 1655 char_u *old_swb = p_swb; |
1621 | 1656 unsigned old_swb_flags = swb_flags; |
7 | 1657 int opened_window = FALSE; |
1658 win_T *win; | |
1659 win_T *altwin; | |
1822 | 1660 int flags; |
7 | 1661 #endif |
1743 | 1662 win_T *oldwin = curwin; |
7 | 1663 int print_message = TRUE; |
1664 int len; | |
1665 #ifdef FEAT_FOLDING | |
1666 int old_KeyTyped = KeyTyped; /* getting file may reset it */ | |
1667 #endif | |
9 | 1668 int ok = OK; |
644 | 1669 int usable_win; |
1670 | |
659 | 1671 if (qi == NULL) |
1672 qi = &ql_info; | |
644 | 1673 |
1674 if (qi->qf_curlist >= qi->qf_listcount | |
1675 || qi->qf_lists[qi->qf_curlist].qf_count == 0) | |
7 | 1676 { |
1677 EMSG(_(e_quickfix)); | |
1678 return; | |
1679 } | |
1680 | |
644 | 1681 qf_ptr = qi->qf_lists[qi->qf_curlist].qf_ptr; |
7 | 1682 old_qf_ptr = qf_ptr; |
644 | 1683 qf_index = qi->qf_lists[qi->qf_curlist].qf_index; |
7 | 1684 old_qf_index = qf_index; |
1685 if (dir == FORWARD || dir == FORWARD_FILE) /* next valid entry */ | |
1686 { | |
1687 while (errornr--) | |
1688 { | |
1689 old_qf_ptr = qf_ptr; | |
1690 prev_index = qf_index; | |
1691 old_qf_fnum = qf_ptr->qf_fnum; | |
1692 do | |
1693 { | |
644 | 1694 if (qf_index == qi->qf_lists[qi->qf_curlist].qf_count |
7 | 1695 || qf_ptr->qf_next == NULL) |
1696 { | |
1697 qf_ptr = old_qf_ptr; | |
1698 qf_index = prev_index; | |
1699 if (err != NULL) | |
1700 { | |
1701 EMSG(_(err)); | |
1702 goto theend; | |
1703 } | |
1704 errornr = 0; | |
1705 break; | |
1706 } | |
1707 ++qf_index; | |
1708 qf_ptr = qf_ptr->qf_next; | |
644 | 1709 } while ((!qi->qf_lists[qi->qf_curlist].qf_nonevalid |
1710 && !qf_ptr->qf_valid) | |
7 | 1711 || (dir == FORWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum)); |
1712 err = NULL; | |
1713 } | |
1714 } | |
1715 else if (dir == BACKWARD || dir == BACKWARD_FILE) /* prev. valid entry */ | |
1716 { | |
1717 while (errornr--) | |
1718 { | |
1719 old_qf_ptr = qf_ptr; | |
1720 prev_index = qf_index; | |
1721 old_qf_fnum = qf_ptr->qf_fnum; | |
1722 do | |
1723 { | |
1724 if (qf_index == 1 || qf_ptr->qf_prev == NULL) | |
1725 { | |
1726 qf_ptr = old_qf_ptr; | |
1727 qf_index = prev_index; | |
1728 if (err != NULL) | |
1729 { | |
1730 EMSG(_(err)); | |
1731 goto theend; | |
1732 } | |
1733 errornr = 0; | |
1734 break; | |
1735 } | |
1736 --qf_index; | |
1737 qf_ptr = qf_ptr->qf_prev; | |
644 | 1738 } while ((!qi->qf_lists[qi->qf_curlist].qf_nonevalid |
1739 && !qf_ptr->qf_valid) | |
7 | 1740 || (dir == BACKWARD_FILE && qf_ptr->qf_fnum == old_qf_fnum)); |
1741 err = NULL; | |
1742 } | |
1743 } | |
1744 else if (errornr != 0) /* go to specified number */ | |
1745 { | |
1746 while (errornr < qf_index && qf_index > 1 && qf_ptr->qf_prev != NULL) | |
1747 { | |
1748 --qf_index; | |
1749 qf_ptr = qf_ptr->qf_prev; | |
1750 } | |
644 | 1751 while (errornr > qf_index && qf_index < |
1752 qi->qf_lists[qi->qf_curlist].qf_count | |
7 | 1753 && qf_ptr->qf_next != NULL) |
1754 { | |
1755 ++qf_index; | |
1756 qf_ptr = qf_ptr->qf_next; | |
1757 } | |
1758 } | |
1759 | |
1760 #ifdef FEAT_WINDOWS | |
644 | 1761 qi->qf_lists[qi->qf_curlist].qf_index = qf_index; |
1762 if (qf_win_pos_update(qi, old_qf_index)) | |
7 | 1763 /* No need to print the error message if it's visible in the error |
1764 * window */ | |
1765 print_message = FALSE; | |
1766 | |
1767 /* | |
9 | 1768 * For ":helpgrep" find a help window or open one. |
1769 */ | |
682 | 1770 if (qf_ptr->qf_type == 1 && (!curwin->w_buffer->b_help || cmdmod.tab != 0)) |
9 | 1771 { |
1772 win_T *wp; | |
1773 | |
682 | 1774 if (cmdmod.tab != 0) |
1775 wp = NULL; | |
1776 else | |
1777 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
1778 if (wp->w_buffer != NULL && wp->w_buffer->b_help) | |
1779 break; | |
9 | 1780 if (wp != NULL && wp->w_buffer->b_nwindows > 0) |
1781 win_enter(wp, TRUE); | |
1782 else | |
1783 { | |
1784 /* | |
1785 * Split off help window; put it at far top if no position | |
1786 * specified, the current window is vertically split and narrow. | |
1787 */ | |
1822 | 1788 flags = WSP_HELP; |
9 | 1789 if (cmdmod.split == 0 && curwin->w_width != Columns |
1790 && curwin->w_width < 80) | |
1822 | 1791 flags |= WSP_TOP; |
1792 if (qi != &ql_info) | |
1793 flags |= WSP_NEWLOC; /* don't copy the location list */ | |
1794 | |
1795 if (win_split(0, flags) == FAIL) | |
9 | 1796 goto theend; |
26 | 1797 opened_window = TRUE; /* close it when fail */ |
9 | 1798 |
1799 if (curwin->w_height < p_hh) | |
1800 win_setheight((int)p_hh); | |
659 | 1801 |
1802 if (qi != &ql_info) /* not a quickfix list */ | |
1803 { | |
1804 /* The new window should use the supplied location list */ | |
1805 curwin->w_llist = qi; | |
1806 qi->qf_refcount++; | |
1807 } | |
9 | 1808 } |
1809 | |
1810 if (!p_im) | |
1811 restart_edit = 0; /* don't want insert mode in help file */ | |
1812 } | |
1813 | |
1814 /* | |
7 | 1815 * If currently in the quickfix window, find another window to show the |
1816 * file in. | |
1817 */ | |
26 | 1818 if (bt_quickfix(curbuf) && !opened_window) |
7 | 1819 { |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1820 win_T *usable_win_ptr = NULL; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1821 |
7 | 1822 /* |
1823 * If there is no file specified, we don't know where to go. | |
1824 * But do advance, otherwise ":cn" gets stuck. | |
1825 */ | |
1826 if (qf_ptr->qf_fnum == 0) | |
1827 goto theend; | |
1828 | |
644 | 1829 usable_win = 0; |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1830 |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1831 ll_ref = curwin->w_llist_ref; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1832 if (ll_ref != NULL) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1833 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1834 /* Find a window using the same location list that is not a |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1835 * quickfix window. */ |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1836 FOR_ALL_WINDOWS(usable_win_ptr) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1837 if (usable_win_ptr->w_llist == ll_ref |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1838 && usable_win_ptr->w_buffer->b_p_bt[0] != 'q') |
5084
14e7a115d54d
updated for version 7.3.1285
Bram Moolenaar <bram@vim.org>
parents:
5062
diff
changeset
|
1839 { |
14e7a115d54d
updated for version 7.3.1285
Bram Moolenaar <bram@vim.org>
parents:
5062
diff
changeset
|
1840 usable_win = 1; |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1841 break; |
5084
14e7a115d54d
updated for version 7.3.1285
Bram Moolenaar <bram@vim.org>
parents:
5062
diff
changeset
|
1842 } |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1843 } |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1844 |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1845 if (!usable_win) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1846 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1847 /* Locate a window showing a normal buffer */ |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1848 FOR_ALL_WINDOWS(win) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1849 if (win->w_buffer->b_p_bt[0] == NUL) |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1850 { |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1851 usable_win = 1; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1852 break; |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1853 } |
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1854 } |
644 | 1855 |
7 | 1856 /* |
1621 | 1857 * If no usable window is found and 'switchbuf' contains "usetab" |
1020 | 1858 * then search in other tabs. |
7 | 1859 */ |
1621 | 1860 if (!usable_win && (swb_flags & SWB_USETAB)) |
1020 | 1861 { |
1862 tabpage_T *tp; | |
1863 win_T *wp; | |
1864 | |
1865 FOR_ALL_TAB_WINDOWS(tp, wp) | |
1866 { | |
1867 if (wp->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1868 { | |
1869 goto_tabpage_win(tp, wp); | |
1870 usable_win = 1; | |
1819 | 1871 goto win_found; |
1020 | 1872 } |
1873 } | |
1874 } | |
1819 | 1875 win_found: |
1020 | 1876 |
1877 /* | |
1396 | 1878 * If there is only one window and it is the quickfix window, create a |
1879 * new one above the quickfix window. | |
1020 | 1880 */ |
1881 if (((firstwin == lastwin) && bt_quickfix(curbuf)) || !usable_win) | |
7 | 1882 { |
1822 | 1883 flags = WSP_ABOVE; |
1884 if (ll_ref != NULL) | |
1885 flags |= WSP_NEWLOC; | |
1886 if (win_split(0, flags) == FAIL) | |
7 | 1887 goto failed; /* not enough room for window */ |
1888 opened_window = TRUE; /* close it when fail */ | |
1889 p_swb = empty_option; /* don't split again */ | |
1621 | 1890 swb_flags = 0; |
2583 | 1891 RESET_BINDING(curwin); |
644 | 1892 if (ll_ref != NULL) |
1893 { | |
1894 /* The new window should use the location list from the | |
1895 * location list window */ | |
1896 curwin->w_llist = ll_ref; | |
1897 ll_ref->qf_refcount++; | |
1898 } | |
7 | 1899 } |
1900 else | |
1901 { | |
644 | 1902 if (curwin->w_llist_ref != NULL) |
1903 { | |
1904 /* In a location window */ | |
5062
761cef8f5d1d
updated for version 7.3.1274
Bram Moolenaar <bram@vim.org>
parents:
5060
diff
changeset
|
1905 win = usable_win_ptr; |
644 | 1906 if (win == NULL) |
1907 { | |
1908 /* Find the window showing the selected file */ | |
1909 FOR_ALL_WINDOWS(win) | |
1910 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1911 break; | |
1912 if (win == NULL) | |
1913 { | |
1914 /* Find a previous usable window */ | |
1915 win = curwin; | |
1916 do | |
1917 { | |
1918 if (win->w_buffer->b_p_bt[0] == NUL) | |
1919 break; | |
1920 if (win->w_prev == NULL) | |
1921 win = lastwin; /* wrap around the top */ | |
1922 else | |
1923 win = win->w_prev; /* go to previous window */ | |
1924 } while (win != curwin); | |
1925 } | |
1926 } | |
1927 win_goto(win); | |
1928 | |
1929 /* If the location list for the window is not set, then set it | |
1930 * to the location list from the location window */ | |
1931 if (win->w_llist == NULL) | |
1932 { | |
1933 win->w_llist = ll_ref; | |
1934 ll_ref->qf_refcount++; | |
1935 } | |
1936 } | |
1937 else | |
1938 { | |
1939 | |
7 | 1940 /* |
1941 * Try to find a window that shows the right buffer. | |
1942 * Default to the window just above the quickfix buffer. | |
1943 */ | |
1944 win = curwin; | |
1945 altwin = NULL; | |
1946 for (;;) | |
1947 { | |
1948 if (win->w_buffer->b_fnum == qf_ptr->qf_fnum) | |
1949 break; | |
1950 if (win->w_prev == NULL) | |
1951 win = lastwin; /* wrap around the top */ | |
1952 else | |
1953 win = win->w_prev; /* go to previous window */ | |
1954 | |
644 | 1955 if (IS_QF_WINDOW(win)) |
7 | 1956 { |
1957 /* Didn't find it, go to the window before the quickfix | |
1958 * window. */ | |
1959 if (altwin != NULL) | |
1960 win = altwin; | |
1961 else if (curwin->w_prev != NULL) | |
1962 win = curwin->w_prev; | |
1963 else | |
1964 win = curwin->w_next; | |
1965 break; | |
1966 } | |
1967 | |
1968 /* Remember a usable window. */ | |
1969 if (altwin == NULL && !win->w_p_pvw | |
1970 && win->w_buffer->b_p_bt[0] == NUL) | |
1971 altwin = win; | |
1972 } | |
1973 | |
1974 win_goto(win); | |
644 | 1975 } |
7 | 1976 } |
1977 } | |
1978 #endif | |
1979 | |
1980 /* | |
1981 * If there is a file name, | |
1982 * read the wanted file if needed, and check autowrite etc. | |
1983 */ | |
1984 old_curbuf = curbuf; | |
1985 old_lnum = curwin->w_cursor.lnum; | |
9 | 1986 |
1987 if (qf_ptr->qf_fnum != 0) | |
1988 { | |
1989 if (qf_ptr->qf_type == 1) | |
1990 { | |
1991 /* Open help file (do_ecmd() will set b_help flag, readfile() will | |
1992 * set b_p_ro flag). */ | |
1993 if (!can_abandon(curbuf, forceit)) | |
1994 { | |
1995 EMSG(_(e_nowrtmsg)); | |
1996 ok = FALSE; | |
1997 } | |
1998 else | |
1999 ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1, | |
1743 | 2000 ECMD_HIDE + ECMD_SET_HELP, |
2001 oldwin == curwin ? curwin : NULL); | |
9 | 2002 } |
2003 else | |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2004 { |
8702
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2005 int old_qf_curlist = qi->qf_curlist; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2006 int is_abort = FALSE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2007 |
9 | 2008 ok = buflist_getfile(qf_ptr->qf_fnum, |
2009 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit); | |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2010 if (qi != &ql_info && !win_valid(oldwin)) |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2011 { |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2012 EMSG(_("E924: Current window was closed")); |
8702
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2013 is_abort = TRUE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2014 opened_window = FALSE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2015 } |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2016 else if (old_qf_curlist != qi->qf_curlist |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2017 || !is_qf_entry_present(qi, qf_ptr)) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2018 { |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2019 if (qi == &ql_info) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2020 EMSG(_("E925: Current quickfix was changed")); |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2021 else |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2022 EMSG(_("E926: Current location list was changed")); |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2023 is_abort = TRUE; |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2024 } |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2025 |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2026 if (is_abort) |
39d6e4f2f748
commit https://github.com/vim/vim/commit/ffec3c53496d49668669deabc0724ec78e2274fd
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2027 { |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2028 ok = FALSE; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2029 qi = NULL; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2030 qf_ptr = NULL; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2031 } |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2032 } |
9 | 2033 } |
2034 | |
2035 if (ok == OK) | |
7 | 2036 { |
2037 /* When not switched to another buffer, still need to set pc mark */ | |
2038 if (curbuf == old_curbuf) | |
2039 setpcmark(); | |
2040 | |
230 | 2041 if (qf_ptr->qf_pattern == NULL) |
7 | 2042 { |
230 | 2043 /* |
2044 * Go to line with error, unless qf_lnum is 0. | |
2045 */ | |
2046 i = qf_ptr->qf_lnum; | |
2047 if (i > 0) | |
2048 { | |
2049 if (i > curbuf->b_ml.ml_line_count) | |
2050 i = curbuf->b_ml.ml_line_count; | |
2051 curwin->w_cursor.lnum = i; | |
2052 } | |
2053 if (qf_ptr->qf_col > 0) | |
7 | 2054 { |
230 | 2055 curwin->w_cursor.col = qf_ptr->qf_col - 1; |
6853 | 2056 #ifdef FEAT_VIRTUALEDIT |
2057 curwin->w_cursor.coladd = 0; | |
2058 #endif | |
230 | 2059 if (qf_ptr->qf_viscol == TRUE) |
7 | 2060 { |
230 | 2061 /* |
2062 * Check each character from the beginning of the error | |
2063 * line up to the error column. For each tab character | |
2064 * found, reduce the error column value by the length of | |
2065 * a tab character. | |
2066 */ | |
2067 line = ml_get_curline(); | |
2068 screen_col = 0; | |
2069 for (char_col = 0; char_col < curwin->w_cursor.col; ++char_col) | |
7 | 2070 { |
230 | 2071 if (*line == NUL) |
2072 break; | |
2073 if (*line++ == '\t') | |
2074 { | |
2075 curwin->w_cursor.col -= 7 - (screen_col % 8); | |
2076 screen_col += 8 - (screen_col % 8); | |
2077 } | |
2078 else | |
2079 ++screen_col; | |
7 | 2080 } |
2081 } | |
230 | 2082 check_cursor(); |
7 | 2083 } |
230 | 2084 else |
2085 beginline(BL_WHITE | BL_FIX); | |
7 | 2086 } |
2087 else | |
230 | 2088 { |
2089 pos_T save_cursor; | |
2090 | |
2091 /* Move the cursor to the first line in the buffer */ | |
2092 save_cursor = curwin->w_cursor; | |
2093 curwin->w_cursor.lnum = 0; | |
1521 | 2094 if (!do_search(NULL, '/', qf_ptr->qf_pattern, (long)1, |
2095 SEARCH_KEEP, NULL)) | |
230 | 2096 curwin->w_cursor = save_cursor; |
2097 } | |
7 | 2098 |
2099 #ifdef FEAT_FOLDING | |
2100 if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped) | |
2101 foldOpenCursor(); | |
2102 #endif | |
2103 if (print_message) | |
2104 { | |
3267 | 2105 /* Update the screen before showing the message, unless the screen |
2106 * scrolled up. */ | |
2107 if (!msg_scrolled) | |
2108 update_topline_redraw(); | |
7 | 2109 sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index, |
644 | 2110 qi->qf_lists[qi->qf_curlist].qf_count, |
7 | 2111 qf_ptr->qf_cleared ? _(" (line deleted)") : "", |
2112 (char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr)); | |
2113 /* Add the message, skipping leading whitespace and newlines. */ | |
2114 len = (int)STRLEN(IObuff); | |
2115 qf_fmt_text(skipwhite(qf_ptr->qf_text), IObuff + len, IOSIZE - len); | |
2116 | |
2117 /* Output the message. Overwrite to avoid scrolling when the 'O' | |
2118 * flag is present in 'shortmess'; But when not jumping, print the | |
2119 * whole message. */ | |
2120 i = msg_scroll; | |
2121 if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) | |
2122 msg_scroll = TRUE; | |
2123 else if (!msg_scrolled && shortmess(SHM_OVERALL)) | |
2124 msg_scroll = FALSE; | |
2125 msg_attr_keep(IObuff, 0, TRUE); | |
2126 msg_scroll = i; | |
2127 } | |
2128 } | |
2129 else | |
2130 { | |
2131 #ifdef FEAT_WINDOWS | |
2132 if (opened_window) | |
2133 win_close(curwin, TRUE); /* Close opened window */ | |
2134 #endif | |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2135 if (qf_ptr != NULL && qf_ptr->qf_fnum != 0) |
7 | 2136 { |
2137 /* | |
2138 * Couldn't open file, so put index back where it was. This could | |
2139 * happen if the file was readonly and we changed something. | |
2140 */ | |
2141 #ifdef FEAT_WINDOWS | |
2142 failed: | |
2143 #endif | |
2144 qf_ptr = old_qf_ptr; | |
2145 qf_index = old_qf_index; | |
2146 } | |
2147 } | |
2148 theend: | |
8605
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2149 if (qi != NULL) |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2150 { |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2151 qi->qf_lists[qi->qf_curlist].qf_ptr = qf_ptr; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2152 qi->qf_lists[qi->qf_curlist].qf_index = qf_index; |
536b9b88d1ca
commit https://github.com/vim/vim/commit/0899d698030ec076eb26352cda1ea334ab0819d9
Christian Brabandt <cb@256bit.org>
parents:
8603
diff
changeset
|
2153 } |
7 | 2154 #ifdef FEAT_WINDOWS |
2155 if (p_swb != old_swb && opened_window) | |
2156 { | |
2157 /* Restore old 'switchbuf' value, but not when an autocommand or | |
2158 * modeline has changed the value. */ | |
2159 if (p_swb == empty_option) | |
1621 | 2160 { |
7 | 2161 p_swb = old_swb; |
1621 | 2162 swb_flags = old_swb_flags; |
2163 } | |
7 | 2164 else |
2165 free_string_option(old_swb); | |
2166 } | |
2167 #endif | |
2168 } | |
2169 | |
2170 /* | |
2171 * ":clist": list all errors | |
644 | 2172 * ":llist": list all locations |
7 | 2173 */ |
2174 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2175 qf_list(exarg_T *eap) |
7 | 2176 { |
230 | 2177 buf_T *buf; |
2178 char_u *fname; | |
2179 qfline_T *qfp; | |
2180 int i; | |
2181 int idx1 = 1; | |
2182 int idx2 = -1; | |
2183 char_u *arg = eap->arg; | |
2184 int all = eap->forceit; /* if not :cl!, only show | |
7 | 2185 recognised errors */ |
644 | 2186 qf_info_T *qi = &ql_info; |
2187 | |
2188 if (eap->cmdidx == CMD_llist) | |
2189 { | |
2190 qi = GET_LOC_LIST(curwin); | |
2191 if (qi == NULL) | |
2192 { | |
2193 EMSG(_(e_loclist)); | |
2194 return; | |
2195 } | |
2196 } | |
2197 | |
2198 if (qi->qf_curlist >= qi->qf_listcount | |
2199 || qi->qf_lists[qi->qf_curlist].qf_count == 0) | |
7 | 2200 { |
2201 EMSG(_(e_quickfix)); | |
2202 return; | |
2203 } | |
2204 if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL) | |
2205 { | |
2206 EMSG(_(e_trailing)); | |
2207 return; | |
2208 } | |
644 | 2209 i = qi->qf_lists[qi->qf_curlist].qf_count; |
7 | 2210 if (idx1 < 0) |
2211 idx1 = (-idx1 > i) ? 0 : idx1 + i + 1; | |
2212 if (idx2 < 0) | |
2213 idx2 = (-idx2 > i) ? 0 : idx2 + i + 1; | |
2214 | |
644 | 2215 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid) |
7 | 2216 all = TRUE; |
644 | 2217 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
2218 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ) | |
7 | 2219 { |
2220 if ((qfp->qf_valid || all) && idx1 <= i && i <= idx2) | |
2221 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
2222 msg_putchar('\n'); |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
2223 if (got_int) |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1918
diff
changeset
|
2224 break; |
446 | 2225 |
2226 fname = NULL; | |
2227 if (qfp->qf_fnum != 0 | |
7 | 2228 && (buf = buflist_findnr(qfp->qf_fnum)) != NULL) |
446 | 2229 { |
2230 fname = buf->b_fname; | |
2231 if (qfp->qf_type == 1) /* :helpgrep */ | |
2232 fname = gettail(fname); | |
2233 } | |
2234 if (fname == NULL) | |
2235 sprintf((char *)IObuff, "%2d", i); | |
2236 else | |
2237 vim_snprintf((char *)IObuff, IOSIZE, "%2d %s", | |
273 | 2238 i, (char *)fname); |
644 | 2239 msg_outtrans_attr(IObuff, i == qi->qf_lists[qi->qf_curlist].qf_index |
446 | 2240 ? hl_attr(HLF_L) : hl_attr(HLF_D)); |
2241 if (qfp->qf_lnum == 0) | |
2242 IObuff[0] = NUL; | |
2243 else if (qfp->qf_col == 0) | |
2244 sprintf((char *)IObuff, ":%ld", qfp->qf_lnum); | |
2245 else | |
2246 sprintf((char *)IObuff, ":%ld col %d", | |
7 | 2247 qfp->qf_lnum, qfp->qf_col); |
446 | 2248 sprintf((char *)IObuff + STRLEN(IObuff), "%s:", |
7 | 2249 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); |
446 | 2250 msg_puts_attr(IObuff, hl_attr(HLF_N)); |
2251 if (qfp->qf_pattern != NULL) | |
2252 { | |
2253 qf_fmt_text(qfp->qf_pattern, IObuff, IOSIZE); | |
2254 STRCAT(IObuff, ":"); | |
2255 msg_puts(IObuff); | |
2256 } | |
2257 msg_puts((char_u *)" "); | |
230 | 2258 |
446 | 2259 /* Remove newlines and leading whitespace from the text. For an |
2260 * unrecognized line keep the indent, the compiler may mark a word | |
2261 * with ^^^^. */ | |
2262 qf_fmt_text((fname != NULL || qfp->qf_lnum != 0) | |
7 | 2263 ? skipwhite(qfp->qf_text) : qfp->qf_text, |
2264 IObuff, IOSIZE); | |
446 | 2265 msg_prt_line(IObuff, FALSE); |
2266 out_flush(); /* show one line at a time */ | |
7 | 2267 } |
446 | 2268 |
2269 qfp = qfp->qf_next; | |
2270 ++i; | |
7 | 2271 ui_breakcheck(); |
2272 } | |
2273 } | |
2274 | |
2275 /* | |
2276 * Remove newlines and leading whitespace from an error message. | |
2277 * Put the result in "buf[bufsize]". | |
2278 */ | |
2279 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2280 qf_fmt_text(char_u *text, char_u *buf, int bufsize) |
7 | 2281 { |
2282 int i; | |
2283 char_u *p = text; | |
2284 | |
2285 for (i = 0; *p != NUL && i < bufsize - 1; ++i) | |
2286 { | |
2287 if (*p == '\n') | |
2288 { | |
2289 buf[i] = ' '; | |
2290 while (*++p != NUL) | |
2291 if (!vim_iswhite(*p) && *p != '\n') | |
2292 break; | |
2293 } | |
2294 else | |
2295 buf[i] = *p++; | |
2296 } | |
2297 buf[i] = NUL; | |
2298 } | |
2299 | |
2300 /* | |
2301 * ":colder [count]": Up in the quickfix stack. | |
2302 * ":cnewer [count]": Down in the quickfix stack. | |
644 | 2303 * ":lolder [count]": Up in the location list stack. |
2304 * ":lnewer [count]": Down in the location list stack. | |
7 | 2305 */ |
2306 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2307 qf_age(exarg_T *eap) |
7 | 2308 { |
644 | 2309 qf_info_T *qi = &ql_info; |
7 | 2310 int count; |
2311 | |
644 | 2312 if (eap->cmdidx == CMD_lolder || eap->cmdidx == CMD_lnewer) |
2313 { | |
2314 qi = GET_LOC_LIST(curwin); | |
2315 if (qi == NULL) | |
2316 { | |
2317 EMSG(_(e_loclist)); | |
2318 return; | |
2319 } | |
2320 } | |
2321 | |
7 | 2322 if (eap->addr_count != 0) |
2323 count = eap->line2; | |
2324 else | |
2325 count = 1; | |
2326 while (count--) | |
2327 { | |
644 | 2328 if (eap->cmdidx == CMD_colder || eap->cmdidx == CMD_lolder) |
7 | 2329 { |
644 | 2330 if (qi->qf_curlist == 0) |
7 | 2331 { |
2332 EMSG(_("E380: At bottom of quickfix stack")); | |
4371 | 2333 break; |
7 | 2334 } |
644 | 2335 --qi->qf_curlist; |
7 | 2336 } |
2337 else | |
2338 { | |
644 | 2339 if (qi->qf_curlist >= qi->qf_listcount - 1) |
7 | 2340 { |
2341 EMSG(_("E381: At top of quickfix stack")); | |
4371 | 2342 break; |
7 | 2343 } |
644 | 2344 ++qi->qf_curlist; |
7 | 2345 } |
2346 } | |
644 | 2347 qf_msg(qi); |
7 | 2348 } |
2349 | |
2350 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2351 qf_msg(qf_info_T *qi) |
7 | 2352 { |
2353 smsg((char_u *)_("error list %d of %d; %d errors"), | |
644 | 2354 qi->qf_curlist + 1, qi->qf_listcount, |
2355 qi->qf_lists[qi->qf_curlist].qf_count); | |
7 | 2356 #ifdef FEAT_WINDOWS |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2357 qf_update_buffer(qi, NULL); |
7 | 2358 #endif |
2359 } | |
2360 | |
2361 /* | |
581 | 2362 * Free error list "idx". |
7 | 2363 */ |
2364 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2365 qf_free(qf_info_T *qi, int idx) |
7 | 2366 { |
230 | 2367 qfline_T *qfp; |
3982 | 2368 int stop = FALSE; |
7 | 2369 |
644 | 2370 while (qi->qf_lists[idx].qf_count) |
7 | 2371 { |
644 | 2372 qfp = qi->qf_lists[idx].qf_start->qf_next; |
3982 | 2373 if (qi->qf_lists[idx].qf_title != NULL && !stop) |
3949 | 2374 { |
2375 vim_free(qi->qf_lists[idx].qf_start->qf_text); | |
3982 | 2376 stop = (qi->qf_lists[idx].qf_start == qfp); |
3949 | 2377 vim_free(qi->qf_lists[idx].qf_start->qf_pattern); |
2378 vim_free(qi->qf_lists[idx].qf_start); | |
3982 | 2379 if (stop) |
2380 /* Somehow qf_count may have an incorrect value, set it to 1 | |
2381 * to avoid crashing when it's wrong. | |
2382 * TODO: Avoid qf_count being incorrect. */ | |
2383 qi->qf_lists[idx].qf_count = 1; | |
3949 | 2384 } |
644 | 2385 qi->qf_lists[idx].qf_start = qfp; |
2386 --qi->qf_lists[idx].qf_count; | |
7 | 2387 } |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
2388 vim_free(qi->qf_lists[idx].qf_title); |
2576 | 2389 qi->qf_lists[idx].qf_title = NULL; |
6081 | 2390 qi->qf_lists[idx].qf_index = 0; |
7 | 2391 } |
2392 | |
2393 /* | |
2394 * qf_mark_adjust: adjust marks | |
2395 */ | |
2396 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2397 qf_mark_adjust( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2398 win_T *wp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2399 linenr_T line1, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2400 linenr_T line2, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2401 long amount, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2402 long amount_after) |
7 | 2403 { |
230 | 2404 int i; |
2405 qfline_T *qfp; | |
2406 int idx; | |
644 | 2407 qf_info_T *qi = &ql_info; |
2408 | |
2409 if (wp != NULL) | |
2410 { | |
2411 if (wp->w_llist == NULL) | |
2412 return; | |
2413 qi = wp->w_llist; | |
2414 } | |
2415 | |
2416 for (idx = 0; idx < qi->qf_listcount; ++idx) | |
2417 if (qi->qf_lists[idx].qf_count) | |
2418 for (i = 0, qfp = qi->qf_lists[idx].qf_start; | |
2419 i < qi->qf_lists[idx].qf_count; ++i, qfp = qfp->qf_next) | |
7 | 2420 if (qfp->qf_fnum == curbuf->b_fnum) |
2421 { | |
2422 if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2) | |
2423 { | |
2424 if (amount == MAXLNUM) | |
2425 qfp->qf_cleared = TRUE; | |
2426 else | |
2427 qfp->qf_lnum += amount; | |
2428 } | |
2429 else if (amount_after && qfp->qf_lnum > line2) | |
2430 qfp->qf_lnum += amount_after; | |
2431 } | |
2432 } | |
2433 | |
2434 /* | |
2435 * Make a nice message out of the error character and the error number: | |
2436 * char number message | |
2437 * e or E 0 " error" | |
2438 * w or W 0 " warning" | |
2439 * i or I 0 " info" | |
2440 * 0 0 "" | |
2441 * other 0 " c" | |
2442 * e or E n " error n" | |
2443 * w or W n " warning n" | |
2444 * i or I n " info n" | |
2445 * 0 n " error n" | |
2446 * other n " c n" | |
2447 * 1 x "" :helpgrep | |
2448 */ | |
2449 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2450 qf_types(int c, int nr) |
7 | 2451 { |
2452 static char_u buf[20]; | |
2453 static char_u cc[3]; | |
2454 char_u *p; | |
2455 | |
2456 if (c == 'W' || c == 'w') | |
2457 p = (char_u *)" warning"; | |
2458 else if (c == 'I' || c == 'i') | |
2459 p = (char_u *)" info"; | |
2460 else if (c == 'E' || c == 'e' || (c == 0 && nr > 0)) | |
2461 p = (char_u *)" error"; | |
2462 else if (c == 0 || c == 1) | |
2463 p = (char_u *)""; | |
2464 else | |
2465 { | |
2466 cc[0] = ' '; | |
2467 cc[1] = c; | |
2468 cc[2] = NUL; | |
2469 p = cc; | |
2470 } | |
2471 | |
2472 if (nr <= 0) | |
2473 return p; | |
2474 | |
2475 sprintf((char *)buf, "%s %3d", (char *)p, nr); | |
2476 return buf; | |
2477 } | |
2478 | |
2479 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
2480 /* | |
2481 * ":cwindow": open the quickfix window if we have errors to display, | |
2482 * close it if not. | |
644 | 2483 * ":lwindow": open the location list window if we have locations to display, |
2484 * close it if not. | |
7 | 2485 */ |
2486 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2487 ex_cwindow(exarg_T *eap) |
7 | 2488 { |
644 | 2489 qf_info_T *qi = &ql_info; |
7 | 2490 win_T *win; |
2491 | |
644 | 2492 if (eap->cmdidx == CMD_lwindow) |
2493 { | |
2494 qi = GET_LOC_LIST(curwin); | |
2495 if (qi == NULL) | |
2496 return; | |
2497 } | |
2498 | |
2499 /* Look for an existing quickfix window. */ | |
2500 win = qf_find_win(qi); | |
7 | 2501 |
2502 /* | |
2503 * If a quickfix window is open but we have no errors to display, | |
2504 * close the window. If a quickfix window is not open, then open | |
2505 * it if we have errors; otherwise, leave it closed. | |
2506 */ | |
644 | 2507 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid |
2795 | 2508 || qi->qf_lists[qi->qf_curlist].qf_count == 0 |
857 | 2509 || qi->qf_curlist >= qi->qf_listcount) |
7 | 2510 { |
2511 if (win != NULL) | |
2512 ex_cclose(eap); | |
2513 } | |
2514 else if (win == NULL) | |
2515 ex_copen(eap); | |
2516 } | |
2517 | |
2518 /* | |
2519 * ":cclose": close the window showing the list of errors. | |
644 | 2520 * ":lclose": close the window showing the location list |
7 | 2521 */ |
2522 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2523 ex_cclose(exarg_T *eap) |
7 | 2524 { |
644 | 2525 win_T *win = NULL; |
2526 qf_info_T *qi = &ql_info; | |
2527 | |
2528 if (eap->cmdidx == CMD_lclose || eap->cmdidx == CMD_lwindow) | |
2529 { | |
2530 qi = GET_LOC_LIST(curwin); | |
2531 if (qi == NULL) | |
2532 return; | |
2533 } | |
2534 | |
2535 /* Find existing quickfix window and close it. */ | |
2536 win = qf_find_win(qi); | |
7 | 2537 if (win != NULL) |
2538 win_close(win, FALSE); | |
2539 } | |
2540 | |
2541 /* | |
2542 * ":copen": open a window that shows the list of errors. | |
644 | 2543 * ":lopen": open a window that shows the location list. |
7 | 2544 */ |
2545 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2546 ex_copen(exarg_T *eap) |
7 | 2547 { |
644 | 2548 qf_info_T *qi = &ql_info; |
7 | 2549 int height; |
2550 win_T *win; | |
682 | 2551 tabpage_T *prevtab = curtab; |
859 | 2552 buf_T *qf_buf; |
1743 | 2553 win_T *oldwin = curwin; |
7 | 2554 |
644 | 2555 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow) |
2556 { | |
2557 qi = GET_LOC_LIST(curwin); | |
2558 if (qi == NULL) | |
2559 { | |
2560 EMSG(_(e_loclist)); | |
2561 return; | |
2562 } | |
2563 } | |
2564 | |
7 | 2565 if (eap->addr_count != 0) |
2566 height = eap->line2; | |
2567 else | |
2568 height = QF_WINHEIGHT; | |
2569 | |
2570 reset_VIsual_and_resel(); /* stop Visual mode */ | |
2571 #ifdef FEAT_GUI | |
2572 need_mouse_correct = TRUE; | |
2573 #endif | |
2574 | |
2575 /* | |
2576 * Find existing quickfix window, or open a new one. | |
2577 */ | |
644 | 2578 win = qf_find_win(qi); |
2579 | |
682 | 2580 if (win != NULL && cmdmod.tab == 0) |
5753 | 2581 { |
7 | 2582 win_goto(win); |
5753 | 2583 if (eap->addr_count != 0) |
2584 { | |
2585 if (cmdmod.split & WSP_VERT) | |
2586 { | |
2587 if (height != W_WIDTH(win)) | |
2588 win_setwidth(height); | |
2589 } | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8605
diff
changeset
|
2590 else if (height != win->w_height) |
5753 | 2591 win_setheight(height); |
2592 } | |
2593 } | |
7 | 2594 else |
2595 { | |
859 | 2596 qf_buf = qf_find_buf(qi); |
2597 | |
7 | 2598 /* The current window becomes the previous window afterwards. */ |
2599 win = curwin; | |
2600 | |
3939 | 2601 if ((eap->cmdidx == CMD_copen || eap->cmdidx == CMD_cwindow) |
2602 && cmdmod.split == 0) | |
2603 /* Create the new window at the very bottom, except when | |
2604 * :belowright or :aboveleft is used. */ | |
644 | 2605 win_goto(lastwin); |
1822 | 2606 if (win_split(height, WSP_BELOW | WSP_NEWLOC) == FAIL) |
7 | 2607 return; /* not enough room for window */ |
2583 | 2608 RESET_BINDING(curwin); |
7 | 2609 |
644 | 2610 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow) |
7 | 2611 { |
644 | 2612 /* |
2613 * For the location list window, create a reference to the | |
2614 * location list from the window 'win'. | |
2615 */ | |
2616 curwin->w_llist_ref = win->w_llist; | |
2617 win->w_llist->qf_refcount++; | |
7 | 2618 } |
644 | 2619 |
1743 | 2620 if (oldwin != curwin) |
2621 oldwin = NULL; /* don't store info when in another window */ | |
859 | 2622 if (qf_buf != NULL) |
2623 /* Use the existing quickfix buffer */ | |
2624 (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE, | |
1743 | 2625 ECMD_HIDE + ECMD_OLDBUF, oldwin); |
859 | 2626 else |
2627 { | |
2628 /* Create a new quickfix buffer */ | |
1743 | 2629 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin); |
859 | 2630 /* switch off 'swapfile' */ |
2631 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | |
2632 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix", | |
729 | 2633 OPT_LOCAL); |
859 | 2634 set_option_value((char_u *)"bh", 0L, (char_u *)"wipe", OPT_LOCAL); |
2651 | 2635 RESET_BINDING(curwin); |
1864 | 2636 #ifdef FEAT_DIFF |
2637 curwin->w_p_diff = FALSE; | |
2638 #endif | |
2639 #ifdef FEAT_FOLDING | |
2640 set_option_value((char_u *)"fdm", 0L, (char_u *)"manual", | |
2641 OPT_LOCAL); | |
2642 #endif | |
859 | 2643 } |
7 | 2644 |
682 | 2645 /* Only set the height when still in the same tab page and there is no |
2646 * window to the side. */ | |
8643
24b43dd167eb
commit https://github.com/vim/vim/commit/44a2f923c00f1384c9ecde12fb5b4711bc20702e
Christian Brabandt <cb@256bit.org>
parents:
8605
diff
changeset
|
2647 if (curtab == prevtab && curwin->w_width == Columns) |
7 | 2648 win_setheight(height); |
2649 curwin->w_p_wfh = TRUE; /* set 'winfixheight' */ | |
2650 if (win_valid(win)) | |
2651 prevwin = win; | |
2652 } | |
2653 | |
6793 | 2654 qf_set_title_var(qi); |
2655 | |
7 | 2656 /* |
2657 * Fill the buffer with the quickfix list. | |
2658 */ | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2659 qf_fill_buffer(qi, curbuf, NULL); |
644 | 2660 |
2661 curwin->w_cursor.lnum = qi->qf_lists[qi->qf_curlist].qf_index; | |
7 | 2662 curwin->w_cursor.col = 0; |
2663 check_cursor(); | |
2664 update_topline(); /* scroll to show the line */ | |
2665 } | |
2666 | |
2667 /* | |
2668 * Return the number of the current entry (line number in the quickfix | |
2669 * window). | |
2670 */ | |
2671 linenr_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2672 qf_current_entry(win_T *wp) |
7 | 2673 { |
644 | 2674 qf_info_T *qi = &ql_info; |
2675 | |
2676 if (IS_LL_WINDOW(wp)) | |
2677 /* In the location list window, use the referenced location list */ | |
2678 qi = wp->w_llist_ref; | |
2679 | |
2680 return qi->qf_lists[qi->qf_curlist].qf_index; | |
7 | 2681 } |
2682 | |
2683 /* | |
2684 * Update the cursor position in the quickfix window to the current error. | |
2685 * Return TRUE if there is a quickfix window. | |
2686 */ | |
2687 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2688 qf_win_pos_update( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2689 qf_info_T *qi, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2690 int old_qf_index) /* previous qf_index or zero */ |
7 | 2691 { |
2692 win_T *win; | |
644 | 2693 int qf_index = qi->qf_lists[qi->qf_curlist].qf_index; |
7 | 2694 |
2695 /* | |
2696 * Put the cursor on the current error in the quickfix window, so that | |
2697 * it's viewable. | |
2698 */ | |
644 | 2699 win = qf_find_win(qi); |
7 | 2700 if (win != NULL |
2701 && qf_index <= win->w_buffer->b_ml.ml_line_count | |
2702 && old_qf_index != qf_index) | |
2703 { | |
2704 win_T *old_curwin = curwin; | |
2705 | |
2706 curwin = win; | |
2707 curbuf = win->w_buffer; | |
2708 if (qf_index > old_qf_index) | |
2709 { | |
2710 curwin->w_redraw_top = old_qf_index; | |
2711 curwin->w_redraw_bot = qf_index; | |
2712 } | |
2713 else | |
2714 { | |
2715 curwin->w_redraw_top = qf_index; | |
2716 curwin->w_redraw_bot = old_qf_index; | |
2717 } | |
2718 curwin->w_cursor.lnum = qf_index; | |
2719 curwin->w_cursor.col = 0; | |
2720 update_topline(); /* scroll to show the line */ | |
2721 redraw_later(VALID); | |
2722 curwin->w_redr_status = TRUE; /* update ruler */ | |
2723 curwin = old_curwin; | |
2724 curbuf = curwin->w_buffer; | |
2725 } | |
2726 return win != NULL; | |
2727 } | |
2728 | |
2729 /* | |
859 | 2730 * Check whether the given window is displaying the specified quickfix/location |
2731 * list buffer | |
2732 */ | |
2733 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2734 is_qf_win(win_T *win, qf_info_T *qi) |
859 | 2735 { |
2736 /* | |
2737 * A window displaying the quickfix buffer will have the w_llist_ref field | |
2738 * set to NULL. | |
2739 * A window displaying a location list buffer will have the w_llist_ref | |
2740 * pointing to the location list. | |
2741 */ | |
2742 if (bt_quickfix(win->w_buffer)) | |
2743 if ((qi == &ql_info && win->w_llist_ref == NULL) | |
2744 || (qi != &ql_info && win->w_llist_ref == qi)) | |
2745 return TRUE; | |
2746 | |
2747 return FALSE; | |
2748 } | |
2749 | |
2750 /* | |
644 | 2751 * Find a window displaying the quickfix/location list 'qi' |
859 | 2752 * Searches in only the windows opened in the current tab. |
644 | 2753 */ |
2754 static win_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2755 qf_find_win(qf_info_T *qi) |
644 | 2756 { |
2757 win_T *win; | |
2758 | |
2759 FOR_ALL_WINDOWS(win) | |
859 | 2760 if (is_qf_win(win, qi)) |
2761 break; | |
644 | 2762 |
2763 return win; | |
2764 } | |
2765 | |
2766 /* | |
859 | 2767 * Find a quickfix buffer. |
2768 * Searches in windows opened in all the tabs. | |
7 | 2769 */ |
2770 static buf_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2771 qf_find_buf(qf_info_T *qi) |
7 | 2772 { |
859 | 2773 tabpage_T *tp; |
644 | 2774 win_T *win; |
2775 | |
859 | 2776 FOR_ALL_TAB_WINDOWS(tp, win) |
2777 if (is_qf_win(win, qi)) | |
2778 return win->w_buffer; | |
2779 | |
2780 return NULL; | |
7 | 2781 } |
2782 | |
2783 /* | |
2784 * Find the quickfix buffer. If it exists, update the contents. | |
2785 */ | |
2786 static void | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2787 qf_update_buffer(qf_info_T *qi, qfline_T *old_last) |
7 | 2788 { |
2789 buf_T *buf; | |
3016 | 2790 win_T *win; |
2791 win_T *curwin_save; | |
7 | 2792 aco_save_T aco; |
2793 | |
2794 /* Check if a buffer for the quickfix list exists. Update it. */ | |
644 | 2795 buf = qf_find_buf(qi); |
7 | 2796 if (buf != NULL) |
2797 { | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2798 linenr_T old_line_count = buf->b_ml.ml_line_count; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2799 |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2800 if (old_last == NULL) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2801 /* set curwin/curbuf to buf and save a few things */ |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2802 aucmd_prepbuf(&aco, buf); |
7 | 2803 |
6793 | 2804 if ((win = qf_find_win(qi)) != NULL) |
3016 | 2805 { |
2806 curwin_save = curwin; | |
2807 curwin = win; | |
6079 | 2808 qf_set_title_var(qi); |
3016 | 2809 curwin = curwin_save; |
2810 } | |
2811 | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2812 qf_fill_buffer(qi, buf, old_last); |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2813 |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2814 if (old_last == NULL) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2815 { |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
2816 (void)qf_win_pos_update(qi, 0); |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2817 |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2818 /* restore curwin/curbuf and a few other things */ |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2819 aucmd_restbuf(&aco); |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2820 } |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2821 |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2822 /* Only redraw when added lines are visible. This avoids flickering |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2823 * when the added lines are not visible. */ |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2824 if ((win = qf_find_win(qi)) != NULL && old_line_count < win->w_botline) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2825 redraw_buf_later(buf, NOT_VALID); |
7 | 2826 } |
2827 } | |
2828 | |
6793 | 2829 /* |
2830 * Set "w:quickfix_title" if "qi" has a title. | |
2831 */ | |
3016 | 2832 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2833 qf_set_title_var(qf_info_T *qi) |
3016 | 2834 { |
6793 | 2835 if (qi->qf_lists[qi->qf_curlist].qf_title != NULL) |
2836 set_internal_string_var((char_u *)"w:quickfix_title", | |
3016 | 2837 qi->qf_lists[qi->qf_curlist].qf_title); |
2838 } | |
2839 | |
7 | 2840 /* |
2841 * Fill current buffer with quickfix errors, replacing any previous contents. | |
2842 * curbuf must be the quickfix buffer! | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2843 * If "old_last" is not NULL append the items after this one. |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2844 * When "old_last" is NULL then "buf" must equal "curbuf"! Because |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2845 * ml_delete() is used and autocommands will be triggered. |
7 | 2846 */ |
2847 static void | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2848 qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last) |
7 | 2849 { |
230 | 2850 linenr_T lnum; |
2851 qfline_T *qfp; | |
2852 buf_T *errbuf; | |
2853 int len; | |
2854 int old_KeyTyped = KeyTyped; | |
7 | 2855 |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2856 if (old_last == NULL) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2857 { |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2858 if (buf != curbuf) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2859 { |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2860 EMSG2(_(e_intern2), "qf_fill_buffer()"); |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2861 return; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2862 } |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2863 |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2864 /* delete all existing lines */ |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2865 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2866 (void)ml_delete((linenr_T)1, FALSE); |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2867 } |
7 | 2868 |
2869 /* Check if there is anything to display */ | |
644 | 2870 if (qi->qf_curlist < qi->qf_listcount) |
7 | 2871 { |
2872 /* Add one line for each error */ | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2873 if (old_last == NULL) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2874 { |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2875 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2876 lnum = 0; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2877 } |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2878 else |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2879 { |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2880 qfp = old_last->qf_next; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2881 lnum = buf->b_ml.ml_line_count; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2882 } |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2883 while (lnum < qi->qf_lists[qi->qf_curlist].qf_count) |
7 | 2884 { |
2885 if (qfp->qf_fnum != 0 | |
2886 && (errbuf = buflist_findnr(qfp->qf_fnum)) != NULL | |
2887 && errbuf->b_fname != NULL) | |
2888 { | |
2889 if (qfp->qf_type == 1) /* :helpgrep */ | |
2890 STRCPY(IObuff, gettail(errbuf->b_fname)); | |
2891 else | |
2892 STRCPY(IObuff, errbuf->b_fname); | |
2893 len = (int)STRLEN(IObuff); | |
2894 } | |
2895 else | |
2896 len = 0; | |
2897 IObuff[len++] = '|'; | |
2898 | |
2899 if (qfp->qf_lnum > 0) | |
2900 { | |
2901 sprintf((char *)IObuff + len, "%ld", qfp->qf_lnum); | |
2902 len += (int)STRLEN(IObuff + len); | |
2903 | |
2904 if (qfp->qf_col > 0) | |
2905 { | |
2906 sprintf((char *)IObuff + len, " col %d", qfp->qf_col); | |
2907 len += (int)STRLEN(IObuff + len); | |
2908 } | |
2909 | |
2910 sprintf((char *)IObuff + len, "%s", | |
2911 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); | |
2912 len += (int)STRLEN(IObuff + len); | |
2913 } | |
230 | 2914 else if (qfp->qf_pattern != NULL) |
2915 { | |
2916 qf_fmt_text(qfp->qf_pattern, IObuff + len, IOSIZE - len); | |
2917 len += (int)STRLEN(IObuff + len); | |
2918 } | |
7 | 2919 IObuff[len++] = '|'; |
2920 IObuff[len++] = ' '; | |
2921 | |
2922 /* Remove newlines and leading whitespace from the text. | |
2923 * For an unrecognized line keep the indent, the compiler may | |
2924 * mark a word with ^^^^. */ | |
2925 qf_fmt_text(len > 3 ? skipwhite(qfp->qf_text) : qfp->qf_text, | |
2926 IObuff + len, IOSIZE - len); | |
2927 | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2928 if (ml_append_buf(buf, lnum, IObuff, |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2929 (colnr_T)STRLEN(IObuff) + 1, FALSE) == FAIL) |
7 | 2930 break; |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2931 ++lnum; |
7 | 2932 qfp = qfp->qf_next; |
2933 } | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2934 |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2935 if (old_last == NULL) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2936 /* Delete the empty line which is now at the end */ |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2937 (void)ml_delete(lnum + 1, FALSE); |
7 | 2938 } |
2939 | |
2940 /* correct cursor position */ | |
2941 check_lnums(TRUE); | |
2942 | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2943 if (old_last == NULL) |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2944 { |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2945 /* Set the 'filetype' to "qf" each time after filling the buffer. |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2946 * This resembles reading a file into a buffer, it's more logical when |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2947 * using autocommands. */ |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2948 set_option_value((char_u *)"ft", 0L, (char_u *)"qf", OPT_LOCAL); |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2949 curbuf->b_p_ma = FALSE; |
7 | 2950 |
2951 #ifdef FEAT_AUTOCMD | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2952 keep_filetype = TRUE; /* don't detect 'filetype' */ |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2953 apply_autocmds(EVENT_BUFREADPOST, (char_u *)"quickfix", NULL, |
7 | 2954 FALSE, curbuf); |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2955 apply_autocmds(EVENT_BUFWINENTER, (char_u *)"quickfix", NULL, |
7 | 2956 FALSE, curbuf); |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2957 keep_filetype = FALSE; |
7 | 2958 #endif |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2959 /* make sure it will be redrawn */ |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2960 redraw_curbuf_later(NOT_VALID); |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
2961 } |
7 | 2962 |
2963 /* Restore KeyTyped, setting 'filetype' may reset it. */ | |
2964 KeyTyped = old_KeyTyped; | |
2965 } | |
2966 | |
2967 #endif /* FEAT_WINDOWS */ | |
2968 | |
2969 /* | |
2970 * Return TRUE if "buf" is the quickfix buffer. | |
2971 */ | |
2972 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2973 bt_quickfix(buf_T *buf) |
7 | 2974 { |
3242 | 2975 return buf != NULL && buf->b_p_bt[0] == 'q'; |
7 | 2976 } |
2977 | |
2978 /* | |
17 | 2979 * Return TRUE if "buf" is a "nofile" or "acwrite" buffer. |
2980 * This means the buffer name is not a file name. | |
7 | 2981 */ |
2982 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2983 bt_nofile(buf_T *buf) |
7 | 2984 { |
3242 | 2985 return buf != NULL && ((buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f') |
2986 || buf->b_p_bt[0] == 'a'); | |
7 | 2987 } |
2988 | |
2989 /* | |
2990 * Return TRUE if "buf" is a "nowrite" or "nofile" buffer. | |
2991 */ | |
2992 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2993 bt_dontwrite(buf_T *buf) |
7 | 2994 { |
3242 | 2995 return buf != NULL && buf->b_p_bt[0] == 'n'; |
7 | 2996 } |
2997 | |
2998 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2999 bt_dontwrite_msg(buf_T *buf) |
7 | 3000 { |
3001 if (bt_dontwrite(buf)) | |
3002 { | |
3003 EMSG(_("E382: Cannot write, 'buftype' option is set")); | |
3004 return TRUE; | |
3005 } | |
3006 return FALSE; | |
3007 } | |
3008 | |
3009 /* | |
3010 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide" | |
3011 * and 'bufhidden'. | |
3012 */ | |
3013 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3014 buf_hide(buf_T *buf) |
7 | 3015 { |
3016 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */ | |
3017 switch (buf->b_p_bh[0]) | |
3018 { | |
3019 case 'u': /* "unload" */ | |
3020 case 'w': /* "wipe" */ | |
3021 case 'd': return FALSE; /* "delete" */ | |
3022 case 'h': return TRUE; /* "hide" */ | |
3023 } | |
3024 return (p_hid || cmdmod.hide); | |
3025 } | |
3026 | |
3027 /* | |
41 | 3028 * Return TRUE when using ":vimgrep" for ":grep". |
3029 */ | |
3030 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3031 grep_internal(cmdidx_T cmdidx) |
41 | 3032 { |
661 | 3033 return ((cmdidx == CMD_grep |
3034 || cmdidx == CMD_lgrep | |
3035 || cmdidx == CMD_grepadd | |
3036 || cmdidx == CMD_lgrepadd) | |
41 | 3037 && STRCMP("internal", |
3038 *curbuf->b_p_gp == NUL ? p_gp : curbuf->b_p_gp) == 0); | |
3039 } | |
3040 | |
3041 /* | |
657 | 3042 * Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd" |
7 | 3043 */ |
3044 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3045 ex_make(exarg_T *eap) |
7 | 3046 { |
161 | 3047 char_u *fname; |
7 | 3048 char_u *cmd; |
3049 unsigned len; | |
657 | 3050 win_T *wp = NULL; |
659 | 3051 qf_info_T *qi = &ql_info; |
842 | 3052 int res; |
161 | 3053 #ifdef FEAT_AUTOCMD |
3054 char_u *au_name = NULL; | |
3055 | |
2782 | 3056 /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */ |
3057 if (grep_internal(eap->cmdidx)) | |
3058 { | |
3059 ex_vimgrep(eap); | |
3060 return; | |
3061 } | |
3062 | |
161 | 3063 switch (eap->cmdidx) |
3064 { | |
661 | 3065 case CMD_make: au_name = (char_u *)"make"; break; |
3066 case CMD_lmake: au_name = (char_u *)"lmake"; break; | |
3067 case CMD_grep: au_name = (char_u *)"grep"; break; | |
3068 case CMD_lgrep: au_name = (char_u *)"lgrep"; break; | |
3069 case CMD_grepadd: au_name = (char_u *)"grepadd"; break; | |
3070 case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break; | |
161 | 3071 default: break; |
3072 } | |
3073 if (au_name != NULL) | |
3074 { | |
3075 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
3076 curbuf->b_fname, TRUE, curbuf); | |
532 | 3077 # ifdef FEAT_EVAL |
161 | 3078 if (did_throw || force_abort) |
3079 return; | |
532 | 3080 # endif |
161 | 3081 } |
3082 #endif | |
7 | 3083 |
657 | 3084 if (eap->cmdidx == CMD_lmake || eap->cmdidx == CMD_lgrep |
3085 || eap->cmdidx == CMD_lgrepadd) | |
3086 wp = curwin; | |
3087 | |
7 | 3088 autowrite_all(); |
161 | 3089 fname = get_mef_name(); |
3090 if (fname == NULL) | |
7 | 3091 return; |
161 | 3092 mch_remove(fname); /* in case it's not unique */ |
7 | 3093 |
3094 /* | |
3095 * If 'shellpipe' empty: don't redirect to 'errorfile'. | |
3096 */ | |
3097 len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1; | |
3098 if (*p_sp != NUL) | |
161 | 3099 len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3; |
7 | 3100 cmd = alloc(len); |
3101 if (cmd == NULL) | |
3102 return; | |
3103 sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg, | |
3104 (char *)p_shq); | |
3105 if (*p_sp != NUL) | |
1872 | 3106 append_redir(cmd, len, p_sp, fname); |
7 | 3107 /* |
3108 * Output a newline if there's something else than the :make command that | |
3109 * was typed (in which case the cursor is in column 0). | |
3110 */ | |
3111 if (msg_col == 0) | |
3112 msg_didout = FALSE; | |
3113 msg_start(); | |
3114 MSG_PUTS(":!"); | |
3115 msg_outtrans(cmd); /* show what we are doing */ | |
3116 | |
3117 /* let the shell know if we are redirecting output or not */ | |
3118 do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0); | |
3119 | |
3120 #ifdef AMIGA | |
3121 out_flush(); | |
3122 /* read window status report and redraw before message */ | |
3123 (void)char_avail(); | |
3124 #endif | |
3125 | |
842 | 3126 res = qf_init(wp, fname, (eap->cmdidx != CMD_make |
657 | 3127 && eap->cmdidx != CMD_lmake) ? p_gefm : p_efm, |
3128 (eap->cmdidx != CMD_grepadd | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3129 && eap->cmdidx != CMD_lgrepadd), |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3130 *eap->cmdlinep); |
2847 | 3131 if (wp != NULL) |
3132 qi = GET_LOC_LIST(wp); | |
842 | 3133 #ifdef FEAT_AUTOCMD |
3134 if (au_name != NULL) | |
2847 | 3135 { |
842 | 3136 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, |
3137 curbuf->b_fname, TRUE, curbuf); | |
2847 | 3138 if (qi->qf_curlist < qi->qf_listcount) |
3139 res = qi->qf_lists[qi->qf_curlist].qf_count; | |
3140 else | |
3141 res = 0; | |
3142 } | |
842 | 3143 #endif |
3144 if (res > 0 && !eap->forceit) | |
659 | 3145 qf_jump(qi, 0, 0, FALSE); /* display first error */ |
7 | 3146 |
161 | 3147 mch_remove(fname); |
3148 vim_free(fname); | |
7 | 3149 vim_free(cmd); |
3150 } | |
3151 | |
3152 /* | |
3153 * Return the name for the errorfile, in allocated memory. | |
3154 * Find a new unique name when 'makeef' contains "##". | |
3155 * Returns NULL for error. | |
3156 */ | |
3157 static char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3158 get_mef_name(void) |
7 | 3159 { |
3160 char_u *p; | |
3161 char_u *name; | |
3162 static int start = -1; | |
3163 static int off = 0; | |
3164 #ifdef HAVE_LSTAT | |
3165 struct stat sb; | |
3166 #endif | |
3167 | |
3168 if (*p_mef == NUL) | |
3169 { | |
6721 | 3170 name = vim_tempname('e', FALSE); |
7 | 3171 if (name == NULL) |
3172 EMSG(_(e_notmp)); | |
3173 return name; | |
3174 } | |
3175 | |
3176 for (p = p_mef; *p; ++p) | |
3177 if (p[0] == '#' && p[1] == '#') | |
3178 break; | |
3179 | |
3180 if (*p == NUL) | |
3181 return vim_strsave(p_mef); | |
3182 | |
3183 /* Keep trying until the name doesn't exist yet. */ | |
3184 for (;;) | |
3185 { | |
3186 if (start == -1) | |
3187 start = mch_get_pid(); | |
3188 else | |
3189 off += 19; | |
3190 | |
3191 name = alloc((unsigned)STRLEN(p_mef) + 30); | |
3192 if (name == NULL) | |
3193 break; | |
3194 STRCPY(name, p_mef); | |
3195 sprintf((char *)name + (p - p_mef), "%d%d", start, off); | |
3196 STRCAT(name, p + 2); | |
3197 if (mch_getperm(name) < 0 | |
3198 #ifdef HAVE_LSTAT | |
3199 /* Don't accept a symbolic link, its a security risk. */ | |
3200 && mch_lstat((char *)name, &sb) < 0 | |
3201 #endif | |
3202 ) | |
3203 break; | |
3204 vim_free(name); | |
3205 } | |
3206 return name; | |
3207 } | |
3208 | |
3209 /* | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3210 * Returns the number of valid entries in the current quickfix/location list. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3211 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3212 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3213 qf_get_size(exarg_T *eap) |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3214 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3215 qf_info_T *qi = &ql_info; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3216 qfline_T *qfp; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3217 int i, sz = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3218 int prev_fnum = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3219 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3220 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3221 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3222 /* Location list */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3223 qi = GET_LOC_LIST(curwin); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3224 if (qi == NULL) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3225 return 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3226 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3227 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3228 for (i = 0, qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3229 (i < qi->qf_lists[qi->qf_curlist].qf_count) && (qfp != NULL); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3230 ++i, qfp = qfp->qf_next) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3231 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3232 if (qfp->qf_valid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3233 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3234 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3235 sz++; /* Count all valid entries */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3236 else if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3237 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3238 /* Count the number of files */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3239 sz++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3240 prev_fnum = qfp->qf_fnum; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3241 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3242 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3243 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3244 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3245 return sz; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3246 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3247 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3248 /* |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3249 * Returns the current index of the quickfix/location list. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3250 * Returns 0 if there is an error. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3251 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3252 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3253 qf_get_cur_idx(exarg_T *eap) |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3254 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3255 qf_info_T *qi = &ql_info; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3256 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3257 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3258 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3259 /* Location list */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3260 qi = GET_LOC_LIST(curwin); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3261 if (qi == NULL) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3262 return 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3263 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3264 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3265 return qi->qf_lists[qi->qf_curlist].qf_index; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3266 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3267 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3268 /* |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3269 * Returns the current index in the quickfix/location list (counting only valid |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3270 * entries). If no valid entries are in the list, then returns 1. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3271 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3272 int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3273 qf_get_cur_valid_idx(exarg_T *eap) |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3274 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3275 qf_info_T *qi = &ql_info; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3276 qf_list_T *qfl; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3277 qfline_T *qfp; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3278 int i, eidx = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3279 int prev_fnum = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3280 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3281 if (eap->cmdidx == CMD_ldo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3282 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3283 /* Location list */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3284 qi = GET_LOC_LIST(curwin); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3285 if (qi == NULL) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3286 return 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3287 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3288 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3289 qfl = &qi->qf_lists[qi->qf_curlist]; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3290 qfp = qfl->qf_start; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3291 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3292 /* check if the list has valid errors */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3293 if (qfl->qf_count <= 0 || qfl->qf_nonevalid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3294 return 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3295 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3296 for (i = 1; i <= qfl->qf_index && qfp!= NULL; i++, qfp = qfp->qf_next) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3297 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3298 if (qfp->qf_valid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3299 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3300 if (eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3301 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3302 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3303 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3304 /* Count the number of files */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3305 eidx++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3306 prev_fnum = qfp->qf_fnum; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3307 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3308 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3309 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3310 eidx++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3311 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3312 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3313 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3314 return eidx ? eidx : 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3315 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3316 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3317 /* |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3318 * Get the 'n'th valid error entry in the quickfix or location list. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3319 * Used by :cdo, :ldo, :cfdo and :lfdo commands. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3320 * For :cdo and :ldo returns the 'n'th valid error entry. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3321 * For :cfdo and :lfdo returns the 'n'th valid file entry. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3322 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3323 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3324 qf_get_nth_valid_entry(qf_info_T *qi, int n, int fdo) |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3325 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3326 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist]; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3327 qfline_T *qfp = qfl->qf_start; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3328 int i, eidx; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3329 int prev_fnum = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3330 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3331 /* check if the list has valid errors */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3332 if (qfl->qf_count <= 0 || qfl->qf_nonevalid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3333 return 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3334 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3335 for (i = 1, eidx = 0; i <= qfl->qf_count && qfp!= NULL; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3336 i++, qfp = qfp->qf_next) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3337 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3338 if (qfp->qf_valid) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3339 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3340 if (fdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3341 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3342 if (qfp->qf_fnum > 0 && qfp->qf_fnum != prev_fnum) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3343 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3344 /* Count the number of files */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3345 eidx++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3346 prev_fnum = qfp->qf_fnum; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3347 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3348 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3349 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3350 eidx++; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3351 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3352 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3353 if (eidx == n) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3354 break; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3355 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3356 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3357 if (i <= qfl->qf_count) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3358 return i; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3359 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3360 return 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3361 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3362 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3363 /* |
7 | 3364 * ":cc", ":crewind", ":cfirst" and ":clast". |
644 | 3365 * ":ll", ":lrewind", ":lfirst" and ":llast". |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3366 * ":cdo", ":ldo", ":cfdo" and ":lfdo" |
7 | 3367 */ |
3368 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3369 ex_cc(exarg_T *eap) |
7 | 3370 { |
659 | 3371 qf_info_T *qi = &ql_info; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3372 int errornr; |
659 | 3373 |
3374 if (eap->cmdidx == CMD_ll | |
3375 || eap->cmdidx == CMD_lrewind | |
3376 || eap->cmdidx == CMD_lfirst | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3377 || eap->cmdidx == CMD_llast |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3378 || eap->cmdidx == CMD_ldo |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3379 || eap->cmdidx == CMD_lfdo) |
644 | 3380 { |
3381 qi = GET_LOC_LIST(curwin); | |
3382 if (qi == NULL) | |
3383 { | |
3384 EMSG(_(e_loclist)); | |
3385 return; | |
3386 } | |
3387 } | |
3388 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3389 if (eap->addr_count > 0) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3390 errornr = (int)eap->line2; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3391 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3392 { |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3393 if (eap->cmdidx == CMD_cc || eap->cmdidx == CMD_ll) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3394 errornr = 0; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3395 else if (eap->cmdidx == CMD_crewind || eap->cmdidx == CMD_lrewind |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3396 || eap->cmdidx == CMD_cfirst || eap->cmdidx == CMD_lfirst) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3397 errornr = 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3398 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3399 errornr = 32767; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3400 } |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3401 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3402 /* For cdo and ldo commands, jump to the nth valid error. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3403 * For cfdo and lfdo commands, jump to the nth valid file entry. |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3404 */ |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3405 if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo || |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3406 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3407 errornr = qf_get_nth_valid_entry(qi, |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3408 eap->addr_count > 0 ? (int)eap->line1 : 1, |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3409 eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo); |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3410 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3411 qf_jump(qi, 0, errornr, eap->forceit); |
7 | 3412 } |
3413 | |
3414 /* | |
3415 * ":cnext", ":cnfile", ":cNext" and ":cprevious". | |
644 | 3416 * ":lnext", ":lNext", ":lprevious", ":lnfile", ":lNfile" and ":lpfile". |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3417 * Also, used by ":cdo", ":ldo", ":cfdo" and ":lfdo" commands. |
7 | 3418 */ |
3419 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3420 ex_cnext(exarg_T *eap) |
7 | 3421 { |
659 | 3422 qf_info_T *qi = &ql_info; |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3423 int errornr; |
659 | 3424 |
3425 if (eap->cmdidx == CMD_lnext | |
3426 || eap->cmdidx == CMD_lNext | |
3427 || eap->cmdidx == CMD_lprevious | |
3428 || eap->cmdidx == CMD_lnfile | |
3429 || eap->cmdidx == CMD_lNfile | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3430 || eap->cmdidx == CMD_lpfile |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3431 || eap->cmdidx == CMD_ldo |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3432 || eap->cmdidx == CMD_lfdo) |
644 | 3433 { |
3434 qi = GET_LOC_LIST(curwin); | |
3435 if (qi == NULL) | |
3436 { | |
3437 EMSG(_(e_loclist)); | |
3438 return; | |
3439 } | |
3440 } | |
3441 | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3442 if (eap->addr_count > 0 && |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3443 (eap->cmdidx != CMD_cdo && eap->cmdidx != CMD_ldo && |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3444 eap->cmdidx != CMD_cfdo && eap->cmdidx != CMD_lfdo)) |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3445 errornr = (int)eap->line2; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3446 else |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3447 errornr = 1; |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3448 |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3449 qf_jump(qi, (eap->cmdidx == CMD_cnext || eap->cmdidx == CMD_lnext |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3450 || eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo) |
7 | 3451 ? FORWARD |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3452 : (eap->cmdidx == CMD_cnfile || eap->cmdidx == CMD_lnfile |
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3453 || eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo) |
7 | 3454 ? FORWARD_FILE |
644 | 3455 : (eap->cmdidx == CMD_cpfile || eap->cmdidx == CMD_lpfile |
3456 || eap->cmdidx == CMD_cNfile || eap->cmdidx == CMD_lNfile) | |
7 | 3457 ? BACKWARD_FILE |
3458 : BACKWARD, | |
7092
64e30831fa42
commit https://github.com/vim/vim/commit/aa23b379421aa214e6543b06c974594a25799b09
Christian Brabandt <cb@256bit.org>
parents:
6853
diff
changeset
|
3459 errornr, eap->forceit); |
7 | 3460 } |
3461 | |
3462 /* | |
446 | 3463 * ":cfile"/":cgetfile"/":caddfile" commands. |
644 | 3464 * ":lfile"/":lgetfile"/":laddfile" commands. |
7 | 3465 */ |
3466 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3467 ex_cfile(exarg_T *eap) |
7 | 3468 { |
644 | 3469 win_T *wp = NULL; |
659 | 3470 qf_info_T *qi = &ql_info; |
3404 | 3471 #ifdef FEAT_AUTOCMD |
3472 char_u *au_name = NULL; | |
3473 #endif | |
644 | 3474 |
3475 if (eap->cmdidx == CMD_lfile || eap->cmdidx == CMD_lgetfile | |
3404 | 3476 || eap->cmdidx == CMD_laddfile) |
644 | 3477 wp = curwin; |
3478 | |
3404 | 3479 #ifdef FEAT_AUTOCMD |
3480 switch (eap->cmdidx) | |
3481 { | |
3482 case CMD_cfile: au_name = (char_u *)"cfile"; break; | |
3483 case CMD_cgetfile: au_name = (char_u *)"cgetfile"; break; | |
3484 case CMD_caddfile: au_name = (char_u *)"caddfile"; break; | |
3485 case CMD_lfile: au_name = (char_u *)"lfile"; break; | |
3486 case CMD_lgetfile: au_name = (char_u *)"lgetfile"; break; | |
3487 case CMD_laddfile: au_name = (char_u *)"laddfile"; break; | |
3488 default: break; | |
3489 } | |
3490 if (au_name != NULL) | |
3491 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, NULL, FALSE, curbuf); | |
3492 #endif | |
2296
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3493 #ifdef FEAT_BROWSE |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3494 if (cmdmod.browse) |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3495 { |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3496 char_u *browse_file = do_browse(0, (char_u *)_("Error file"), eap->arg, |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3497 NULL, NULL, BROWSE_FILTER_ALL_FILES, NULL); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3498 if (browse_file == NULL) |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3499 return; |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3500 set_string_option_direct((char_u *)"ef", -1, browse_file, OPT_FREE, 0); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3501 vim_free(browse_file); |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3502 } |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3503 else |
eb7be7b075a6
Support :browse for commands that use an error file argument. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2146
diff
changeset
|
3504 #endif |
7 | 3505 if (*eap->arg != NUL) |
694 | 3506 set_string_option_direct((char_u *)"ef", -1, eap->arg, OPT_FREE, 0); |
446 | 3507 |
3508 /* | |
3509 * This function is used by the :cfile, :cgetfile and :caddfile | |
3510 * commands. | |
3511 * :cfile always creates a new quickfix list and jumps to the | |
3512 * first error. | |
3513 * :cgetfile creates a new quickfix list but doesn't jump to the | |
3514 * first error. | |
3515 * :caddfile adds to an existing quickfix list. If there is no | |
3516 * quickfix list then a new list is created. | |
3517 */ | |
644 | 3518 if (qf_init(wp, p_ef, p_efm, (eap->cmdidx != CMD_caddfile |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3519 && eap->cmdidx != CMD_laddfile), |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
3520 *eap->cmdlinep) > 0 |
644 | 3521 && (eap->cmdidx == CMD_cfile |
3522 || eap->cmdidx == CMD_lfile)) | |
665 | 3523 { |
3404 | 3524 #ifdef FEAT_AUTOCMD |
3525 if (au_name != NULL) | |
3526 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf); | |
3527 #endif | |
665 | 3528 if (wp != NULL) |
3529 qi = GET_LOC_LIST(wp); | |
659 | 3530 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
665 | 3531 } |
3404 | 3532 |
3533 else | |
3534 { | |
3535 #ifdef FEAT_AUTOCMD | |
3536 if (au_name != NULL) | |
3537 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf); | |
3538 #endif | |
3539 } | |
7 | 3540 } |
3541 | |
3542 /* | |
41 | 3543 * ":vimgrep {pattern} file(s)" |
657 | 3544 * ":vimgrepadd {pattern} file(s)" |
3545 * ":lvimgrep {pattern} file(s)" | |
3546 * ":lvimgrepadd {pattern} file(s)" | |
41 | 3547 */ |
3548 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3549 ex_vimgrep(exarg_T *eap) |
41 | 3550 { |
42 | 3551 regmmatch_T regmatch; |
153 | 3552 int fcount; |
41 | 3553 char_u **fnames; |
1411 | 3554 char_u *fname; |
8603
bfa74b84c41c
commit https://github.com/vim/vim/commit/5584df65a0ca2315d1eebc13c54a448bee4d0758
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
3555 char_u *title; |
153 | 3556 char_u *s; |
3557 char_u *p; | |
3558 int fi; | |
657 | 3559 qf_info_T *qi = &ql_info; |
4003 | 3560 #ifdef FEAT_AUTOCMD |
3561 qfline_T *cur_qf_start; | |
3562 #endif | |
230 | 3563 qfline_T *prevp = NULL; |
41 | 3564 long lnum; |
42 | 3565 buf_T *buf; |
3566 int duplicate_name = FALSE; | |
3567 int using_dummy; | |
1396 | 3568 int redraw_for_dummy = FALSE; |
42 | 3569 int found_match; |
123 | 3570 buf_T *first_match_buf = NULL; |
3571 time_t seconds = 0; | |
677 | 3572 int save_mls; |
123 | 3573 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
3574 char_u *save_ei = NULL; | |
677 | 3575 #endif |
123 | 3576 aco_save_T aco; |
170 | 3577 int flags = 0; |
3578 colnr_T col; | |
716 | 3579 long tomatch; |
2770 | 3580 char_u *dirname_start = NULL; |
3581 char_u *dirname_now = NULL; | |
1411 | 3582 char_u *target_dir = NULL; |
1683 | 3583 #ifdef FEAT_AUTOCMD |
3584 char_u *au_name = NULL; | |
161 | 3585 |
3586 switch (eap->cmdidx) | |
3587 { | |
2782 | 3588 case CMD_vimgrep: au_name = (char_u *)"vimgrep"; break; |
3589 case CMD_lvimgrep: au_name = (char_u *)"lvimgrep"; break; | |
3590 case CMD_vimgrepadd: au_name = (char_u *)"vimgrepadd"; break; | |
657 | 3591 case CMD_lvimgrepadd: au_name = (char_u *)"lvimgrepadd"; break; |
2782 | 3592 case CMD_grep: au_name = (char_u *)"grep"; break; |
3593 case CMD_lgrep: au_name = (char_u *)"lgrep"; break; | |
3594 case CMD_grepadd: au_name = (char_u *)"grepadd"; break; | |
3595 case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break; | |
161 | 3596 default: break; |
3597 } | |
3598 if (au_name != NULL) | |
3599 { | |
3600 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
3601 curbuf->b_fname, TRUE, curbuf); | |
3602 if (did_throw || force_abort) | |
3603 return; | |
3604 } | |
3605 #endif | |
41 | 3606 |
661 | 3607 if (eap->cmdidx == CMD_lgrep |
659 | 3608 || eap->cmdidx == CMD_lvimgrep |
3609 || eap->cmdidx == CMD_lgrepadd | |
3610 || eap->cmdidx == CMD_lvimgrepadd) | |
657 | 3611 { |
3612 qi = ll_get_or_alloc_list(curwin); | |
3613 if (qi == NULL) | |
3614 return; | |
3615 } | |
3616 | |
716 | 3617 if (eap->addr_count > 0) |
3618 tomatch = eap->line2; | |
3619 else | |
3620 tomatch = MAXLNUM; | |
3621 | |
42 | 3622 /* Get the search pattern: either white-separated or enclosed in // */ |
41 | 3623 regmatch.regprog = NULL; |
8603
bfa74b84c41c
commit https://github.com/vim/vim/commit/5584df65a0ca2315d1eebc13c54a448bee4d0758
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
3624 title = vim_strsave(*eap->cmdlinep); |
170 | 3625 p = skip_vimgrep_pat(eap->arg, &s, &flags); |
153 | 3626 if (p == NULL) |
41 | 3627 { |
282 | 3628 EMSG(_(e_invalpat)); |
153 | 3629 goto theend; |
41 | 3630 } |
4197 | 3631 |
3632 if (s != NULL && *s == NUL) | |
3633 { | |
3634 /* Pattern is empty, use last search pattern. */ | |
3635 if (last_search_pat() == NULL) | |
3636 { | |
3637 EMSG(_(e_noprevre)); | |
3638 goto theend; | |
3639 } | |
3640 regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); | |
3641 } | |
3642 else | |
3643 regmatch.regprog = vim_regcomp(s, RE_MAGIC); | |
3644 | |
41 | 3645 if (regmatch.regprog == NULL) |
3646 goto theend; | |
95 | 3647 regmatch.rmm_ic = p_ic; |
410 | 3648 regmatch.rmm_maxcol = 0; |
41 | 3649 |
3650 p = skipwhite(p); | |
3651 if (*p == NUL) | |
3652 { | |
3653 EMSG(_("E683: File name missing or invalid pattern")); | |
3654 goto theend; | |
3655 } | |
3656 | |
661 | 3657 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd && |
657 | 3658 eap->cmdidx != CMD_vimgrepadd && eap->cmdidx != CMD_lvimgrepadd) |
644 | 3659 || qi->qf_curlist == qi->qf_listcount) |
41 | 3660 /* make place for a new list */ |
8603
bfa74b84c41c
commit https://github.com/vim/vim/commit/5584df65a0ca2315d1eebc13c54a448bee4d0758
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
3661 qf_new_list(qi, title != NULL ? title : *eap->cmdlinep); |
644 | 3662 else if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
41 | 3663 /* Adding to existing list, find last entry. */ |
644 | 3664 for (prevp = qi->qf_lists[qi->qf_curlist].qf_start; |
41 | 3665 prevp->qf_next != prevp; prevp = prevp->qf_next) |
3666 ; | |
3667 | |
3668 /* parse the list of arguments */ | |
3620 | 3669 if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL) |
41 | 3670 goto theend; |
3671 if (fcount == 0) | |
3672 { | |
3673 EMSG(_(e_nomatch)); | |
3674 goto theend; | |
3675 } | |
3676 | |
7558
9a4c9dccd603
commit https://github.com/vim/vim/commit/b86a343280b08d6701da68ee0651e960a0a7a61c
Christian Brabandt <cb@256bit.org>
parents:
7515
diff
changeset
|
3677 dirname_start = alloc_id(MAXPATHL, aid_qf_dirname_start); |
9a4c9dccd603
commit https://github.com/vim/vim/commit/b86a343280b08d6701da68ee0651e960a0a7a61c
Christian Brabandt <cb@256bit.org>
parents:
7515
diff
changeset
|
3678 dirname_now = alloc_id(MAXPATHL, aid_qf_dirname_now); |
2770 | 3679 if (dirname_start == NULL || dirname_now == NULL) |
7662
4d34891e98f4
commit https://github.com/vim/vim/commit/61ff4dd6a4d47bd32383fe28087be2b37dec53f4
Christian Brabandt <cb@256bit.org>
parents:
7558
diff
changeset
|
3680 { |
4d34891e98f4
commit https://github.com/vim/vim/commit/61ff4dd6a4d47bd32383fe28087be2b37dec53f4
Christian Brabandt <cb@256bit.org>
parents:
7558
diff
changeset
|
3681 FreeWild(fcount, fnames); |
2770 | 3682 goto theend; |
7662
4d34891e98f4
commit https://github.com/vim/vim/commit/61ff4dd6a4d47bd32383fe28087be2b37dec53f4
Christian Brabandt <cb@256bit.org>
parents:
7558
diff
changeset
|
3683 } |
2770 | 3684 |
1411 | 3685 /* Remember the current directory, because a BufRead autocommand that does |
3686 * ":lcd %:p:h" changes the meaning of short path names. */ | |
3687 mch_dirname(dirname_start, MAXPATHL); | |
3688 | |
4003 | 3689 #ifdef FEAT_AUTOCMD |
4352 | 3690 /* Remember the value of qf_start, so that we can check for autocommands |
4003 | 3691 * changing the current quickfix list. */ |
3692 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3693 #endif | |
3694 | |
123 | 3695 seconds = (time_t)0; |
716 | 3696 for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) |
41 | 3697 { |
1411 | 3698 fname = shorten_fname1(fnames[fi]); |
123 | 3699 if (time(NULL) > seconds) |
3700 { | |
1411 | 3701 /* Display the file name every second or so, show the user we are |
3702 * working on it. */ | |
123 | 3703 seconds = time(NULL); |
3704 msg_start(); | |
1411 | 3705 p = msg_strtrunc(fname, TRUE); |
123 | 3706 if (p == NULL) |
1411 | 3707 msg_outtrans(fname); |
123 | 3708 else |
3709 { | |
3710 msg_outtrans(p); | |
3711 vim_free(p); | |
3712 } | |
3713 msg_clr_eos(); | |
3714 msg_didout = FALSE; /* overwrite this message */ | |
3715 msg_nowait = TRUE; /* don't wait for this message */ | |
3716 msg_col = 0; | |
3717 out_flush(); | |
3718 } | |
3719 | |
42 | 3720 buf = buflist_findname_exp(fnames[fi]); |
3721 if (buf == NULL || buf->b_ml.ml_mfp == NULL) | |
3722 { | |
3723 /* Remember that a buffer with this name already exists. */ | |
3724 duplicate_name = (buf != NULL); | |
123 | 3725 using_dummy = TRUE; |
1396 | 3726 redraw_for_dummy = TRUE; |
123 | 3727 |
3728 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) | |
3729 /* Don't do Filetype autocommands to avoid loading syntax and | |
3730 * indent scripts, a great speed improvement. */ | |
3731 save_ei = au_event_disable(",Filetype"); | |
3732 #endif | |
677 | 3733 /* Don't use modelines here, it's useless. */ |
3734 save_mls = p_mls; | |
3735 p_mls = 0; | |
42 | 3736 |
3737 /* Load file into a buffer, so that 'fileencoding' is detected, | |
3738 * autocommands applied, etc. */ | |
3490 | 3739 buf = load_dummy_buffer(fname, dirname_start, dirname_now); |
123 | 3740 |
677 | 3741 p_mls = save_mls; |
123 | 3742 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
3743 au_event_restore(save_ei); | |
3744 #endif | |
42 | 3745 } |
3746 else | |
3747 /* Use existing, loaded buffer. */ | |
3748 using_dummy = FALSE; | |
123 | 3749 |
4003 | 3750 #ifdef FEAT_AUTOCMD |
3751 if (cur_qf_start != qi->qf_lists[qi->qf_curlist].qf_start) | |
3752 { | |
3753 int idx; | |
3754 | |
3755 /* Autocommands changed the quickfix list. Find the one we were | |
3756 * using and restore it. */ | |
3757 for (idx = 0; idx < LISTCOUNT; ++idx) | |
3758 if (cur_qf_start == qi->qf_lists[idx].qf_start) | |
3759 { | |
3760 qi->qf_curlist = idx; | |
3761 break; | |
3762 } | |
3763 if (idx == LISTCOUNT) | |
3764 { | |
3765 /* List cannot be found, create a new one. */ | |
3766 qf_new_list(qi, *eap->cmdlinep); | |
3767 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3768 } | |
3769 } | |
3770 #endif | |
3771 | |
42 | 3772 if (buf == NULL) |
123 | 3773 { |
3774 if (!got_int) | |
1411 | 3775 smsg((char_u *)_("Cannot open file \"%s\""), fname); |
123 | 3776 } |
41 | 3777 else |
3778 { | |
717 | 3779 /* Try for a match in all lines of the buffer. |
3780 * For ":1vimgrep" look for first match only. */ | |
42 | 3781 found_match = FALSE; |
716 | 3782 for (lnum = 1; lnum <= buf->b_ml.ml_line_count && tomatch > 0; |
3783 ++lnum) | |
41 | 3784 { |
170 | 3785 col = 0; |
3786 while (vim_regexec_multi(®match, curwin, buf, lnum, | |
1521 | 3787 col, NULL) > 0) |
41 | 3788 { |
1411 | 3789 ; |
644 | 3790 if (qf_add_entry(qi, &prevp, |
41 | 3791 NULL, /* dir */ |
1411 | 3792 fname, |
1065 | 3793 0, |
42 | 3794 ml_get_buf(buf, |
3795 regmatch.startpos[0].lnum + lnum, FALSE), | |
3796 regmatch.startpos[0].lnum + lnum, | |
3797 regmatch.startpos[0].col + 1, | |
170 | 3798 FALSE, /* vis_col */ |
230 | 3799 NULL, /* search pattern */ |
856 | 3800 0, /* nr */ |
3801 0, /* type */ | |
3802 TRUE /* valid */ | |
41 | 3803 ) == FAIL) |
3804 { | |
3805 got_int = TRUE; | |
3806 break; | |
3807 } | |
716 | 3808 found_match = TRUE; |
3809 if (--tomatch == 0) | |
3810 break; | |
170 | 3811 if ((flags & VGR_GLOBAL) == 0 |
3812 || regmatch.endpos[0].lnum > 0) | |
3813 break; | |
3814 col = regmatch.endpos[0].col | |
3815 + (col == regmatch.endpos[0].col); | |
1883 | 3816 if (col > (colnr_T)STRLEN(ml_get_buf(buf, lnum, FALSE))) |
170 | 3817 break; |
41 | 3818 } |
3819 line_breakcheck(); | |
42 | 3820 if (got_int) |
3821 break; | |
41 | 3822 } |
4003 | 3823 #ifdef FEAT_AUTOCMD |
3824 cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start; | |
3825 #endif | |
42 | 3826 |
3827 if (using_dummy) | |
3828 { | |
123 | 3829 if (found_match && first_match_buf == NULL) |
3830 first_match_buf = buf; | |
42 | 3831 if (duplicate_name) |
123 | 3832 { |
42 | 3833 /* Never keep a dummy buffer if there is another buffer |
3834 * with the same name. */ | |
3490 | 3835 wipe_dummy_buffer(buf, dirname_start); |
123 | 3836 buf = NULL; |
3837 } | |
717 | 3838 else if (!cmdmod.hide |
3839 || buf->b_p_bh[0] == 'u' /* "unload" */ | |
3840 || buf->b_p_bh[0] == 'w' /* "wipe" */ | |
3841 || buf->b_p_bh[0] == 'd') /* "delete" */ | |
42 | 3842 { |
717 | 3843 /* When no match was found we don't need to remember the |
3844 * buffer, wipe it out. If there was a match and it | |
3845 * wasn't the first one or we won't jump there: only | |
3846 * unload the buffer. | |
3847 * Ignore 'hidden' here, because it may lead to having too | |
3848 * many swap files. */ | |
42 | 3849 if (!found_match) |
123 | 3850 { |
3490 | 3851 wipe_dummy_buffer(buf, dirname_start); |
123 | 3852 buf = NULL; |
3853 } | |
170 | 3854 else if (buf != first_match_buf || (flags & VGR_NOJUMP)) |
123 | 3855 { |
3490 | 3856 unload_dummy_buffer(buf, dirname_start); |
123 | 3857 buf = NULL; |
3858 } | |
42 | 3859 } |
123 | 3860 |
3861 if (buf != NULL) | |
3862 { | |
1411 | 3863 /* If the buffer is still loaded we need to use the |
3864 * directory we jumped to below. */ | |
3865 if (buf == first_match_buf | |
3866 && target_dir == NULL | |
3867 && STRCMP(dirname_start, dirname_now) != 0) | |
3868 target_dir = vim_strsave(dirname_now); | |
3869 | |
123 | 3870 /* The buffer is still loaded, the Filetype autocommands |
677 | 3871 * need to be done now, in that buffer. And the modelines |
717 | 3872 * need to be done (again). But not the window-local |
3873 * options! */ | |
123 | 3874 aucmd_prepbuf(&aco, buf); |
677 | 3875 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL) |
123 | 3876 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, |
3877 buf->b_fname, TRUE, buf); | |
677 | 3878 #endif |
717 | 3879 do_modelines(OPT_NOWIN); |
123 | 3880 aucmd_restbuf(&aco); |
3881 } | |
42 | 3882 } |
41 | 3883 } |
3884 } | |
3885 | |
3886 FreeWild(fcount, fnames); | |
3887 | |
644 | 3888 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
3889 qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start; | |
3890 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
41 | 3891 |
3892 #ifdef FEAT_WINDOWS | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
3893 qf_update_buffer(qi, NULL); |
41 | 3894 #endif |
3895 | |
842 | 3896 #ifdef FEAT_AUTOCMD |
3897 if (au_name != NULL) | |
3898 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | |
3899 curbuf->b_fname, TRUE, curbuf); | |
3900 #endif | |
3901 | |
41 | 3902 /* Jump to first match. */ |
644 | 3903 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
170 | 3904 { |
3905 if ((flags & VGR_NOJUMP) == 0) | |
1396 | 3906 { |
3907 buf = curbuf; | |
659 | 3908 qf_jump(qi, 0, 0, eap->forceit); |
1396 | 3909 if (buf != curbuf) |
3910 /* If we jumped to another buffer redrawing will already be | |
3911 * taken care of. */ | |
3912 redraw_for_dummy = FALSE; | |
1411 | 3913 |
3914 /* Jump to the directory used after loading the buffer. */ | |
3915 if (curbuf == first_match_buf && target_dir != NULL) | |
3916 { | |
3917 exarg_T ea; | |
3918 | |
3919 ea.arg = target_dir; | |
3920 ea.cmdidx = CMD_lcd; | |
3921 ex_cd(&ea); | |
3922 } | |
1396 | 3923 } |
170 | 3924 } |
42 | 3925 else |
3926 EMSG2(_(e_nomatch2), s); | |
41 | 3927 |
1396 | 3928 /* If we loaded a dummy buffer into the current window, the autocommands |
3929 * may have messed up things, need to redraw and recompute folds. */ | |
3930 if (redraw_for_dummy) | |
3931 { | |
3932 #ifdef FEAT_FOLDING | |
3933 foldUpdateAll(curwin); | |
3934 #else | |
3935 redraw_later(NOT_VALID); | |
3936 #endif | |
3937 } | |
3938 | |
41 | 3939 theend: |
8603
bfa74b84c41c
commit https://github.com/vim/vim/commit/5584df65a0ca2315d1eebc13c54a448bee4d0758
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
3940 vim_free(title); |
2770 | 3941 vim_free(dirname_now); |
3942 vim_free(dirname_start); | |
1411 | 3943 vim_free(target_dir); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
3944 vim_regfree(regmatch.regprog); |
41 | 3945 } |
3946 | |
3947 /* | |
170 | 3948 * Skip over the pattern argument of ":vimgrep /pat/[g][j]". |
153 | 3949 * Put the start of the pattern in "*s", unless "s" is NULL. |
170 | 3950 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP. |
3951 * If "s" is not NULL terminate the pattern with a NUL. | |
3952 * Return a pointer to the char just past the pattern plus flags. | |
153 | 3953 */ |
3954 char_u * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3955 skip_vimgrep_pat(char_u *p, char_u **s, int *flags) |
153 | 3956 { |
3957 int c; | |
3958 | |
3959 if (vim_isIDc(*p)) | |
3960 { | |
170 | 3961 /* ":vimgrep pattern fname" */ |
153 | 3962 if (s != NULL) |
3963 *s = p; | |
170 | 3964 p = skiptowhite(p); |
3965 if (s != NULL && *p != NUL) | |
3966 *p++ = NUL; | |
153 | 3967 } |
170 | 3968 else |
3969 { | |
3970 /* ":vimgrep /pattern/[g][j] fname" */ | |
3971 if (s != NULL) | |
3972 *s = p + 1; | |
3973 c = *p; | |
3974 p = skip_regexp(p + 1, c, TRUE, NULL); | |
3975 if (*p != c) | |
3976 return NULL; | |
3977 | |
3978 /* Truncate the pattern. */ | |
3979 if (s != NULL) | |
3980 *p = NUL; | |
3981 ++p; | |
3982 | |
3983 /* Find the flags */ | |
3984 while (*p == 'g' || *p == 'j') | |
3985 { | |
3986 if (flags != NULL) | |
3987 { | |
3988 if (*p == 'g') | |
3989 *flags |= VGR_GLOBAL; | |
3990 else | |
3991 *flags |= VGR_NOJUMP; | |
3992 } | |
3993 ++p; | |
3994 } | |
3995 } | |
153 | 3996 return p; |
3997 } | |
3998 | |
3999 /* | |
3490 | 4000 * Restore current working directory to "dirname_start" if they differ, taking |
4001 * into account whether it is set locally or globally. | |
4002 */ | |
4003 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4004 restore_start_dir(char_u *dirname_start) |
3490 | 4005 { |
4006 char_u *dirname_now = alloc(MAXPATHL); | |
4007 | |
4008 if (NULL != dirname_now) | |
4009 { | |
4010 mch_dirname(dirname_now, MAXPATHL); | |
4011 if (STRCMP(dirname_start, dirname_now) != 0) | |
4012 { | |
4013 /* If the directory has changed, change it back by building up an | |
4014 * appropriate ex command and executing it. */ | |
4015 exarg_T ea; | |
4016 | |
4017 ea.arg = dirname_start; | |
4018 ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; | |
4019 ex_cd(&ea); | |
4020 } | |
3974 | 4021 vim_free(dirname_now); |
3490 | 4022 } |
4023 } | |
4024 | |
4025 /* | |
4026 * Load file "fname" into a dummy buffer and return the buffer pointer, | |
4027 * placing the directory resulting from the buffer load into the | |
4028 * "resulting_dir" pointer. "resulting_dir" must be allocated by the caller | |
4029 * prior to calling this function. Restores directory to "dirname_start" prior | |
4030 * to returning, if autocmds or the 'autochdir' option have changed it. | |
4031 * | |
4032 * If creating the dummy buffer does not fail, must call unload_dummy_buffer() | |
4033 * or wipe_dummy_buffer() later! | |
4034 * | |
42 | 4035 * Returns NULL if it fails. |
4036 */ | |
4037 static buf_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4038 load_dummy_buffer( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4039 char_u *fname, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4040 char_u *dirname_start, /* in: old directory */ |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4041 char_u *resulting_dir) /* out: new directory */ |
42 | 4042 { |
4043 buf_T *newbuf; | |
2646 | 4044 buf_T *newbuf_to_wipe = NULL; |
42 | 4045 int failed = TRUE; |
4046 aco_save_T aco; | |
4047 | |
4048 /* Allocate a buffer without putting it in the buffer list. */ | |
4049 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); | |
4050 if (newbuf == NULL) | |
4051 return NULL; | |
4052 | |
177 | 4053 /* Init the options. */ |
4054 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP); | |
4055 | |
1918 | 4056 /* need to open the memfile before putting the buffer in a window */ |
4057 if (ml_open(newbuf) == OK) | |
42 | 4058 { |
1918 | 4059 /* set curwin/curbuf to buf and save a few things */ |
4060 aucmd_prepbuf(&aco, newbuf); | |
4061 | |
4062 /* Need to set the filename for autocommands. */ | |
4063 (void)setfname(curbuf, fname, NULL, FALSE); | |
4064 | |
42 | 4065 /* Create swap file now to avoid the ATTENTION message. */ |
4066 check_need_swap(TRUE); | |
4067 | |
4068 /* Remove the "dummy" flag, otherwise autocommands may not | |
4069 * work. */ | |
4070 curbuf->b_flags &= ~BF_DUMMY; | |
4071 | |
4072 if (readfile(fname, NULL, | |
4073 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, | |
4074 NULL, READ_NEW | READ_DUMMY) == OK | |
857 | 4075 && !got_int |
42 | 4076 && !(curbuf->b_flags & BF_NEW)) |
4077 { | |
4078 failed = FALSE; | |
4079 if (curbuf != newbuf) | |
4080 { | |
2646 | 4081 /* Bloody autocommands changed the buffer! Can happen when |
4082 * using netrw and editing a remote file. Use the current | |
4083 * buffer instead, delete the dummy one after restoring the | |
4084 * window stuff. */ | |
4085 newbuf_to_wipe = newbuf; | |
42 | 4086 newbuf = curbuf; |
4087 } | |
4088 } | |
1918 | 4089 |
4090 /* restore curwin/curbuf and a few other things */ | |
4091 aucmd_restbuf(&aco); | |
2646 | 4092 if (newbuf_to_wipe != NULL && buf_valid(newbuf_to_wipe)) |
4093 wipe_buffer(newbuf_to_wipe, FALSE); | |
42 | 4094 } |
4095 | |
3490 | 4096 /* |
4097 * When autocommands/'autochdir' option changed directory: go back. | |
4098 * Let the caller know what the resulting dir was first, in case it is | |
4099 * important. | |
4100 */ | |
4101 mch_dirname(resulting_dir, MAXPATHL); | |
4102 restore_start_dir(dirname_start); | |
4103 | |
42 | 4104 if (!buf_valid(newbuf)) |
4105 return NULL; | |
4106 if (failed) | |
4107 { | |
3490 | 4108 wipe_dummy_buffer(newbuf, dirname_start); |
42 | 4109 return NULL; |
4110 } | |
4111 return newbuf; | |
4112 } | |
4113 | |
4114 /* | |
3490 | 4115 * Wipe out the dummy buffer that load_dummy_buffer() created. Restores |
4116 * directory to "dirname_start" prior to returning, if autocmds or the | |
4117 * 'autochdir' option have changed it. | |
42 | 4118 */ |
4119 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4120 wipe_dummy_buffer(buf_T *buf, char_u *dirname_start) |
42 | 4121 { |
4122 if (curbuf != buf) /* safety check */ | |
857 | 4123 { |
4124 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
4125 cleanup_T cs; | |
4126 | |
4127 /* Reset the error/interrupt/exception state here so that aborting() | |
4128 * returns FALSE when wiping out the buffer. Otherwise it doesn't | |
4129 * work when got_int is set. */ | |
4130 enter_cleanup(&cs); | |
4131 #endif | |
4132 | |
42 | 4133 wipe_buffer(buf, FALSE); |
857 | 4134 |
4135 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
4136 /* Restore the error/interrupt/exception state if not discarded by a | |
4137 * new aborting error, interrupt, or uncaught exception. */ | |
4138 leave_cleanup(&cs); | |
4139 #endif | |
3490 | 4140 /* When autocommands/'autochdir' option changed directory: go back. */ |
4141 restore_start_dir(dirname_start); | |
857 | 4142 } |
42 | 4143 } |
4144 | |
4145 /* | |
3490 | 4146 * Unload the dummy buffer that load_dummy_buffer() created. Restores |
4147 * directory to "dirname_start" prior to returning, if autocmds or the | |
4148 * 'autochdir' option have changed it. | |
42 | 4149 */ |
4150 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4151 unload_dummy_buffer(buf_T *buf, char_u *dirname_start) |
42 | 4152 { |
4153 if (curbuf != buf) /* safety check */ | |
3490 | 4154 { |
3365 | 4155 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE); |
3490 | 4156 |
4157 /* When autocommands/'autochdir' option changed directory: go back. */ | |
4158 restore_start_dir(dirname_start); | |
4159 } | |
42 | 4160 } |
4161 | |
170 | 4162 #if defined(FEAT_EVAL) || defined(PROTO) |
4163 /* | |
4164 * Add each quickfix error to list "list" as a dictionary. | |
4165 */ | |
4166 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4167 get_errorlist(win_T *wp, list_T *list) |
170 | 4168 { |
644 | 4169 qf_info_T *qi = &ql_info; |
230 | 4170 dict_T *dict; |
4171 char_u buf[2]; | |
4172 qfline_T *qfp; | |
4173 int i; | |
1065 | 4174 int bufnum; |
170 | 4175 |
647 | 4176 if (wp != NULL) |
4177 { | |
4178 qi = GET_LOC_LIST(wp); | |
4179 if (qi == NULL) | |
4180 return FAIL; | |
4181 } | |
4182 | |
644 | 4183 if (qi->qf_curlist >= qi->qf_listcount |
712 | 4184 || qi->qf_lists[qi->qf_curlist].qf_count == 0) |
170 | 4185 return FAIL; |
4186 | |
644 | 4187 qfp = qi->qf_lists[qi->qf_curlist].qf_start; |
4188 for (i = 1; !got_int && i <= qi->qf_lists[qi->qf_curlist].qf_count; ++i) | |
170 | 4189 { |
1065 | 4190 /* Handle entries with a non-existing buffer number. */ |
4191 bufnum = qfp->qf_fnum; | |
4192 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
4193 bufnum = 0; | |
4194 | |
170 | 4195 if ((dict = dict_alloc()) == NULL) |
4196 return FAIL; | |
4197 if (list_append_dict(list, dict) == FAIL) | |
4198 return FAIL; | |
4199 | |
4200 buf[0] = qfp->qf_type; | |
4201 buf[1] = NUL; | |
1065 | 4202 if ( dict_add_nr_str(dict, "bufnr", (long)bufnum, NULL) == FAIL |
170 | 4203 || dict_add_nr_str(dict, "lnum", (long)qfp->qf_lnum, NULL) == FAIL |
4204 || dict_add_nr_str(dict, "col", (long)qfp->qf_col, NULL) == FAIL | |
4205 || dict_add_nr_str(dict, "vcol", (long)qfp->qf_viscol, NULL) == FAIL | |
4206 || dict_add_nr_str(dict, "nr", (long)qfp->qf_nr, NULL) == FAIL | |
960 | 4207 || dict_add_nr_str(dict, "pattern", 0L, |
4208 qfp->qf_pattern == NULL ? (char_u *)"" : qfp->qf_pattern) == FAIL | |
4209 || dict_add_nr_str(dict, "text", 0L, | |
4210 qfp->qf_text == NULL ? (char_u *)"" : qfp->qf_text) == FAIL | |
170 | 4211 || dict_add_nr_str(dict, "type", 0L, buf) == FAIL |
4212 || dict_add_nr_str(dict, "valid", (long)qfp->qf_valid, NULL) == FAIL) | |
4213 return FAIL; | |
4214 | |
4215 qfp = qfp->qf_next; | |
4216 } | |
4217 return OK; | |
4218 } | |
230 | 4219 |
4220 /* | |
4221 * Populate the quickfix list with the items supplied in the list | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4222 * of dictionaries. "title" will be copied to w:quickfix_title. |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4223 * "action" is 'a' for add, 'r' for replace. Otherwise create a new list. |
230 | 4224 */ |
4225 int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4226 set_errorlist( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4227 win_T *wp, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4228 list_T *list, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4229 int action, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4230 char_u *title) |
230 | 4231 { |
4232 listitem_T *li; | |
4233 dict_T *d; | |
4234 char_u *filename, *pattern, *text, *type; | |
1065 | 4235 int bufnum; |
230 | 4236 long lnum; |
4237 int col, nr; | |
4238 int vcol; | |
4239 qfline_T *prevp = NULL; | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4240 #ifdef FEAT_WINDOWS |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4241 qfline_T *old_last = NULL; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4242 #endif |
230 | 4243 int valid, status; |
4244 int retval = OK; | |
644 | 4245 qf_info_T *qi = &ql_info; |
1065 | 4246 int did_bufnr_emsg = FALSE; |
644 | 4247 |
647 | 4248 if (wp != NULL) |
4249 { | |
648 | 4250 qi = ll_get_or_alloc_list(wp); |
647 | 4251 if (qi == NULL) |
4252 return FAIL; | |
4253 } | |
4254 | |
644 | 4255 if (action == ' ' || qi->qf_curlist == qi->qf_listcount) |
277 | 4256 /* make place for a new list */ |
3965 | 4257 qf_new_list(qi, title); |
644 | 4258 else if (action == 'a' && qi->qf_lists[qi->qf_curlist].qf_count > 0) |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4259 { |
277 | 4260 /* Adding to existing list, find last entry. */ |
644 | 4261 for (prevp = qi->qf_lists[qi->qf_curlist].qf_start; |
277 | 4262 prevp->qf_next != prevp; prevp = prevp->qf_next) |
4263 ; | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4264 #ifdef FEAT_WINDOWS |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4265 old_last = prevp; |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4266 #endif |
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4267 } |
277 | 4268 else if (action == 'r') |
6079 | 4269 { |
644 | 4270 qf_free(qi, qi->qf_curlist); |
6079 | 4271 qf_store_title(qi, title); |
4272 } | |
230 | 4273 |
4274 for (li = list->lv_first; li != NULL; li = li->li_next) | |
4275 { | |
4276 if (li->li_tv.v_type != VAR_DICT) | |
4277 continue; /* Skip non-dict items */ | |
4278 | |
4279 d = li->li_tv.vval.v_dict; | |
4280 if (d == NULL) | |
4281 continue; | |
4282 | |
659 | 4283 filename = get_dict_string(d, (char_u *)"filename", TRUE); |
1065 | 4284 bufnum = get_dict_number(d, (char_u *)"bufnr"); |
230 | 4285 lnum = get_dict_number(d, (char_u *)"lnum"); |
4286 col = get_dict_number(d, (char_u *)"col"); | |
4287 vcol = get_dict_number(d, (char_u *)"vcol"); | |
4288 nr = get_dict_number(d, (char_u *)"nr"); | |
659 | 4289 type = get_dict_string(d, (char_u *)"type", TRUE); |
4290 pattern = get_dict_string(d, (char_u *)"pattern", TRUE); | |
4291 text = get_dict_string(d, (char_u *)"text", TRUE); | |
230 | 4292 if (text == NULL) |
4293 text = vim_strsave((char_u *)""); | |
4294 | |
4295 valid = TRUE; | |
1065 | 4296 if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) |
230 | 4297 valid = FALSE; |
4298 | |
1065 | 4299 /* Mark entries with non-existing buffer number as not valid. Give the |
4300 * error message only once. */ | |
4301 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
4302 { | |
4303 if (!did_bufnr_emsg) | |
4304 { | |
4305 did_bufnr_emsg = TRUE; | |
4306 EMSGN(_("E92: Buffer %ld not found"), bufnum); | |
4307 } | |
4308 valid = FALSE; | |
4309 bufnum = 0; | |
4310 } | |
4311 | |
644 | 4312 status = qf_add_entry(qi, &prevp, |
230 | 4313 NULL, /* dir */ |
4314 filename, | |
1065 | 4315 bufnum, |
230 | 4316 text, |
4317 lnum, | |
4318 col, | |
4319 vcol, /* vis_col */ | |
4320 pattern, /* search pattern */ | |
4321 nr, | |
4322 type == NULL ? NUL : *type, | |
4323 valid); | |
4324 | |
4325 vim_free(filename); | |
4326 vim_free(pattern); | |
4327 vim_free(text); | |
4328 vim_free(type); | |
4329 | |
4330 if (status == FAIL) | |
4331 { | |
4332 retval = FAIL; | |
4333 break; | |
4334 } | |
4335 } | |
4336 | |
2146
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
4337 if (qi->qf_lists[qi->qf_curlist].qf_index == 0) |
2795 | 4338 /* no valid entry */ |
2146
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
4339 qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE; |
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
4340 else |
c17a42da3920
updated for version 7.2.428
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
4341 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4342 if (action != 'a') { |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4343 qi->qf_lists[qi->qf_curlist].qf_ptr = |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4344 qi->qf_lists[qi->qf_curlist].qf_start; |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4345 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4346 qi->qf_lists[qi->qf_curlist].qf_index = 1; |
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4347 } |
230 | 4348 |
4349 #ifdef FEAT_WINDOWS | |
8932
25c2031e9f9f
commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28
Christian Brabandt <cb@256bit.org>
parents:
8751
diff
changeset
|
4350 /* Don't update the cursor in quickfix window when appending entries */ |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4351 qf_update_buffer(qi, old_last); |
230 | 4352 #endif |
4353 | |
4354 return retval; | |
4355 } | |
170 | 4356 #endif |
4357 | |
42 | 4358 /* |
41 | 4359 * ":[range]cbuffer [bufnr]" command. |
657 | 4360 * ":[range]caddbuffer [bufnr]" command. |
798 | 4361 * ":[range]cgetbuffer [bufnr]" command. |
644 | 4362 * ":[range]lbuffer [bufnr]" command. |
657 | 4363 * ":[range]laddbuffer [bufnr]" command. |
798 | 4364 * ":[range]lgetbuffer [bufnr]" command. |
41 | 4365 */ |
4366 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4367 ex_cbuffer(exarg_T *eap) |
41 | 4368 { |
4369 buf_T *buf = NULL; | |
644 | 4370 qf_info_T *qi = &ql_info; |
4371 | |
798 | 4372 if (eap->cmdidx == CMD_lbuffer || eap->cmdidx == CMD_lgetbuffer |
4373 || eap->cmdidx == CMD_laddbuffer) | |
644 | 4374 { |
4375 qi = ll_get_or_alloc_list(curwin); | |
4376 if (qi == NULL) | |
4377 return; | |
4378 } | |
41 | 4379 |
4380 if (*eap->arg == NUL) | |
4381 buf = curbuf; | |
4382 else if (*skipwhite(skipdigits(eap->arg)) == NUL) | |
4383 buf = buflist_findnr(atoi((char *)eap->arg)); | |
4384 if (buf == NULL) | |
4385 EMSG(_(e_invarg)); | |
4386 else if (buf->b_ml.ml_mfp == NULL) | |
4387 EMSG(_("E681: Buffer is not loaded")); | |
4388 else | |
4389 { | |
4390 if (eap->addr_count == 0) | |
4391 { | |
4392 eap->line1 = 1; | |
4393 eap->line2 = buf->b_ml.ml_line_count; | |
4394 } | |
4395 if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count | |
4396 || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count) | |
4397 EMSG(_(e_invrange)); | |
4398 else | |
661 | 4399 { |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4400 char_u *qf_title = *eap->cmdlinep; |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4401 |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4402 if (buf->b_sfname) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4403 { |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4404 vim_snprintf((char *)IObuff, IOSIZE, "%s (%s)", |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4405 (char *)qf_title, (char *)buf->b_sfname); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4406 qf_title = IObuff; |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4407 } |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4408 |
798 | 4409 if (qf_init_ext(qi, NULL, buf, NULL, p_efm, |
4410 (eap->cmdidx != CMD_caddbuffer | |
4411 && eap->cmdidx != CMD_laddbuffer), | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4412 eap->line1, eap->line2, |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4413 qf_title) > 0 |
798 | 4414 && (eap->cmdidx == CMD_cbuffer |
4415 || eap->cmdidx == CMD_lbuffer)) | |
661 | 4416 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
4417 } | |
41 | 4418 } |
4419 } | |
4420 | |
532 | 4421 #if defined(FEAT_EVAL) || defined(PROTO) |
41 | 4422 /* |
798 | 4423 * ":cexpr {expr}", ":cgetexpr {expr}", ":caddexpr {expr}" command. |
4424 * ":lexpr {expr}", ":lgetexpr {expr}", ":laddexpr {expr}" command. | |
446 | 4425 */ |
4426 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4427 ex_cexpr(exarg_T *eap) |
446 | 4428 { |
4429 typval_T *tv; | |
644 | 4430 qf_info_T *qi = &ql_info; |
4431 | |
798 | 4432 if (eap->cmdidx == CMD_lexpr || eap->cmdidx == CMD_lgetexpr |
4433 || eap->cmdidx == CMD_laddexpr) | |
644 | 4434 { |
4435 qi = ll_get_or_alloc_list(curwin); | |
4436 if (qi == NULL) | |
4437 return; | |
4438 } | |
446 | 4439 |
625 | 4440 /* Evaluate the expression. When the result is a string or a list we can |
4441 * use it to fill the errorlist. */ | |
446 | 4442 tv = eval_expr(eap->arg, NULL); |
625 | 4443 if (tv != NULL) |
4444 { | |
4445 if ((tv->v_type == VAR_STRING && tv->vval.v_string != NULL) | |
4446 || (tv->v_type == VAR_LIST && tv->vval.v_list != NULL)) | |
4447 { | |
7701
075810b0cb6c
commit https://github.com/vim/vim/commit/d6357e8f93c50f984ffd69c3a0d247d8603f86c3
Christian Brabandt <cb@256bit.org>
parents:
7662
diff
changeset
|
4448 if (qf_init_ext(qi, NULL, NULL, tv, p_efm, |
798 | 4449 (eap->cmdidx != CMD_caddexpr |
4450 && eap->cmdidx != CMD_laddexpr), | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2296
diff
changeset
|
4451 (linenr_T)0, (linenr_T)0, *eap->cmdlinep) > 0 |
798 | 4452 && (eap->cmdidx == CMD_cexpr |
4453 || eap->cmdidx == CMD_lexpr)) | |
659 | 4454 qf_jump(qi, 0, 0, eap->forceit); /* display first error */ |
625 | 4455 } |
4456 else | |
626 | 4457 EMSG(_("E777: String or List expected")); |
625 | 4458 free_tv(tv); |
4459 } | |
446 | 4460 } |
532 | 4461 #endif |
446 | 4462 |
4463 /* | |
7 | 4464 * ":helpgrep {pattern}" |
4465 */ | |
4466 void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4467 ex_helpgrep(exarg_T *eap) |
7 | 4468 { |
4469 regmatch_T regmatch; | |
4470 char_u *save_cpo; | |
4471 char_u *p; | |
4472 int fcount; | |
4473 char_u **fnames; | |
4474 FILE *fd; | |
4475 int fi; | |
230 | 4476 qfline_T *prevp = NULL; |
7 | 4477 long lnum; |
9 | 4478 #ifdef FEAT_MULTI_LANG |
4479 char_u *lang; | |
4480 #endif | |
644 | 4481 qf_info_T *qi = &ql_info; |
659 | 4482 int new_qi = FALSE; |
4483 win_T *wp; | |
3269 | 4484 #ifdef FEAT_AUTOCMD |
4485 char_u *au_name = NULL; | |
4486 #endif | |
7 | 4487 |
9 | 4488 #ifdef FEAT_MULTI_LANG |
4489 /* Check for a specified language */ | |
4490 lang = check_help_lang(eap->arg); | |
4491 #endif | |
4492 | |
3269 | 4493 #ifdef FEAT_AUTOCMD |
4494 switch (eap->cmdidx) | |
4495 { | |
4496 case CMD_helpgrep: au_name = (char_u *)"helpgrep"; break; | |
4497 case CMD_lhelpgrep: au_name = (char_u *)"lhelpgrep"; break; | |
4498 default: break; | |
4499 } | |
4500 if (au_name != NULL) | |
4501 { | |
4502 apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name, | |
4503 curbuf->b_fname, TRUE, curbuf); | |
4504 if (did_throw || force_abort) | |
4505 return; | |
4506 } | |
4507 #endif | |
4508 | |
4509 /* Make 'cpoptions' empty, the 'l' flag should not be used here. */ | |
4510 save_cpo = p_cpo; | |
4511 p_cpo = empty_option; | |
4512 | |
659 | 4513 if (eap->cmdidx == CMD_lhelpgrep) |
4514 { | |
4515 /* Find an existing help window */ | |
4516 FOR_ALL_WINDOWS(wp) | |
4517 if (wp->w_buffer != NULL && wp->w_buffer->b_help) | |
4518 break; | |
4519 | |
4520 if (wp == NULL) /* Help window not found */ | |
4521 qi = NULL; | |
4522 else | |
4523 qi = wp->w_llist; | |
4524 | |
4525 if (qi == NULL) | |
4526 { | |
4527 /* Allocate a new location list for help text matches */ | |
4528 if ((qi = ll_new_list()) == NULL) | |
4529 return; | |
4530 new_qi = TRUE; | |
4531 } | |
4532 } | |
4533 | |
7 | 4534 regmatch.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING); |
4535 regmatch.rm_ic = FALSE; | |
4536 if (regmatch.regprog != NULL) | |
4537 { | |
3257 | 4538 #ifdef FEAT_MBYTE |
4539 vimconv_T vc; | |
4540 | |
4541 /* Help files are in utf-8 or latin1, convert lines when 'encoding' | |
4542 * differs. */ | |
4543 vc.vc_type = CONV_NONE; | |
4544 if (!enc_utf8) | |
4545 convert_setup(&vc, (char_u *)"utf-8", p_enc); | |
4546 #endif | |
4547 | |
7 | 4548 /* create a new quickfix list */ |
3965 | 4549 qf_new_list(qi, *eap->cmdlinep); |
7 | 4550 |
4551 /* Go through all directories in 'runtimepath' */ | |
4552 p = p_rtp; | |
4553 while (*p != NUL && !got_int) | |
4554 { | |
4555 copy_option_part(&p, NameBuff, MAXPATHL, ","); | |
4556 | |
4557 /* Find all "*.txt" and "*.??x" files in the "doc" directory. */ | |
4558 add_pathsep(NameBuff); | |
4559 STRCAT(NameBuff, "doc/*.\\(txt\\|??x\\)"); | |
4560 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
4561 &fnames, EW_FILE|EW_SILENT) == OK | |
4562 && fcount > 0) | |
4563 { | |
4564 for (fi = 0; fi < fcount && !got_int; ++fi) | |
4565 { | |
9 | 4566 #ifdef FEAT_MULTI_LANG |
4567 /* Skip files for a different language. */ | |
4568 if (lang != NULL | |
4569 && STRNICMP(lang, fnames[fi] | |
4570 + STRLEN(fnames[fi]) - 3, 2) != 0 | |
4571 && !(STRNICMP(lang, "en", 2) == 0 | |
4572 && STRNICMP("txt", fnames[fi] | |
4573 + STRLEN(fnames[fi]) - 3, 3) == 0)) | |
4574 continue; | |
4575 #endif | |
531 | 4576 fd = mch_fopen((char *)fnames[fi], "r"); |
7 | 4577 if (fd != NULL) |
4578 { | |
4579 lnum = 1; | |
4580 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) | |
4581 { | |
3257 | 4582 char_u *line = IObuff; |
4583 #ifdef FEAT_MBYTE | |
4584 /* Convert a line if 'encoding' is not utf-8 and | |
4585 * the line contains a non-ASCII character. */ | |
4586 if (vc.vc_type != CONV_NONE | |
4587 && has_non_ascii(IObuff)) { | |
4588 line = string_convert(&vc, IObuff, NULL); | |
4589 if (line == NULL) | |
4590 line = IObuff; | |
4591 } | |
4592 #endif | |
4593 | |
4594 if (vim_regexec(®match, line, (colnr_T)0)) | |
7 | 4595 { |
3257 | 4596 int l = (int)STRLEN(line); |
7 | 4597 |
4598 /* remove trailing CR, LF, spaces, etc. */ | |
3257 | 4599 while (l > 0 && line[l - 1] <= ' ') |
4600 line[--l] = NUL; | |
7 | 4601 |
644 | 4602 if (qf_add_entry(qi, &prevp, |
7 | 4603 NULL, /* dir */ |
4604 fnames[fi], | |
1065 | 4605 0, |
3257 | 4606 line, |
7 | 4607 lnum, |
3257 | 4608 (int)(regmatch.startp[0] - line) |
42 | 4609 + 1, /* col */ |
170 | 4610 FALSE, /* vis_col */ |
230 | 4611 NULL, /* search pattern */ |
7 | 4612 0, /* nr */ |
4613 1, /* type */ | |
4614 TRUE /* valid */ | |
4615 ) == FAIL) | |
4616 { | |
4617 got_int = TRUE; | |
3257 | 4618 #ifdef FEAT_MBYTE |
4619 if (line != IObuff) | |
4620 vim_free(line); | |
4621 #endif | |
7 | 4622 break; |
4623 } | |
4624 } | |
3257 | 4625 #ifdef FEAT_MBYTE |
4626 if (line != IObuff) | |
4627 vim_free(line); | |
4628 #endif | |
7 | 4629 ++lnum; |
4630 line_breakcheck(); | |
4631 } | |
4632 fclose(fd); | |
4633 } | |
4634 } | |
4635 FreeWild(fcount, fnames); | |
4636 } | |
4637 } | |
3257 | 4638 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4371
diff
changeset
|
4639 vim_regfree(regmatch.regprog); |
3257 | 4640 #ifdef FEAT_MBYTE |
4641 if (vc.vc_type != CONV_NONE) | |
4642 convert_setup(&vc, NULL, NULL); | |
4643 #endif | |
7 | 4644 |
644 | 4645 qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE; |
4646 qi->qf_lists[qi->qf_curlist].qf_ptr = | |
4647 qi->qf_lists[qi->qf_curlist].qf_start; | |
4648 qi->qf_lists[qi->qf_curlist].qf_index = 1; | |
7 | 4649 } |
4650 | |
1672 | 4651 if (p_cpo == empty_option) |
4652 p_cpo = save_cpo; | |
4653 else | |
4654 /* Darn, some plugin changed the value. */ | |
4655 free_string_option(save_cpo); | |
7 | 4656 |
4657 #ifdef FEAT_WINDOWS | |
9175
d415c079f84e
commit https://github.com/vim/vim/commit/864293abb72d62604d8d6b458addfb43c14230c3
Christian Brabandt <cb@256bit.org>
parents:
9114
diff
changeset
|
4658 qf_update_buffer(qi, NULL); |
7 | 4659 #endif |
4660 | |
3269 | 4661 #ifdef FEAT_AUTOCMD |
4662 if (au_name != NULL) | |
4663 { | |
4664 apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, | |
4665 curbuf->b_fname, TRUE, curbuf); | |
4666 if (!new_qi && qi != &ql_info && qf_find_buf(qi) == NULL) | |
4667 /* autocommands made "qi" invalid */ | |
4668 return; | |
4669 } | |
4670 #endif | |
4671 | |
7 | 4672 /* Jump to first match. */ |
644 | 4673 if (qi->qf_lists[qi->qf_curlist].qf_count > 0) |
659 | 4674 qf_jump(qi, 0, 0, FALSE); |
9 | 4675 else |
4676 EMSG2(_(e_nomatch2), eap->arg); | |
659 | 4677 |
4678 if (eap->cmdidx == CMD_lhelpgrep) | |
4679 { | |
4680 /* If the help window is not opened or if it already points to the | |
661 | 4681 * correct location list, then free the new location list. */ |
659 | 4682 if (!curwin->w_buffer->b_help || curwin->w_llist == qi) |
4683 { | |
4684 if (new_qi) | |
4685 ll_free_all(&qi); | |
4686 } | |
4687 else if (curwin->w_llist == NULL) | |
4688 curwin->w_llist = qi; | |
4689 } | |
7 | 4690 } |
4691 | |
4692 #endif /* FEAT_QUICKFIX */ |