vim-help.patch revision 379
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw--- src/ex_cmds.c Thu Apr 21 16:23:08 2011
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+++ src/ex_cmds.c Thu Apr 21 16:23:08 2011
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw@@ -5525,6 +5525,8 @@
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw int len;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char_u *lang;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw #endif
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ int nohelp = FALSE, nominhelp = FALSE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ char_u *mhf = NULL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (eap != NULL)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw@@ -5576,6 +5578,23 @@
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw n = find_help_tags(arg, &num_matches, &matches,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw eap != NULL && eap->forceit);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ /*
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ * If we didn't find the help topic, check to see whether 'helpfile'
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ * (typically $VIMRUNTIME/doc/help.txt) exists. If not, then we'll send the
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ * user to the minimized help file delivered with the core vim package which
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ * explains why there's no help and how to get it.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ if (num_matches == 0 && mch_access((char *)p_hf, F_OK) < 0) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ nohelp = TRUE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ mhf = alloc(MAXPATHL);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ STRNCPY(mhf, p_hf, MAXPATHL - 1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ mhf[STRLEN(mhf) - 8] = '\0';
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ STRNCAT(mhf, "help_minimized.txt", MAXPATHL - STRLEN(mhf) - 1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ if (mch_access((char *)mhf, F_OK) < 0)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ nominhelp = TRUE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+ }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw+
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw i = 0;
#ifdef FEAT_MULTI_LANG
if (n != FAIL && lang != NULL)
@@ -5588,7 +5607,7 @@
break;
}
#endif
- if (i >= num_matches || n == FAIL)
+ if (!nohelp && i >= num_matches || n == FAIL)
{
#ifdef FEAT_MULTI_LANG
if (lang != NULL)
@@ -5601,9 +5620,11 @@
return;
}
- /* The first match (in the requested language) is the best match. */
- tag = vim_strsave(matches[i]);
- FreeWild(num_matches, matches);
+ if (!nohelp) {
+ /* The first match (in the requested language) is the best match. */
+ tag = vim_strsave(matches[i]);
+ FreeWild(num_matches, matches);
+ }
#ifdef FEAT_GUI
need_mouse_correct = TRUE;
@@ -5635,12 +5656,14 @@
* There is no help window yet.
* Try to open the file specified by the "helpfile" option.
*/
- if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL)
- {
- smsg((char_u *)_("Sorry, help file \"%s\" not found"), p_hf);
- goto erret;
+ if (!nohelp || nominhelp) {
+ if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL)
+ {
+ smsg((char_u *)_("Sorry, help file \"%s\" not found"), p_hf);
+ goto erret;
+ }
+ fclose(helpfd);
}
- fclose(helpfd);
#ifdef FEAT_WINDOWS
/* Split off help window; put it at far top if no position
@@ -5671,7 +5694,7 @@
* Set the alternate file to the previously edited file.
*/
alt_fnum = curbuf->b_fnum;
- (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL,
+ (void)do_ecmd(0, mhf, NULL, NULL, ECMD_LASTL,
ECMD_HIDE + ECMD_SET_HELP,
#ifdef FEAT_WINDOWS
NULL /* buffer is still open, don't store info */
@@ -5688,7 +5711,7 @@
if (!p_im)
restart_edit = 0; /* don't want insert mode in help file */
- if (tag != NULL)
+ if (!nohelp && tag != NULL)
do_tag(tag, DT_HELP, 1, FALSE, TRUE);
/* Delete the empty buffer if we're not using it. Careful: autocommands
@@ -5706,7 +5729,8 @@
curwin->w_alt_fnum = alt_fnum;
erret:
- vim_free(tag);
+ if (!nohelp)
+ vim_free(tag);
}