components/vim/patches/vim-help.patch
changeset 379 c6a17bba1da3
child 7049 e8d705cba87d
equal deleted inserted replaced
378:f0b61ed1d10d 379:c6a17bba1da3
       
     1 --- src/ex_cmds.c	Thu Apr 21 16:23:08 2011
       
     2 +++ src/ex_cmds.c	Thu Apr 21 16:23:08 2011
       
     3 @@ -5525,6 +5525,8 @@
       
     4      int		len;
       
     5      char_u	*lang;
       
     6  #endif
       
     7 +    int		nohelp = FALSE, nominhelp = FALSE;
       
     8 +    char_u	*mhf = NULL;
       
     9  
       
    10      if (eap != NULL)
       
    11      {
       
    12 @@ -5576,6 +5578,23 @@
       
    13      n = find_help_tags(arg, &num_matches, &matches,
       
    14  						 eap != NULL && eap->forceit);
       
    15  
       
    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);
       
    28 +
       
    29 +	if (mch_access((char *)mhf, F_OK) < 0)
       
    30 +	    nominhelp = TRUE;
       
    31 +    }
       
    32 +
       
    33      i = 0;
       
    34  #ifdef FEAT_MULTI_LANG
       
    35      if (n != FAIL && lang != NULL)
       
    36 @@ -5588,7 +5607,7 @@
       
    37  		break;
       
    38  	}
       
    39  #endif
       
    40 -    if (i >= num_matches || n == FAIL)
       
    41 +    if (!nohelp && i >= num_matches || n == FAIL)
       
    42      {
       
    43  #ifdef FEAT_MULTI_LANG
       
    44  	if (lang != NULL)
       
    45 @@ -5601,9 +5620,11 @@
       
    46  	return;
       
    47      }
       
    48  
       
    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 +    }
       
    57  
       
    58  #ifdef FEAT_GUI
       
    59      need_mouse_correct = TRUE;
       
    60 @@ -5635,12 +5656,14 @@
       
    61  	     * There is no help window yet.
       
    62  	     * Try to open the file specified by the "helpfile" option.
       
    63  	     */
       
    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);
       
    75  	    }
       
    76 -	    fclose(helpfd);
       
    77  
       
    78  #ifdef FEAT_WINDOWS
       
    79  	    /* Split off help window; put it at far top if no position
       
    80 @@ -5671,7 +5694,7 @@
       
    81  	     * Set the alternate file to the previously edited file.
       
    82  	     */
       
    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 @@ -5688,7 +5711,7 @@
       
    90      if (!p_im)
       
    91  	restart_edit = 0;	    /* don't want insert mode in help file */
       
    92  
       
    93 -    if (tag != NULL)
       
    94 +    if (!nohelp && tag != NULL)
       
    95  	do_tag(tag, DT_HELP, 1, FALSE, TRUE);
       
    96  
       
    97      /* Delete the empty buffer if we're not using it.  Careful: autocommands
       
    98 @@ -5706,7 +5729,8 @@
       
    99  	curwin->w_alt_fnum = alt_fnum;
       
   100  
       
   101  erret:
       
   102 -    vim_free(tag);
       
   103 +    if (!nohelp)
       
   104 +	vim_free(tag);
       
   105  }
       
   106  
       
   107