vim: resync with upstream, update to 8.0.0104
[unleashed-userland.git] / components / editor / vim / patches / vim-help.patch
blob914479efd6bfd274ef483199f3aebabba2e0d3a5
1 --- a/src/ex_cmds.c 2016-09-21 15:16:13.032570431 -0700
2 +++ b/src/ex_cmds.c 2016-09-21 15:16:13.055466074 -0700
3 @@ -6276,6 +6276,8 @@
4 #ifdef FEAT_FOLDING
5 int old_KeyTyped = KeyTyped;
6 #endif
7 + int nohelp = FALSE, nominhelp = FALSE;
8 + char_u *mhf = NULL;
10 if (eap != NULL)
12 @@ -6327,6 +6329,23 @@
13 n = find_help_tags(arg, &num_matches, &matches,
14 eap != NULL && eap->forceit);
16 + /*
17 + * If we didn't find the help topic, check to see whether 'helpfile'
18 + * (typically $VIMRUNTIME/doc/help.txt) exists. If not, then we'll send the
19 + * user to the minimized help file delivered with the core vim package which
20 + * explains why there's no help and how to get it.
21 + */
22 + if (num_matches == 0 && mch_access((char *)p_hf, F_OK) < 0) {
23 + nohelp = TRUE;
24 + mhf = alloc(MAXPATHL);
25 + STRNCPY(mhf, p_hf, MAXPATHL - 1);
26 + mhf[STRLEN(mhf) - 8] = '\0';
27 + STRNCAT(mhf, "help_minimized.txt", MAXPATHL - STRLEN(mhf) - 1);
29 + if (mch_access((char *)mhf, F_OK) < 0)
30 + nominhelp = TRUE;
31 + }
33 i = 0;
34 #ifdef FEAT_MULTI_LANG
35 if (n != FAIL && lang != NULL)
36 @@ -6339,7 +6358,7 @@
37 break;
39 #endif
40 - if (i >= num_matches || n == FAIL)
41 + if (!nohelp && i >= num_matches || n == FAIL)
43 #ifdef FEAT_MULTI_LANG
44 if (lang != NULL)
45 @@ -6352,9 +6371,11 @@
46 return;
49 - /* The first match (in the requested language) is the best match. */
50 - tag = vim_strsave(matches[i]);
51 - FreeWild(num_matches, matches);
52 + if (!nohelp) {
53 + /* The first match (in the requested language) is the best match. */
54 + tag = vim_strsave(matches[i]);
55 + FreeWild(num_matches, matches);
56 + }
58 #ifdef FEAT_GUI
59 need_mouse_correct = TRUE;
60 @@ -6386,12 +6407,14 @@
61 * There is no help window yet.
62 * Try to open the file specified by the "helpfile" option.
64 - if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL)
65 - {
66 - smsg((char_u *)_("Sorry, help file \"%s\" not found"), p_hf);
67 - goto erret;
68 + if (!nohelp || nominhelp) {
69 + if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL)
70 + {
71 + smsg((char_u *)_("Sorry, help file \"%s\" not found"), p_hf);
72 + goto erret;
73 + }
74 + fclose(helpfd);
76 - fclose(helpfd);
78 #ifdef FEAT_WINDOWS
79 /* Split off help window; put it at far top if no position
80 @@ -6420,7 +6443,7 @@
81 * Set the alternate file to the previously edited file.
83 alt_fnum = curbuf->b_fnum;
84 - (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL,
85 + (void)do_ecmd(0, mhf, NULL, NULL, ECMD_LASTL,
86 ECMD_HIDE + ECMD_SET_HELP,
87 #ifdef FEAT_WINDOWS
88 NULL /* buffer is still open, don't store info */
89 @@ -6443,7 +6466,7 @@
90 KeyTyped = old_KeyTyped;
91 #endif
93 - if (tag != NULL)
94 + if (!nohelp && tag != NULL)
95 do_tag(tag, DT_HELP, 1, FALSE, TRUE);
97 /* Delete the empty buffer if we're not using it. Careful: autocommands
98 @@ -6461,7 +6484,8 @@
99 curwin->w_alt_fnum = alt_fnum;
101 erret:
102 - vim_free(tag);
103 + if (!nohelp)
104 + vim_free(tag);