components/vim/vim72-patches/vim-help.patch
author Danek Duvall <danek.duvall@oracle.com>
Thu, 07 Apr 2011 16:25:07 -0700
changeset 198 172fc01ce997
permissions -rw-r--r--
7016732 move vim from sfw to userland 7036367 vim is too big

--- src/ex_cmds.c.orig	Tue Apr 12 14:21:15 2011
+++ src/ex_cmds.c	Wed Apr 13 13:05:28 2011
@@ -5489,6 +5489,8 @@
     int		len;
     char_u	*lang;
 #endif
+    int		nohelp = FALSE, nominhelp = FALSE;
+    char_u	*mhf = NULL;
 
     if (eap != NULL)
     {
@@ -5540,6 +5542,23 @@
     n = find_help_tags(arg, &num_matches, &matches,
 						 eap != NULL && eap->forceit);
 
+    /*
+     * If we didn't find the help topic, check to see whether 'helpfile'
+     * (typically $VIMRUNTIME/doc/help.txt) exists.  If not, then we'll send the
+     * user to the minimized help file delivered with the core vim package which
+     * explains why there's no help and how to get it.
+     */
+    if (num_matches == 0 && mch_access((char *)p_hf, F_OK) < 0) {
+	nohelp = TRUE;
+	mhf = alloc(MAXPATHL);
+	STRNCPY(mhf, p_hf, MAXPATHL - 1);
+	mhf[STRLEN(mhf) - 8] = '\0';
+	STRNCAT(mhf, "help_minimized.txt", MAXPATHL - STRLEN(mhf) - 1);
+
+	if (mch_access((char *)mhf, F_OK) < 0)
+	    nominhelp = TRUE;
+    }
+
     i = 0;
 #ifdef FEAT_MULTI_LANG
     if (n != FAIL && lang != NULL)
@@ -5552,7 +5571,7 @@
 		break;
 	}
 #endif
-    if (i >= num_matches || n == FAIL)
+    if (!nohelp && i >= num_matches || n == FAIL)
     {
 #ifdef FEAT_MULTI_LANG
 	if (lang != NULL)
@@ -5565,9 +5584,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;
@@ -5599,12 +5620,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
@@ -5635,7 +5658,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 */
@@ -5652,7 +5675,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
@@ -5670,7 +5693,8 @@
 	curwin->w_alt_fnum = alt_fnum;
 
 erret:
-    vim_free(tag);
+    if (!nohelp)
+	vim_free(tag);
 }