annotate src/help.c @ 21629:87a1c4717817

Added tag v8.2.1364 for changeset e23f829c187df363c6531203c4a47109ab1b3cdc
author Bram Moolenaar <Bram@vim.org>
date Tue, 04 Aug 2020 22:00:05 +0200
parents 5db63c2c6929
children 81ae5fa92928
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
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 if (eap != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 // 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
45 // 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
46 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
47 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 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
49 || (*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
50 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 *arg++ = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 eap->nextcmd = arg;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 arg = eap->arg;
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 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
59 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 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
61 return;
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
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 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
65 return;
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 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 arg = (char_u *)"";
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 // remove trailing blanks
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 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
72 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
73 *p-- = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 #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
76 // 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
77 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
78 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 // 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
81 if (*arg == NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 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
83
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 // 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
85 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
86 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
87
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 i = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 #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
90 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
91 // 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
92 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
93 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 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
95 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
96 && 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
97 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 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
101 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 #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
103 if (lang != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 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
105 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 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
108 if (n != FAIL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 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
110 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 // 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
114 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
115 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
116
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 #ifdef FEAT_GUI
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 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
119 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 // 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
122 // 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
123 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
124 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 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
126 wp = NULL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 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
129 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
130 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 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
132 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
133 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 // 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
136 // 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
137 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
138 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 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
140 goto erret;
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 fclose(helpfd);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 // 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
145 // 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
146 // narrow.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 n = WSP_HELP;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 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
149 && 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
150 n |= WSP_TOP;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 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
152 goto erret;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 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
155 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
156
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 // 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
158 // 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
159 // 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
160 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
161 (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
162 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
163 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
164 if (!cmdmod.keepalt)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 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
166 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
167 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 if (!p_im)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 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
172
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 #ifdef FEAT_FOLDING
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 // 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
175 // 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
176 KeyTyped = old_KeyTyped;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 if (tag != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 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
181
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 // 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
183 // 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
184 // window.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 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
186 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 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
188 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
189 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
190 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 // 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
193 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
194 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
195
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 erret:
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 vim_free(tag);
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
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 * ":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
202 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 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
205 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 win_T *win;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 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
209 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 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
211 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 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
213 return;
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 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 }
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 #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
219 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 * 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
221 * 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
222 * 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
223 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 char_u *
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 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
226 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 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
228
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 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
230 && 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
231 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 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
233 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
234 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 return NULL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238
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 * 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
241 * 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
242 * 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
243 * - 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
244 * - 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
245 * - 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
246 * - 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
247 * 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
248 * 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
249 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 int
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 help_heuristic(
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 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
253 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
254 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
255 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 int num_letters;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 char_u *p;
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 num_letters = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 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
261 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
262 num_letters++;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 // 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
265 // 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
266 // 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
267 // 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
268 // 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
269 // 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
270 // 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
271 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
272 && 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
273 offset += 10000;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 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
275 offset *= 200;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 if (wrong_case)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 offset += 5000;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 // 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
279 // 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
280 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
281 offset += 100;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 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
283 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 * 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
287 * 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
288 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 static int
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 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
291 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 char *p1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 char *p2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 int cmp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 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
297 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
298
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 // 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
300 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
301 if (cmp != 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 return cmp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 // 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
305 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
306 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 * 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
310 * 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
311 * 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
312 * 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
313 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 int
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 find_help_tags(
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 char_u *arg,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 int *num_matches,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 char_u ***matches,
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 int keep_lang)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 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
322 int i;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 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
324 "/*", "/\\*", "\"*", "**",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 "cpo-*", "/\\(\\)", "/\\%(\\)",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 "?", ":?", "?<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
327 "-?", "q?", "v_g?",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 "/\\?", "/\\z(\\)", "\\=", ":s\\=",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 "[count]", "[quotex]",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 "[range]", ":[range]",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 "[pattern]", "\\|", "\\%$",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 "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
333 "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
334 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
335 "/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
336 "cpo-star", "/\\\\(\\\\)", "/\\\\%(\\\\)",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 "?", ":?", "?<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
338 "-?", "q?", "v_g?",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 "/\\\\?", "/\\\\z(\\\\)", "\\\\=", ":s\\\\=",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 "\\[count]", "\\[quotex]",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 "\\[range]", ":\\[range]",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 "\\[pattern]", "\\\\bar", "/\\\\%\\$",
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 "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
344 "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
345 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
346 ">=?", ">?", "is?", "isnot?"};
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 int flags;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 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
350
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 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
352 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 // 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
354 // 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
355 // 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
356 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
357 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
358 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 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
360
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 for (;;)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 if (arg[si] == '~')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 d[di++] = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 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
366 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
367 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 ++si;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 }
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 }
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 else
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 // 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
376 // '*' 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
377 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
378 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
379 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 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
381 break;
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 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 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
386 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 // 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
388 // 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
389 // 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
390 // Also "\@<", "\@=", "\@<=", etc.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 // And also "\_$" and "\_^".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 if (arg[0] == '\\'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 && ((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
394 || (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
395 && arg[2] != NUL)))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 STRCPY(d, "/\\\\");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 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
399 // 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
400 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
401 STRCPY(d + 4, "\\$");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 // Replace:
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 // "[:...:]" with "\[:...:]"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 // "[++...]" with "\[++...]"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 // "\{" with "\\{" -- matching "} \}"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 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
410 || (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
411 || (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
412 *d++ = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 // 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
415 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
416 arg++;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 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
418 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 // 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
420 // 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
421 // 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
422 // completion.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 // 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
424 // special meaning.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 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
426 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 switch (*s)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 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
430 d += 3;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 continue;
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, "quote");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 d += 5;
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 '*': *d++ = '.';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 case '?': *d++ = '.';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 case '$':
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 case '.':
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 case '~': *d++ = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 // 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
446 // ":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
447 // 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
448 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
449 || 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
450 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 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
452 *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
453 STRCPY(d, "CTRL-");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 d += 5;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 if (*s < ' ')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 #ifdef EBCDIC
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 *d++ = CtrlChar(*s);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 #else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 *d++ = *s + '@';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 if (d[-1] == '\\')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 *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
464 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 *d++ = *++s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 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
468 *d++ = '_'; // append a '_'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 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
472 *d++ = '\\';
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 // 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
475 // pattern tags: "/\|" --> "/\\|".
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 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
477 && *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
478 *d++ = '\\';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 // "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
481 // "CTRL-\_CTRL-N"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 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
483 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 STRCPY(d, "CTRL-\\\\");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 d += 7;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 s += 6;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 *d++ = *s;
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 // 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
492 // 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
493 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
494 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 // 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
497 // 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
498 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
499 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 // Also '{' and '}'.
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 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 *d = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 if (*IObuff == '`')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 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
509 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 // 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
511 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
512 d[-2] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 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
515 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 // 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
517 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
518 d[-3] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 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
521 && 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
522 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 // 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
524 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
525 d[-4] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 }
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 *matches = (char_u **)"";
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 *num_matches = 0;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 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
534 if (keep_lang)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 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
536 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
537 && *num_matches > 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 // 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
540 // tag name.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 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
542 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
543 // 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
544 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
545 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
546 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 return OK;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 }
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 #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
551 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 * 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
553 * 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
554 * 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
555 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 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
558 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 int i, j;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 int len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 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
562 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
563
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 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
565 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 *p++ = '@';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 *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
568 *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
569 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 *p = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 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
573 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 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
575 if (len <= 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 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
578 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 // 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
580 // 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
581 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
582 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
583 && 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
584 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 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
586 // 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
587 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
588 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 if (*buf != NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 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
593 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 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
595 if (len <= 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 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
598 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 // 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
600 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
601 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 #endif
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 * 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
608 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 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
611 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 char_u *p;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 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
615 #ifdef FEAT_QUICKFIX
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 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
617 (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
618 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 // 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
621 // 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
622 // 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
623 // 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
624 // 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
625 p =
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 #ifdef EBCDIC
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 (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
628 #else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 (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
630 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 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
632 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 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
634 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
635 (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
636 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 #ifdef FEAT_FOLDING
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 // 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
640 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
641 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
642 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 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
645 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
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_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
648 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
649 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
650 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
651 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
652 #ifdef FEAT_ARABIC
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_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
654 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 #ifdef FEAT_RIGHTLEFT
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_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
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_FOLDING
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_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
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_DIFF
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_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
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_SPELL
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_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
666 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 set_buflisted(FALSE);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 }
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 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 * 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
673 * 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
674 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 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
677 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 linenr_T lnum;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 char_u *line;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 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
681 int len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 char_u *fname;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 char_u *p;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 char_u *rt;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 int mustfree;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 // 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
688 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
689 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 ++curbuf_lock;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 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
692 --curbuf_lock;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 #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
696 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
697 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 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
700 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 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
702 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
703 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
704 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 // 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
706 if (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 // 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
709 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
710 line[0] = ' ';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 in_example = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 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
715 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 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
717 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 // 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
719 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
720 line[len - 1] = ' ';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 in_example = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 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
724 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 // 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
726 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
727 line[len - 1] = ' ';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 }
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 // 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
734 // 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
735 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
736 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
737 #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
738 || (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
739 && 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
740 && 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
741 && 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
742 && fname[8] == NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 )
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 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
747 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 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
749 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
750 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 // 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
753 // $VIMRUNTIME.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 p = p_rtp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 while (*p != NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 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
758 mustfree = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 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
760 if (rt != NULL &&
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 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
762 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 int fcount;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 char_u **fnames;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 FILE *fd;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 char_u *s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 int fi;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 vimconv_T vc;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 char_u *cp;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 // 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
772 add_pathsep(NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 #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
774 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
775 #else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 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
777 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 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
779 &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
780 && fcount > 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 #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
783 int i1, i2;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 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
785 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
786 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
787
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 // 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
789 // the same directory.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 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
791 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 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
793 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 if (i1 == i2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 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
797 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 f1 = fnames[i1];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 f2 = fnames[i2];
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 t1 = gettail(f1);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 t2 = gettail(f2);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 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
803 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
804 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
805 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 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
807 && 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
808 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 // 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
810 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
811 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 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
814 || 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
815 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 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
817 && 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
818 // 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
819 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
820 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 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
824 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 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
826 continue;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 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
828 if (fd != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 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
831 if (IObuff[0] == '*'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 && (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
833 != NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 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
836
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 // 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
838 // 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
839 IObuff[0] = '|';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 *s = '|';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 while (*s != NUL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 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
844 *s = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 // 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
846 // 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
847 // 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
848 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
849 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 int l;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 this_utf = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 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
854 if (l == 1)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 this_utf = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 s += l - 1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 ++s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 }
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 // 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
862 // 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
863 // '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
864 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
865 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
866 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
867 : "latin1"), p_enc);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 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
869 // No conversion needed.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 cp = IObuff;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 // 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
874 // 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
875 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
876 NULL);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 if (cp == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 cp = IObuff;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 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
881
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 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
883 if (cp != IObuff)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 vim_free(cp);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 ++lnum;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 fclose(fd);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 }
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 FreeWild(fcount, fnames);
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 if (mustfree)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 vim_free(rt);
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 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 }
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 }
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 * ":exusage"
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 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 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
906 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 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
908 }
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 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 * ":viusage"
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 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 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
915 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 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
917 }
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 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 * 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
921 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 static void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 helptags_one(
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 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
925 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
926 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
927 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
928 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
929 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 FILE *fd_tags;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 FILE *fd;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 garray_T ga;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 int filecount;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 char_u **files;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 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
936 int fi;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 char_u *s;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 int i;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 char_u *fname;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 int dirlen;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 int utf8 = MAYBE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 int this_utf8;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 int firstline;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 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
945
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 // 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
947 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
948 STRCPY(NameBuff, dir);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 STRCAT(NameBuff, "/**/*");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 STRCAT(NameBuff, ext);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 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
952 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
953 || filecount == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 if (!got_int)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 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
957 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 // 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
961 // 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
962 STRCPY(NameBuff, dir);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 add_pathsep(NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 STRCAT(NameBuff, tagfname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 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
966 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
967 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 if (!ignore_writeerr)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 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
970 FreeWild(filecount, files);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 return;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 // 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
975 // 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
976 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
977 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
978 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
979 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 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
981 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 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
985 if (s == NULL)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 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
990 ((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
991 ++ga.ga_len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 }
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 // 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
997 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
998 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 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
1000 if (fd == NULL)
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 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
1003 continue;
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 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
1006
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 firstline = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 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
1009 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 if (firstline)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 // 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
1013 this_utf8 = MAYBE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 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
1015 if (*s >= 0x80)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 int l;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 this_utf8 = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 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
1021 if (l == 1)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 // 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
1024 this_utf8 = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 s += l - 1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 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
1030 this_utf8 = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 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
1032 utf8 = this_utf8;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 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
1034 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 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
1036 mix = !got_int;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 firstline = FALSE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 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
1042 while (p1 != NULL)
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 // 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
1045 // '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
1046 // second byte.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 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
1048 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
1049 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 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
1051 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
1052 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 // 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
1055 // 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
1056 // 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
1057 if (s == p2
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 && (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
1059 && (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
1060 || s[1] == '\0'))
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 *p2 = '\0';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 ++p1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 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
1065 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 break;
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 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
1070 if (s == NULL)
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 got_int = TRUE;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 break;
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 ((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
1076 ++ga.ga_len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 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
1078
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 // find next '*'
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 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
1081 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 p1 = p2;
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 line_breakcheck();
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 }
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 fclose(fd);
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 FreeWild(filecount, files);
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 if (!got_int)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 // Sort the tags.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 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
1097 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
1098
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 // Check for duplicates.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 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
1101 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 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
1103 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
1104 while (*p1 == *p2)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 if (*p2 == '\t')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 *p2 = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 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
1110 _("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
1111 ((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
1112 emsg((char *)NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 *p2 = '\t';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 ++p1;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 ++p2;
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 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 if (utf8 == TRUE)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 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
1123
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 // 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
1125 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
1126 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 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
1128 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
1129 // 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
1130 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
1131 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 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
1134 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
1135 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 // 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
1137 if (*p1 == '\\' || *p1 == '/')
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 putc('\\', fd_tags);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 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
1140 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 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
1142 }
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 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 if (mix)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 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
1147
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 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
1149 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
1150 ga_clear(&ga);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 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
1152 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 * 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
1156 */
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 static void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 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
1159 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 #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
1161 int len;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 int i, j;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 garray_T ga;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 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
1165 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
1166 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
1167 int filecount;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 char_u **files;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 // 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
1171 STRCPY(NameBuff, dirname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 add_pathsep(NameBuff);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 STRCAT(NameBuff, "**");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 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
1175 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
1176 || filecount == 0)
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 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
1179 return;
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
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 // 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
1183 // present.
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 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
1185 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
1186 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 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
1188 if (len > 4)
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 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
1191 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 // ".txt" -> language "en"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 lang[0] = 'e';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 lang[1] = 'n';
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 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
1197 && 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
1198 && 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
1199 && 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
1200 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 // ".abx" -> language "ab"
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 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
1203 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
1204 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 continue;
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 // 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
1209 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
1210 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
1211 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 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
1213 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 // 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
1215 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
1216 break;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 ((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
1218 ((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
1219 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 }
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 // 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
1224 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
1225 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 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
1227 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
1228 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
1229 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
1230 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 // 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
1232 fname[4] = NUL;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 STRCPY(ext, ".txt");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 // 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
1238 STRCPY(ext, ".xxx");
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 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
1240 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
1241 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 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
1243 }
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 ga_clear(&ga);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 FreeWild(filecount, files);
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 #else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 // 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
1250 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
1251 ignore_writeerr);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 #endif
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 static void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 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
1257 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 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
1259 }
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 /*
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 * ":helptags"
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 void
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 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
1266 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 expand_T xpc;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 char_u *dirname;
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 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
1270
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 // 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
1272 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
1273 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 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
1275 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
1276 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 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
1279 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 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
1281 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
1282 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 {
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 ExpandInit(&xpc);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 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
1287 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
1288 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
1289 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
1290 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
1291 else
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 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
1293 vim_free(dirname);
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 }
5db63c2c6929 patch 8.2.1262: src/ex_cmds.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 }