]>
Commit | Line | Data |
---|---|---|
5a088057 KK |
1 | To: vim_dev@googlegroups.com |
2 | Subject: Patch 7.3.631 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.3.631 | |
11 | Problem: Cannot complete user names. | |
12 | Solution: Add user name completion. (Dominique Pelle) | |
13 | Files: runtime/doc/map.txt, src/auto/configure, src/config.h.in, | |
14 | src/configure.in, src/ex_docmd.c, src/ex_getln.c, | |
15 | src/misc1.c, src/misc2.c, src/proto/misc1.pro, src/vim.h | |
16 | ||
17 | ||
18 | *** ../vim-7.3.630/runtime/doc/map.txt 2012-04-30 18:48:38.000000000 +0200 | |
19 | --- runtime/doc/map.txt 2012-08-15 13:46:34.000000000 +0200 | |
20 | *************** | |
21 | *** 1227,1232 **** | |
22 | --- 1244,1250 ---- | |
23 | -complete=syntax syntax file names |'syntax'| | |
24 | -complete=tag tags | |
25 | -complete=tag_listfiles tags, file names are shown when CTRL-D is hit | |
26 | + -complete=user user names | |
27 | -complete=var user variables | |
28 | -complete=custom,{func} custom completion, defined via {func} | |
29 | -complete=customlist,{func} custom completion, defined via {func} | |
30 | *** ../vim-7.3.630/src/auto/configure 2012-07-25 16:32:03.000000000 +0200 | |
31 | --- src/auto/configure 2012-08-15 13:48:06.000000000 +0200 | |
32 | *************** | |
33 | *** 10631,10637 **** | |
34 | fi | |
35 | ||
36 | for ac_func in bcmp fchdir fchown fsync getcwd getpseudotty \ | |
37 | ! getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \ | |
38 | memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \ | |
39 | setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \ | |
40 | sigvec strcasecmp strerror strftime stricmp strncasecmp \ | |
41 | --- 10631,10637 ---- | |
42 | fi | |
43 | ||
44 | for ac_func in bcmp fchdir fchown fsync getcwd getpseudotty \ | |
45 | ! getpwent getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \ | |
46 | memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \ | |
47 | setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \ | |
48 | sigvec strcasecmp strerror strftime stricmp strncasecmp \ | |
49 | *** ../vim-7.3.630/src/config.h.in 2012-02-05 22:51:27.000000000 +0100 | |
50 | --- src/config.h.in 2012-08-15 13:46:35.000000000 +0200 | |
51 | *************** | |
52 | *** 161,166 **** | |
53 | --- 161,167 ---- | |
54 | #undef HAVE_FSYNC | |
55 | #undef HAVE_GETCWD | |
56 | #undef HAVE_GETPSEUDOTTY | |
57 | + #undef HAVE_GETPWENT | |
58 | #undef HAVE_GETPWNAM | |
59 | #undef HAVE_GETPWUID | |
60 | #undef HAVE_GETRLIMIT | |
61 | *** ../vim-7.3.630/src/configure.in 2012-07-25 16:32:03.000000000 +0200 | |
62 | --- src/configure.in 2012-08-15 13:46:35.000000000 +0200 | |
63 | *************** | |
64 | *** 2994,3000 **** | |
65 | dnl Check for functions in one big call, to reduce the size of configure. | |
66 | dnl Can only be used for functions that do not require any include. | |
67 | AC_CHECK_FUNCS(bcmp fchdir fchown fsync getcwd getpseudotty \ | |
68 | ! getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \ | |
69 | memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \ | |
70 | setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \ | |
71 | sigvec strcasecmp strerror strftime stricmp strncasecmp \ | |
72 | --- 2994,3000 ---- | |
73 | dnl Check for functions in one big call, to reduce the size of configure. | |
74 | dnl Can only be used for functions that do not require any include. | |
75 | AC_CHECK_FUNCS(bcmp fchdir fchown fsync getcwd getpseudotty \ | |
76 | ! getpwent getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \ | |
77 | memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \ | |
78 | setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \ | |
79 | sigvec strcasecmp strerror strftime stricmp strncasecmp \ | |
80 | *** ../vim-7.3.630/src/ex_docmd.c 2012-08-02 21:24:38.000000000 +0200 | |
81 | --- src/ex_docmd.c 2012-08-15 13:54:29.000000000 +0200 | |
82 | *************** | |
83 | *** 3515,3520 **** | |
84 | --- 3515,3537 ---- | |
85 | #endif | |
86 | } | |
87 | } | |
88 | + #if defined(FEAT_CMDL_COMPL) | |
89 | + /* Check for user names */ | |
90 | + if (*xp->xp_pattern == '~') | |
91 | + { | |
92 | + for (p = xp->xp_pattern + 1; *p != NUL && *p != '/'; ++p) | |
93 | + ; | |
94 | + /* Complete ~user only if it partially matches a user name. | |
95 | + * A full match ~user<Tab> will be replaced by user's home | |
96 | + * directory i.e. something like ~user<Tab> -> /home/user/ */ | |
97 | + if (*p == NUL && p > xp->xp_pattern + 1 | |
98 | + && match_user(xp->xp_pattern + 1) == 1) | |
99 | + { | |
100 | + xp->xp_context = EXPAND_USER; | |
101 | + ++xp->xp_pattern; | |
102 | + } | |
103 | + } | |
104 | + #endif | |
105 | } | |
106 | ||
107 | /* | |
108 | *************** | |
109 | *** 5396,5401 **** | |
110 | --- 5413,5419 ---- | |
111 | #endif | |
112 | {EXPAND_TAGS, "tag"}, | |
113 | {EXPAND_TAGS_LISTFILES, "tag_listfiles"}, | |
114 | + {EXPAND_USER, "user"}, | |
115 | {EXPAND_USER_VARS, "var"}, | |
116 | {0, NULL} | |
117 | }; | |
118 | *** ../vim-7.3.630/src/ex_getln.c 2012-08-08 18:01:00.000000000 +0200 | |
119 | --- src/ex_getln.c 2012-08-15 13:46:35.000000000 +0200 | |
120 | *************** | |
121 | *** 4336,4341 **** | |
122 | --- 4336,4342 ---- | |
123 | * EXPAND_EXPRESSION Complete internal or user defined function/variable | |
124 | * names in expressions, eg :while s^I | |
125 | * EXPAND_ENV_VARS Complete environment variable names | |
126 | + * EXPAND_USER Complete user names | |
127 | */ | |
128 | static void | |
129 | set_expand_context(xp) | |
130 | *************** | |
131 | *** 4681,4686 **** | |
132 | --- 4682,4688 ---- | |
133 | {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
134 | #endif | |
135 | {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
136 | + {EXPAND_USER, get_users, TRUE, FALSE}, | |
137 | }; | |
138 | int i; | |
139 | ||
140 | *** ../vim-7.3.630/src/misc1.c 2012-08-08 18:01:00.000000000 +0200 | |
141 | --- src/misc1.c 2012-08-15 13:57:53.000000000 +0200 | |
142 | *************** | |
143 | *** 18,23 **** | |
144 | --- 18,28 ---- | |
145 | static char_u *remove_tail __ARGS((char_u *p, char_u *pend, char_u *name)); | |
146 | static int copy_indent __ARGS((int size, char_u *src)); | |
147 | ||
148 | + /* All user names (for ~user completion as done by shell). */ | |
149 | + #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
150 | + static garray_T ga_users; | |
151 | + #endif | |
152 | + | |
153 | /* | |
154 | * Count the size (in window cells) of the indent in the current line. | |
155 | */ | |
156 | *************** | |
157 | *** 3782,3787 **** | |
158 | --- 3787,3800 ---- | |
159 | { | |
160 | vim_free(homedir); | |
161 | } | |
162 | + | |
163 | + # ifdef FEAT_CMDL_COMPL | |
164 | + void | |
165 | + free_users() | |
166 | + { | |
167 | + ga_clear_strings(&ga_users); | |
168 | + } | |
169 | + # endif | |
170 | #endif | |
171 | ||
172 | /* | |
173 | *************** | |
174 | *** 4451,4456 **** | |
175 | --- 4464,4543 ---- | |
176 | return name; | |
177 | # endif | |
178 | } | |
179 | + | |
180 | + /* | |
181 | + * Find all user names for user completion. | |
182 | + * Done only once and then cached. | |
183 | + */ | |
184 | + static void | |
185 | + init_users() { | |
186 | + static int lazy_init_done = FALSE; | |
187 | + | |
188 | + if (lazy_init_done) | |
189 | + return; | |
190 | + | |
191 | + lazy_init_done = TRUE; | |
192 | + ga_init2(&ga_users, sizeof(char_u *), 20); | |
193 | + | |
194 | + # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) | |
195 | + { | |
196 | + char_u* user; | |
197 | + struct passwd* pw; | |
198 | + | |
199 | + setpwent(); | |
200 | + while ((pw = getpwent()) != NULL) | |
201 | + /* pw->pw_name shouldn't be NULL but just in case... */ | |
202 | + if (pw->pw_name != NULL) | |
203 | + { | |
204 | + if (ga_grow(&ga_users, 1) == FAIL) | |
205 | + break; | |
206 | + user = vim_strsave((char_u*)pw->pw_name); | |
207 | + if (user == NULL) | |
208 | + break; | |
209 | + ((char_u **)(ga_users.ga_data))[ga_users.ga_len++] = user; | |
210 | + } | |
211 | + endpwent(); | |
212 | + } | |
213 | + # endif | |
214 | + } | |
215 | + | |
216 | + /* | |
217 | + * Function given to ExpandGeneric() to obtain an user names. | |
218 | + */ | |
219 | + char_u* | |
220 | + get_users(xp, idx) | |
221 | + expand_T *xp UNUSED; | |
222 | + int idx; | |
223 | + { | |
224 | + init_users(); | |
225 | + if (idx < ga_users.ga_len) | |
226 | + return ((char_u **)ga_users.ga_data)[idx]; | |
227 | + return NULL; | |
228 | + } | |
229 | + | |
230 | + /* | |
231 | + * Check whether name matches a user name. Return: | |
232 | + * 0 if name does not match any user name. | |
233 | + * 1 if name partially matches the beginning of a user name. | |
234 | + * 2 is name fully matches a user name. | |
235 | + */ | |
236 | + int match_user(name) | |
237 | + char_u* name; | |
238 | + { | |
239 | + int i; | |
240 | + int n = (int)STRLEN(name); | |
241 | + int result = 0; | |
242 | + | |
243 | + init_users(); | |
244 | + for (i = 0; i < ga_users.ga_len; i++) | |
245 | + { | |
246 | + if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) | |
247 | + return 2; /* full match */ | |
248 | + if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) | |
249 | + result = 1; /* partial match */ | |
250 | + } | |
251 | + return result; | |
252 | + } | |
253 | #endif | |
254 | ||
255 | /* | |
256 | *** ../vim-7.3.630/src/misc2.c 2012-06-29 15:51:26.000000000 +0200 | |
257 | --- src/misc2.c 2012-08-15 13:46:35.000000000 +0200 | |
258 | *************** | |
259 | *** 1110,1115 **** | |
260 | --- 1110,1118 ---- | |
261 | free_all_marks(); | |
262 | alist_clear(&global_alist); | |
263 | free_homedir(); | |
264 | + # if defined(FEAT_CMDL_COMPL) | |
265 | + free_users(); | |
266 | + # endif | |
267 | free_search_patterns(); | |
268 | free_old_sub(); | |
269 | free_last_insert(); | |
270 | *** ../vim-7.3.630/src/proto/misc1.pro 2012-06-06 16:12:54.000000000 +0200 | |
271 | --- src/proto/misc1.pro 2012-08-15 13:46:35.000000000 +0200 | |
272 | *************** | |
273 | *** 50,55 **** | |
274 | --- 50,56 ---- | |
275 | void vim_beep __ARGS((void)); | |
276 | void init_homedir __ARGS((void)); | |
277 | void free_homedir __ARGS((void)); | |
278 | + void free_users __ARGS((void)); | |
279 | char_u *expand_env_save __ARGS((char_u *src)); | |
280 | char_u *expand_env_save_opt __ARGS((char_u *src, int one)); | |
281 | void expand_env __ARGS((char_u *src, char_u *dst, int dstlen)); | |
282 | *************** | |
283 | *** 57,62 **** | |
284 | --- 58,65 ---- | |
285 | char_u *vim_getenv __ARGS((char_u *name, int *mustfree)); | |
286 | void vim_setenv __ARGS((char_u *name, char_u *val)); | |
287 | char_u *get_env_name __ARGS((expand_T *xp, int idx)); | |
288 | + char_u *get_users __ARGS((expand_T *xp, int idx)); | |
289 | + int match_user __ARGS((char_u* name)); | |
290 | void home_replace __ARGS((buf_T *buf, char_u *src, char_u *dst, int dstlen, int one)); | |
291 | char_u *home_replace_save __ARGS((buf_T *buf, char_u *src)); | |
292 | int fullpathcmp __ARGS((char_u *s1, char_u *s2, int checkname)); | |
293 | *** ../vim-7.3.630/src/vim.h 2012-07-10 17:14:50.000000000 +0200 | |
294 | --- src/vim.h 2012-08-15 13:46:35.000000000 +0200 | |
295 | *************** | |
296 | *** 782,787 **** | |
297 | --- 782,788 ---- | |
298 | #define EXPAND_OWNSYNTAX 39 | |
299 | #define EXPAND_LOCALES 40 | |
300 | #define EXPAND_HISTORY 41 | |
301 | + #define EXPAND_USER 42 | |
302 | ||
303 | /* Values for exmode_active (0 is no exmode) */ | |
304 | #define EXMODE_NORMAL 1 | |
305 | *** ../vim-7.3.630/src/version.c 2012-08-15 13:30:55.000000000 +0200 | |
306 | --- src/version.c 2012-08-15 14:01:12.000000000 +0200 | |
307 | *************** | |
308 | *** 716,717 **** | |
309 | --- 716,719 ---- | |
310 | { /* Add new patch number below this line */ | |
311 | + /**/ | |
312 | + 631, | |
313 | /**/ | |
314 | ||
315 | -- | |
316 | "Marriage is the process of finding out what kind of man your wife | |
317 | would have preferred" | |
318 | ||
319 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
320 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
321 | \\\ an exciting new programming language -- http://www.Zimbu.org /// | |
322 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |