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