annotate src/help.c @ 22518:81ae5fa92928 v8.2.1807

patch 8.2.1807: can use :help in a terminal popup window Commit: https://github.com/vim/vim/commit/349f609f8990a3aca9a4b8faa0585d75e03116db Author: Bram Moolenaar <Bram@vim.org> Date: Tue Oct 6 20:46:49 2020 +0200 patch 8.2.1807: can use :help in a terminal popup window Problem: Can use :help in a terminal popup window. Solution: Give an error. (closes https://github.com/vim/vim/issues/7088)
author Bram Moolenaar <Bram@vim.org>
date Tue, 06 Oct 2020 21:00:03 +0200
parents 5db63c2c6929
children 431367075f29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21423
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * help.c: functions for Vim help
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 * ":help": open a read-only window on a help file
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 ex_help(exarg_T *eap)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 char_u *arg;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 char_u *tag;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 FILE *helpfd; // file descriptor of help file
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 int n;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 int i;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 win_T *wp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 int num_matches;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 char_u **matches;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 char_u *p;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 int empty_fnum = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 int alt_fnum = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 buf_T *buf;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 int len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 char_u *lang;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 #ifdef FEAT_FOLDING
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 int old_KeyTyped = KeyTyped;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
22518
81ae5fa92928 patch 8.2.1807: can use :help in a terminal popup window
Bram Moolenaar <Bram@vim.org>
parents: 21423
diff changeset
42 if (ERROR_IF_ANY_POPUP_WINDOW)
81ae5fa92928 patch 8.2.1807: can use :help in a terminal popup window
Bram Moolenaar <Bram@vim.org>
parents: 21423
diff changeset
43 return;
81ae5fa92928 patch 8.2.1807: can use :help in a terminal popup window
Bram Moolenaar <Bram@vim.org>
parents: 21423
diff changeset
44
21423
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 if (eap != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 // A ":help" command ends at the first LF, or at a '|' that is
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 // followed by some text. Set nextcmd to the following command.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 for (arg = eap->arg; *arg; ++arg)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 if (*arg == '\n' || *arg == '\r'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 || (*arg == '|' && arg[1] != NUL && arg[1] != '|'))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 *arg++ = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 eap->nextcmd = arg;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 arg = eap->arg;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 if (eap->forceit && *arg == NUL && !curbuf->b_help)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 emsg(_("E478: Don't panic!"));
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 if (eap->skip) // not executing commands
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 arg = (char_u *)"";
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 // remove trailing blanks
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 p = arg + STRLEN(arg) - 1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 while (p > arg && VIM_ISWHITE(*p) && p[-1] != '\\')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 *p-- = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 // Check for a specified language
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 lang = check_help_lang(arg);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 // When no argument given go to the index.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 if (*arg == NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 arg = (char_u *)"help.txt";
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 // Check if there is a match for the argument.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 n = find_help_tags(arg, &num_matches, &matches,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 eap != NULL && eap->forceit);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 i = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 if (n != FAIL && lang != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 // Find first item with the requested language.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 for (i = 0; i < num_matches; ++i)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 len = (int)STRLEN(matches[i]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 if (len > 3 && matches[i][len - 3] == '@'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 && STRICMP(matches[i] + len - 2, lang) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 if (i >= num_matches || n == FAIL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 if (lang != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 semsg(_("E661: Sorry, no '%s' help for %s"), lang, arg);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 semsg(_("E149: Sorry, no help for %s"), arg);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 if (n != FAIL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 FreeWild(num_matches, matches);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 // The first match (in the requested language) is the best match.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 tag = vim_strsave(matches[i]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 FreeWild(num_matches, matches);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 #ifdef FEAT_GUI
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 need_mouse_correct = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 // Re-use an existing help window or open a new one.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 // Always open a new one for ":tab help".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 if (!bt_help(curwin->w_buffer) || cmdmod.tab != 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 if (cmdmod.tab != 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 wp = NULL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 FOR_ALL_WINDOWS(wp)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 if (bt_help(wp->w_buffer))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 if (wp != NULL && wp->w_buffer->b_nwindows > 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 win_enter(wp, TRUE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 // There is no help window yet.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 // Try to open the file specified by the "helpfile" option.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 smsg(_("Sorry, help file \"%s\" not found"), p_hf);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 goto erret;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 fclose(helpfd);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 // Split off help window; put it at far top if no position
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 // specified, the current window is vertically split and
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 // narrow.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 n = WSP_HELP;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 if (cmdmod.split == 0 && curwin->w_width != Columns
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 && curwin->w_width < 80)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 n |= WSP_TOP;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 if (win_split(0, n) == FAIL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 goto erret;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 if (curwin->w_height < p_hh)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 win_setheight((int)p_hh);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 // Open help file (do_ecmd() will set b_help flag, readfile() will
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 // set b_p_ro flag).
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 // Set the alternate file to the previously edited file.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 alt_fnum = curbuf->b_fnum;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 ECMD_HIDE + ECMD_SET_HELP,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 NULL); // buffer is still open, don't store info
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 if (!cmdmod.keepalt)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 curwin->w_alt_fnum = alt_fnum;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 empty_fnum = curbuf->b_fnum;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 if (!p_im)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 restart_edit = 0; // don't want insert mode in help file
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 #ifdef FEAT_FOLDING
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 // Restore KeyTyped, setting 'filetype=help' may reset it.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 // It is needed for do_tag top open folds under the cursor.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 KeyTyped = old_KeyTyped;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 if (tag != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 do_tag(tag, DT_HELP, 1, FALSE, TRUE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 // Delete the empty buffer if we're not using it. Careful: autocommands
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 // may have jumped to another window, check that the buffer is not in a
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 // window.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 if (empty_fnum != 0 && curbuf->b_fnum != empty_fnum)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 buf = buflist_findnr(empty_fnum);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 if (buf != NULL && buf->b_nwindows == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 wipe_buffer(buf, TRUE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 // keep the previous alternate file
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum && !cmdmod.keepalt)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 curwin->w_alt_fnum = alt_fnum;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 erret:
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 vim_free(tag);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 * ":helpclose": Close one help window
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 ex_helpclose(exarg_T *eap UNUSED)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 win_T *win;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 FOR_ALL_WINDOWS(win)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 if (bt_help(win->w_buffer))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 win_close(win, FALSE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 #if defined(FEAT_MULTI_LANG) || defined(PROTO)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 * In an argument search for a language specifiers in the form "@xx".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 * Changes the "@" to NUL if found, and returns a pointer to "xx".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 * Returns NULL if not found.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 char_u *
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 check_help_lang(char_u *arg)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 int len = (int)STRLEN(arg);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 if (len >= 3 && arg[len - 3] == '@' && ASCII_ISALPHA(arg[len - 2])
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 && ASCII_ISALPHA(arg[len - 1]))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 arg[len - 3] = NUL; // remove the '@'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 return arg + len - 2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 return NULL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 * Return a heuristic indicating how well the given string matches. The
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 * smaller the number, the better the match. This is the order of priorities,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 * from best match to worst match:
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 * - Match with least alphanumeric characters is better.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 * - Match with least total characters is better.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 * - Match towards the start is better.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 * - Match starting with "+" is worse (feature instead of command)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 * Assumption is made that the matched_string passed has already been found to
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 * match some string for which help is requested. webb.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 int
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 help_heuristic(
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 char_u *matched_string,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 int offset, // offset for match
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 int wrong_case) // no matching case
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 int num_letters;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 char_u *p;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 num_letters = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 for (p = matched_string; *p; p++)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 if (ASCII_ISALNUM(*p))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 num_letters++;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 // Multiply the number of letters by 100 to give it a much bigger
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 // weighting than the number of characters.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 // If there only is a match while ignoring case, add 5000.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 // If the match starts in the middle of a word, add 10000 to put it
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 // somewhere in the last half.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 // If the match is more than 2 chars from the start, multiply by 200 to
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 // put it after matches at the start.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 if (ASCII_ISALNUM(matched_string[offset]) && offset > 0
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 && ASCII_ISALNUM(matched_string[offset - 1]))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 offset += 10000;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 else if (offset > 2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 offset *= 200;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 if (wrong_case)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 offset += 5000;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 // Features are less interesting than the subjects themselves, but "+"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 // alone is not a feature.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 if (matched_string[0] == '+' && matched_string[1] != NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 offset += 100;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 return (int)(100 * num_letters + STRLEN(matched_string) + offset);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 * Compare functions for qsort() below, that checks the help heuristics number
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 * that has been put after the tagname by find_tags().
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 static int
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 help_compare(const void *s1, const void *s2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 char *p1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 char *p2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 int cmp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 p1 = *(char **)s1 + strlen(*(char **)s1) + 1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 p2 = *(char **)s2 + strlen(*(char **)s2) + 1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 // Compare by help heuristic number first.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 cmp = strcmp(p1, p2);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 if (cmp != 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 return cmp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 // Compare by strings as tie-breaker when same heuristic number.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 return strcmp(*(char **)s1, *(char **)s2);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 * Find all help tags matching "arg", sort them and return in matches[], with
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 * the number of matches in num_matches.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 * The matches will be sorted with a "best" match algorithm.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 * When "keep_lang" is TRUE try keeping the language of the current buffer.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 int
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 find_help_tags(
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 char_u *arg,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 int *num_matches,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 char_u ***matches,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 int keep_lang)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 char_u *s, *d;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 int i;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 static char *(mtable[]) = {"*", "g*", "[*", "]*", ":*",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 "/*", "/\\*", "\"*", "**",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 "cpo-*", "/\\(\\)", "/\\%(\\)",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 "?", ":?", "?<CR>", "g?", "g?g?", "g??",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 "-?", "q?", "v_g?",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 "/\\?", "/\\z(\\)", "\\=", ":s\\=",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 "[count]", "[quotex]",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 "[range]", ":[range]",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 "[pattern]", "\\|", "\\%$",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 "s/\\~", "s/\\U", "s/\\L",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 "s/\\1", "s/\\2", "s/\\3", "s/\\9"};
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 static char *(rtable[]) = {"star", "gstar", "[star", "]star", ":star",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 "/star", "/\\\\star", "quotestar", "starstar",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 "cpo-star", "/\\\\(\\\\)", "/\\\\%(\\\\)",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 "?", ":?", "?<CR>", "g?", "g?g?", "g??",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 "-?", "q?", "v_g?",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 "/\\\\?", "/\\\\z(\\\\)", "\\\\=", ":s\\\\=",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 "\\[count]", "\\[quotex]",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 "\\[range]", ":\\[range]",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 "\\[pattern]", "\\\\bar", "/\\\\%\\$",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 "s/\\\\\\~", "s/\\\\U", "s/\\\\L",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 "s/\\\\1", "s/\\\\2", "s/\\\\3", "s/\\\\9"};
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 static char *(expr_table[]) = {"!=?", "!~?", "<=?", "<?", "==?", "=~?",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 ">=?", ">?", "is?", "isnot?"};
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 int flags;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 d = IObuff; // assume IObuff is long enough!
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 if (STRNICMP(arg, "expr-", 5) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 // When the string starting with "expr-" and containing '?' and matches
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 // the table, it is taken literally (but ~ is escaped). Otherwise '?'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 // is recognized as a wildcard.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 for (i = (int)(sizeof(expr_table) / sizeof(char *)); --i >= 0; )
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 if (STRCMP(arg + 5, expr_table[i]) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 int si = 0, di = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 for (;;)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 if (arg[si] == '~')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 d[di++] = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 d[di++] = arg[si];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 if (arg[si] == NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 ++si;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 // Recognize a few exceptions to the rule. Some strings that contain
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 // '*' with "star". Otherwise '*' is recognized as a wildcard.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 for (i = (int)(sizeof(mtable) / sizeof(char *)); --i >= 0; )
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 if (STRCMP(arg, mtable[i]) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 STRCPY(d, rtable[i]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 if (i < 0) // no match in table
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 // Replace "\S" with "/\\S", etc. Otherwise every tag is matched.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 // Also replace "\%^" and "\%(", they match every tag too.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 // Also "\zs", "\z1", etc.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 // Also "\@<", "\@=", "\@<=", etc.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 // And also "\_$" and "\_^".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 if (arg[0] == '\\'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 && ((arg[1] != NUL && arg[2] == NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 || (vim_strchr((char_u *)"%_z@", arg[1]) != NULL
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 && arg[2] != NUL)))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 STRCPY(d, "/\\\\");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 STRCPY(d + 3, arg + 1);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 // Check for "/\\_$", should be "/\\_\$"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 if (d[3] == '_' && d[4] == '$')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 STRCPY(d + 4, "\\$");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 // Replace:
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 // "[:...:]" with "\[:...:]"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 // "[++...]" with "\[++...]"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 // "\{" with "\\{" -- matching "} \}"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 if ((arg[0] == '[' && (arg[1] == ':'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 || (arg[1] == '+' && arg[2] == '+')))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 || (arg[0] == '\\' && arg[1] == '{'))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 *d++ = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 // If tag starts with "('", skip the "(". Fixes CTRL-] on ('option'.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 if (*arg == '(' && arg[1] == '\'')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 arg++;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 for (s = arg; *s; ++s)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 // Replace "|" with "bar" and '"' with "quote" to match the name of
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 // the tags for these commands.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 // Replace "*" with ".*" and "?" with "." to match command line
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 // completion.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 // Insert a backslash before '~', '$' and '.' to avoid their
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 // special meaning.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 if (d - IObuff > IOSIZE - 10) // getting too long!?
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 switch (*s)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 case '|': STRCPY(d, "bar");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 d += 3;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 case '"': STRCPY(d, "quote");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 d += 5;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 case '*': *d++ = '.';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 case '?': *d++ = '.';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 case '$':
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 case '.':
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 case '~': *d++ = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 // Replace "^x" by "CTRL-X". Don't do this for "^_" to make
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 // ":help i_^_CTRL-D" work.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 // Insert '-' before and after "CTRL-X" when applicable.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 if (*s < ' ' || (*s == '^' && s[1] && (ASCII_ISALPHA(s[1])
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 || vim_strchr((char_u *)"?@[\\]^", s[1]) != NULL)))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 if (d > IObuff && d[-1] != '_' && d[-1] != '\\')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 *d++ = '_'; // prepend a '_' to make x_CTRL-x
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 STRCPY(d, "CTRL-");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 d += 5;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 if (*s < ' ')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 #ifdef EBCDIC
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 *d++ = CtrlChar(*s);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 #else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 *d++ = *s + '@';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 if (d[-1] == '\\')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 *d++ = '\\'; // double a backslash
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 *d++ = *++s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 if (s[1] != NUL && s[1] != '_')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 *d++ = '_'; // append a '_'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 else if (*s == '^') // "^" or "CTRL-^" or "^_"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 *d++ = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 // Insert a backslash before a backslash after a slash, for search
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 // pattern tags: "/\|" --> "/\\|".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 else if (s[0] == '\\' && s[1] != '\\'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 && *arg == '/' && s == arg + 1)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 *d++ = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 // "CTRL-\_" -> "CTRL-\\_" to avoid the special meaning of "\_" in
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 // "CTRL-\_CTRL-N"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 if (STRNICMP(s, "CTRL-\\_", 7) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 STRCPY(d, "CTRL-\\\\");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 d += 7;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 s += 6;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 *d++ = *s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 // If tag contains "({" or "([", tag terminates at the "(".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 // This is for help on functions, e.g.: abs({expr}).
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 if (*s == '(' && (s[1] == '{' || s[1] =='['))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 // If tag starts with ', toss everything after a second '. Fixes
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 // CTRL-] on 'option'. (would include the trailing '.').
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 if (*s == '\'' && s > arg && *arg == '\'')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 // Also '{' and '}'.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 if (*s == '}' && s > arg && *arg == '{')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 *d = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 if (*IObuff == '`')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 if (d > IObuff + 2 && d[-1] == '`')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 // remove the backticks from `command`
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff));
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 d[-2] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 // remove the backticks and comma from `command`,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff));
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 d[-3] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 else if (d > IObuff + 4 && d[-3] == '`'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 && d[-2] == '\\' && d[-1] == '.')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 // remove the backticks and dot from `command`\.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff));
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 d[-4] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 *matches = (char_u **)"";
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 *num_matches = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 flags = TAG_HELP | TAG_REGEXP | TAG_NAMES | TAG_VERBOSE | TAG_NO_TAGFUNC;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 if (keep_lang)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 flags |= TAG_KEEP_LANG;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 && *num_matches > 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 // Sort the matches found on the heuristic number that is after the
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 // tag name.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 qsort((void *)*matches, (size_t)*num_matches,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 sizeof(char_u *), help_compare);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 // Delete more than TAG_MANY to reduce the size of the listing.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 while (*num_matches > TAG_MANY)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 vim_free((*matches)[--*num_matches]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 return OK;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 * Cleanup matches for help tags:
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 * Remove "@ab" if the top of 'helplang' is "ab" and the language of the first
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 * tag matches it. Otherwise remove "@en" if "en" is the only language.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 cleanup_help_tags(int num_file, char_u **file)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 int i, j;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 int len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 char_u buf[4];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 char_u *p = buf;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 if (p_hlg[0] != NUL && (p_hlg[0] != 'e' || p_hlg[1] != 'n'))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 *p++ = '@';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 *p++ = p_hlg[0];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 *p++ = p_hlg[1];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 *p = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 for (i = 0; i < num_file; ++i)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 len = (int)STRLEN(file[i]) - 3;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 if (len <= 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 if (STRCMP(file[i] + len, "@en") == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 // Sorting on priority means the same item in another language may
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 // be anywhere. Search all items for a match up to the "@en".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 for (j = 0; j < num_file; ++j)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 if (j != i && (int)STRLEN(file[j]) == len + 3
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 && STRNCMP(file[i], file[j], len + 1) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 if (j == num_file)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 // item only exists with @en, remove it
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 file[i][len] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 if (*buf != NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 for (i = 0; i < num_file; ++i)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 len = (int)STRLEN(file[i]) - 3;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 if (len <= 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 if (STRCMP(file[i] + len, buf) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 // remove the default language
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 file[i][len] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 * Called when starting to edit a buffer for a help file.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 prepare_help_buffer(void)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 char_u *p;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 curbuf->b_help = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 #ifdef FEAT_QUICKFIX
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 set_string_option_direct((char_u *)"buftype", -1,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 (char_u *)"help", OPT_FREE|OPT_LOCAL, 0);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 // Always set these options after jumping to a help tag, because the
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 // user may have an autocommand that gets in the way.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 // Accept all ASCII chars for keywords, except ' ', '*', '"', '|', and
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 // latin1 word characters (for translated help files).
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 // Only set it when needed, buf_init_chartab() is some work.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 p =
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 #ifdef EBCDIC
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 (char_u *)"65-255,^*,^|,^\"";
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 #else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 (char_u *)"!-~,^*,^|,^\",192-255";
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 if (STRCMP(curbuf->b_p_isk, p) != 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 set_string_option_direct((char_u *)"isk", -1, p, OPT_FREE|OPT_LOCAL, 0);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 check_buf_options(curbuf);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 (void)buf_init_chartab(curbuf, FALSE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 #ifdef FEAT_FOLDING
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 // Don't use the global foldmethod.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 OPT_FREE|OPT_LOCAL, 0);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 curbuf->b_p_ts = 8; // 'tabstop' is 8
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 curwin->w_p_list = FALSE; // no list mode
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 curbuf->b_p_ma = FALSE; // not modifiable
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 curbuf->b_p_bin = FALSE; // reset 'bin' before reading file
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 curwin->w_p_nu = 0; // no line numbers
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 curwin->w_p_rnu = 0; // no relative line numbers
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 RESET_BINDING(curwin); // no scroll or cursor binding
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 #ifdef FEAT_ARABIC
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 curwin->w_p_arab = FALSE; // no arabic mode
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 #ifdef FEAT_RIGHTLEFT
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 curwin->w_p_rl = FALSE; // help window is left-to-right
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 #ifdef FEAT_FOLDING
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 curwin->w_p_fen = FALSE; // No folding in the help window
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 #ifdef FEAT_DIFF
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 curwin->w_p_diff = FALSE; // No 'diff'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 #ifdef FEAT_SPELL
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 curwin->w_p_spell = FALSE; // No spell checking
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 set_buflisted(FALSE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 * After reading a help file: May cleanup a help buffer when syntax
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 * highlighting is not used.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 fix_help_buffer(void)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 linenr_T lnum;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 char_u *line;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 int in_example = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 int len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 char_u *fname;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 char_u *p;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 char_u *rt;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 int mustfree;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 // Set filetype to "help" if still needed.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 if (STRCMP(curbuf->b_p_ft, "help") != 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 ++curbuf_lock;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 set_option_value((char_u *)"ft", 0L, (char_u *)"help", OPT_LOCAL);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 --curbuf_lock;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 #ifdef FEAT_SYN_HL
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 if (!syntax_present(curwin))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 line = ml_get_buf(curbuf, lnum, FALSE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 len = (int)STRLEN(line);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 if (in_example && len > 0 && !VIM_ISWHITE(line[0]))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 // End of example: non-white or '<' in first column.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 if (line[0] == '<')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 // blank-out a '<' in the first column
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 line = ml_get_buf(curbuf, lnum, TRUE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 line[0] = ' ';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 in_example = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 if (!in_example && len > 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' '))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 // blank-out a '>' in the last column (start of example)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 line = ml_get_buf(curbuf, lnum, TRUE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 line[len - 1] = ' ';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 in_example = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 else if (line[len - 1] == '~')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 // blank-out a '~' at the end of line (header marker)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 line = ml_get_buf(curbuf, lnum, TRUE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 line[len - 1] = ' ';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 // In the "help.txt" and "help.abx" file, add the locally added help
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 // files. This uses the very first line in the help file.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 fname = gettail(curbuf->b_fname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 if (fnamecmp(fname, "help.txt") == 0
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 || (fnamencmp(fname, "help.", 5) == 0
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 && ASCII_ISALPHA(fname[5])
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 && ASCII_ISALPHA(fname[6])
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 && TOLOWER_ASC(fname[7]) == 'x'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 && fname[8] == NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 )
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 line = ml_get_buf(curbuf, lnum, FALSE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 if (strstr((char *)line, "*local-additions*") == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 // Go through all directories in 'runtimepath', skipping
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 // $VIMRUNTIME.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 p = p_rtp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 while (*p != NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 copy_option_part(&p, NameBuff, MAXPATHL, ",");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 mustfree = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 if (rt != NULL &&
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 fullpathcmp(rt, NameBuff, FALSE, TRUE) != FPC_SAME)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 int fcount;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 char_u **fnames;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 FILE *fd;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 char_u *s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 int fi;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 vimconv_T vc;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 char_u *cp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 // Find all "doc/ *.txt" files in this directory.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 add_pathsep(NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 STRCAT(NameBuff, "doc/*.??[tx]");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 #else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 STRCAT(NameBuff, "doc/*.txt");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 if (gen_expand_wildcards(1, &NameBuff, &fcount,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 &fnames, EW_FILE|EW_SILENT) == OK
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 && fcount > 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 int i1, i2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 char_u *f1, *f2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 char_u *t1, *t2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 char_u *e1, *e2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 // If foo.abx is found use it instead of foo.txt in
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 // the same directory.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 for (i1 = 0; i1 < fcount; ++i1)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 for (i2 = 0; i2 < fcount; ++i2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 if (i1 == i2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 if (fnames[i1] == NULL || fnames[i2] == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 f1 = fnames[i1];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 f2 = fnames[i2];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 t1 = gettail(f1);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 t2 = gettail(f2);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 e1 = vim_strrchr(t1, '.');
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 e2 = vim_strrchr(t2, '.');
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 if (e1 == NULL || e2 == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 if (fnamecmp(e1, ".txt") != 0
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 && fnamecmp(e1, fname + 4) != 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 // Not .txt and not .abx, remove it.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 VIM_CLEAR(fnames[i1]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 if (e1 - f1 != e2 - f2
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 || fnamencmp(f1, f2, e1 - f1) != 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 if (fnamecmp(e1, ".txt") == 0
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 && fnamecmp(e2, fname + 4) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 // use .abx instead of .txt
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 VIM_CLEAR(fnames[i1]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 for (fi = 0; fi < fcount; ++fi)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 if (fnames[fi] == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 fd = mch_fopen((char *)fnames[fi], "r");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 if (fd != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 vim_fgets(IObuff, IOSIZE, fd);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 if (IObuff[0] == '*'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 && (s = vim_strchr(IObuff + 1, '*'))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 int this_utf = MAYBE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 // Change tag definition to a
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 // reference and remove <CR>/<NL>.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 IObuff[0] = '|';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 *s = '|';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 while (*s != NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 if (*s == '\r' || *s == '\n')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 *s = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 // The text is utf-8 when a byte
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 // above 127 is found and no
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 // illegal byte sequence is found.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 if (*s >= 0x80 && this_utf != FALSE)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 int l;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 this_utf = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 l = utf_ptr2len(s);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 if (l == 1)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 this_utf = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 s += l - 1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 ++s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 // The help file is latin1 or utf-8;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 // conversion to the current
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 // 'encoding' may be required.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 vc.vc_type = CONV_NONE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 convert_setup(&vc, (char_u *)(
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 this_utf == TRUE ? "utf-8"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 : "latin1"), p_enc);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 if (vc.vc_type == CONV_NONE)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 // No conversion needed.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 cp = IObuff;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 // Do the conversion. If it fails
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 // use the unconverted text.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 cp = string_convert(&vc, IObuff,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 NULL);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 if (cp == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 cp = IObuff;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 convert_setup(&vc, NULL, NULL);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 ml_append(lnum, cp, (colnr_T)0, FALSE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 if (cp != IObuff)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 vim_free(cp);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 ++lnum;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 fclose(fd);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 FreeWild(fcount, fnames);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 if (mustfree)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 vim_free(rt);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 * ":exusage"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 ex_exusage(exarg_T *eap UNUSED)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 do_cmdline_cmd((char_u *)"help ex-cmd-index");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 * ":viusage"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 ex_viusage(exarg_T *eap UNUSED)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 do_cmdline_cmd((char_u *)"help normal-index");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 * Generate tags in one help directory.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 static void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 helptags_one(
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 char_u *dir, // doc directory
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 char_u *ext, // suffix, ".txt", ".itx", ".frx", etc.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 char_u *tagfname, // "tags" for English, "tags-fr" for French.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 int add_help_tags, // add "help-tags" tag
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 int ignore_writeerr) // ignore write error
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 FILE *fd_tags;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 FILE *fd;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 garray_T ga;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 int filecount;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 char_u **files;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 char_u *p1, *p2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 int fi;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 char_u *s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 int i;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 char_u *fname;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 int dirlen;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 int utf8 = MAYBE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 int this_utf8;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 int firstline;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 int mix = FALSE; // detected mixed encodings
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 // Find all *.txt files.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 dirlen = (int)STRLEN(dir);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 STRCPY(NameBuff, dir);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 STRCAT(NameBuff, "/**/*");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 STRCAT(NameBuff, ext);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 if (gen_expand_wildcards(1, &NameBuff, &filecount, &files,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 EW_FILE|EW_SILENT) == FAIL
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 || filecount == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 if (!got_int)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 semsg(_("E151: No match: %s"), NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 // Open the tags file for writing.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 // Do this before scanning through all the files.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 STRCPY(NameBuff, dir);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 add_pathsep(NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 STRCAT(NameBuff, tagfname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 fd_tags = mch_fopen((char *)NameBuff, "w");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 if (fd_tags == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 if (!ignore_writeerr)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 semsg(_("E152: Cannot open %s for writing"), NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 FreeWild(filecount, files);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 // If using the "++t" argument or generating tags for "$VIMRUNTIME/doc"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 // add the "help-tags" tag.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 ga_init2(&ga, (int)sizeof(char_u *), 100);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 if (add_help_tags || fullpathcmp((char_u *)"$VIMRUNTIME/doc",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 dir, FALSE, TRUE) == FPC_SAME)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 if (ga_grow(&ga, 1) == FAIL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 s = alloc(18 + (unsigned)STRLEN(tagfname));
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 if (s == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 sprintf((char *)s, "help-tags\t%s\t1\n", tagfname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 ((char_u **)ga.ga_data)[ga.ga_len] = s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 ++ga.ga_len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 // Go over all the files and extract the tags.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 for (fi = 0; fi < filecount && !got_int; ++fi)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 fd = mch_fopen((char *)files[fi], "r");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 if (fd == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 semsg(_("E153: Unable to open %s for reading"), files[fi]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 fname = files[fi] + dirlen + 1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 firstline = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 if (firstline)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 // Detect utf-8 file by a non-ASCII char in the first line.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 this_utf8 = MAYBE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 for (s = IObuff; *s != NUL; ++s)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 if (*s >= 0x80)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 int l;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 this_utf8 = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 l = utf_ptr2len(s);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 if (l == 1)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 // Illegal UTF-8 byte sequence.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 this_utf8 = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 s += l - 1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 if (this_utf8 == MAYBE) // only ASCII characters found
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 this_utf8 = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 if (utf8 == MAYBE) // first file
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 utf8 = this_utf8;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 else if (utf8 != this_utf8)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 semsg(_("E670: Mix of help file encodings within a language: %s"), files[fi]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 mix = !got_int;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 firstline = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 p1 = vim_strchr(IObuff, '*'); // find first '*'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 while (p1 != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 // Use vim_strbyte() instead of vim_strchr() so that when
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 // 'encoding' is dbcs it still works, don't find '*' in the
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 // second byte.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 p2 = vim_strbyte(p1 + 1, '*'); // find second '*'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 if (p2 != NULL && p2 > p1 + 1) // skip "*" and "**"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 for (s = p1 + 1; s < p2; ++s)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 if (*s == ' ' || *s == '\t' || *s == '|')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 // Only accept a *tag* when it consists of valid
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 // characters, there is white space before it and is
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 // followed by a white character or end-of-line.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 if (s == p2
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 && (p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 && (vim_strchr((char_u *)" \t\n\r", s[1]) != NULL
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 || s[1] == '\0'))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 *p2 = '\0';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 ++p1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 if (ga_grow(&ga, 1) == FAIL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 s = alloc(p2 - p1 + STRLEN(fname) + 2);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 if (s == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 ((char_u **)ga.ga_data)[ga.ga_len] = s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 ++ga.ga_len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 sprintf((char *)s, "%s\t%s", p1, fname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 // find next '*'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 p2 = vim_strchr(p2 + 1, '*');
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 p1 = p2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 line_breakcheck();
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 fclose(fd);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 FreeWild(filecount, files);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 if (!got_int)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 // Sort the tags.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 if (ga.ga_data != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 sort_strings((char_u **)ga.ga_data, ga.ga_len);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 // Check for duplicates.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 for (i = 1; i < ga.ga_len; ++i)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 p1 = ((char_u **)ga.ga_data)[i - 1];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 p2 = ((char_u **)ga.ga_data)[i];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 while (*p1 == *p2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 if (*p2 == '\t')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 *p2 = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 vim_snprintf((char *)NameBuff, MAXPATHL,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 _("E154: Duplicate tag \"%s\" in file %s/%s"),
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 ((char_u **)ga.ga_data)[i], dir, p2 + 1);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 emsg((char *)NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 *p2 = '\t';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 ++p1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 ++p2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 if (utf8 == TRUE)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 // Write the tags into the file.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 for (i = 0; i < ga.ga_len; ++i)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 s = ((char_u **)ga.ga_data)[i];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 if (STRNCMP(s, "help-tags\t", 10) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 // help-tags entry was added in formatted form
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 fputs((char *)s, fd_tags);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 fprintf(fd_tags, "%s\t/*", s);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 for (p1 = s; *p1 != '\t'; ++p1)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 // insert backslash before '\\' and '/'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 if (*p1 == '\\' || *p1 == '/')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 putc('\\', fd_tags);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 putc(*p1, fd_tags);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 fprintf(fd_tags, "*\n");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 if (mix)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 got_int = FALSE; // continue with other languages
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 for (i = 0; i < ga.ga_len; ++i)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 vim_free(((char_u **)ga.ga_data)[i]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 ga_clear(&ga);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 fclose(fd_tags); // there is no check for an error...
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 * Generate tags in one help directory, taking care of translations.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 static void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 do_helptags(char_u *dirname, int add_help_tags, int ignore_writeerr)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 #ifdef FEAT_MULTI_LANG
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 int len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 int i, j;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 garray_T ga;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 char_u lang[2];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 char_u ext[5];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 char_u fname[8];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 int filecount;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 char_u **files;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 // Get a list of all files in the help directory and in subdirectories.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 STRCPY(NameBuff, dirname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 add_pathsep(NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 STRCAT(NameBuff, "**");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 if (gen_expand_wildcards(1, &NameBuff, &filecount, &files,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 EW_FILE|EW_SILENT) == FAIL
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 || filecount == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 semsg(_("E151: No match: %s"), NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 // Go over all files in the directory to find out what languages are
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 // present.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 ga_init2(&ga, 1, 10);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 for (i = 0; i < filecount; ++i)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 len = (int)STRLEN(files[i]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 if (len > 4)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 if (STRICMP(files[i] + len - 4, ".txt") == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 // ".txt" -> language "en"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 lang[0] = 'e';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 lang[1] = 'n';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 else if (files[i][len - 4] == '.'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 && ASCII_ISALPHA(files[i][len - 3])
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 && ASCII_ISALPHA(files[i][len - 2])
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 && TOLOWER_ASC(files[i][len - 1]) == 'x')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 // ".abx" -> language "ab"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 lang[0] = TOLOWER_ASC(files[i][len - 3]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 lang[1] = TOLOWER_ASC(files[i][len - 2]);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 // Did we find this language already?
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 for (j = 0; j < ga.ga_len; j += 2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 if (j == ga.ga_len)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 // New language, add it.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 if (ga_grow(&ga, 2) == FAIL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 ((char_u *)ga.ga_data)[ga.ga_len++] = lang[1];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 // Loop over the found languages to generate a tags file for each one.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 for (j = 0; j < ga.ga_len; j += 2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 STRCPY(fname, "tags-xx");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 fname[5] = ((char_u *)ga.ga_data)[j];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 fname[6] = ((char_u *)ga.ga_data)[j + 1];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 if (fname[5] == 'e' && fname[6] == 'n')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 // English is an exception: use ".txt" and "tags".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 fname[4] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 STRCPY(ext, ".txt");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 // Language "ab" uses ".abx" and "tags-ab".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 STRCPY(ext, ".xxx");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 ext[1] = fname[5];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 ext[2] = fname[6];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 helptags_one(dirname, ext, fname, add_help_tags, ignore_writeerr);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 ga_clear(&ga);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 FreeWild(filecount, files);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 #else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 // No language support, just use "*.txt" and "tags".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 helptags_one(dirname, (char_u *)".txt", (char_u *)"tags", add_help_tags,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 ignore_writeerr);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 static void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 helptags_cb(char_u *fname, void *cookie)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 do_helptags(fname, *(int *)cookie, TRUE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 * ":helptags"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 ex_helptags(exarg_T *eap)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 expand_T xpc;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 char_u *dirname;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 int add_help_tags = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 // Check for ":helptags ++t {dir}".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 if (STRNCMP(eap->arg, "++t", 3) == 0 && VIM_ISWHITE(eap->arg[3]))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 add_help_tags = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 eap->arg = skipwhite(eap->arg + 3);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 if (STRCMP(eap->arg, "ALL") == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 do_in_path(p_rtp, (char_u *)"doc", DIP_ALL + DIP_DIR,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 helptags_cb, &add_help_tags);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 ExpandInit(&xpc);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 xpc.xp_context = EXPAND_DIRECTORIES;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 dirname = ExpandOne(&xpc, eap->arg, NULL,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 if (dirname == NULL || !mch_isdir(dirname))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 semsg(_("E150: Not a directory: %s"), eap->arg);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 do_helptags(dirname, add_help_tags, FALSE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 vim_free(dirname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 }