On Thu, 21 Oct 2010 05:28:53 +0900, Kana Natsuno <[email protected]> 
wrote:
> After observation on 'foldopen' in 2 years, many users stumbled and
> reported
> the behavior about 'foldopen' and key mappings to vim_dev/vim_use.  I
> believe
> that it's not intuitive for most users.

I wrote a patch to improve the current behavior of 'foldopen'.  The
patch introduces new item "map" for 'foldopen'.  If the value of
'foldopen' contains "map", moving the cursor into a closed fold opens
the fold even if the movement is executed by a key mapping.

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff --git ../vim-7.3.027/runtime/doc/options.txt runtime/doc/options.txt
index edd8f2d..99a3450 100644
--- ../vim-7.3.027/runtime/doc/options.txt
+++ runtime/doc/options.txt
@@ -3077,6 +3077,7 @@ A jump table for the options with a short description can be found at |Q_op|.
 		insert		any command in Insert mode
 		jump		far jumps: "G", "gg", etc.
 		mark		jumping to a mark: "'m", CTRL-O, etc.
+		map		any command via a key mapping (see below)
 		percent		"%"
 		quickfix	":cn", ":crew", ":make", etc.
 		search		search for a pattern: "/", "n", "*", "gd", etc.
@@ -3084,8 +3085,9 @@ A jump table for the options with a short description can be found at |Q_op|.
 				Also for |[s| and |]s|.
 		tag		jumping to a tag: ":ta", CTRL-T, etc.
 		undo		undo or redo: "u" and CTRL-R
-	When the command is part of a mapping this option is not used.  Add
-	the |zv| command to the mapping to get the same effect.
+	When the command is part of a key mapping this option is not used
+	unless this option contains "map".  Add the |zv| command to the key
+	mapping to get the same effect.
 	When a movement command is used for an operator (e.g., "dl" or "y%")
 	this option is not used.  This means the operator will include the
 	whole closed fold.
diff --git ../vim-7.3.027/src/edit.c src/edit.c
index 04a17eb..6ae3b2e 100644
--- ../vim-7.3.027/src/edit.c
+++ src/edit.c
@@ -8991,7 +8991,7 @@ ins_left()
     pos_T	tpos;
 
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_HOR) && KeyTyped)
+    if ((fdo_flags & FDO_HOR) && (KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
     undisplay_dollar();
@@ -9034,7 +9034,7 @@ ins_home(c)
     pos_T	tpos;
 
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_HOR) && KeyTyped)
+    if ((fdo_flags & FDO_HOR) && (KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
     undisplay_dollar();
@@ -9056,7 +9056,7 @@ ins_end(c)
     pos_T	tpos;
 
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_HOR) && KeyTyped)
+    if ((fdo_flags & FDO_HOR) && (KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
     undisplay_dollar();
@@ -9073,7 +9073,7 @@ ins_end(c)
 ins_s_left()
 {
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_HOR) && KeyTyped)
+    if ((fdo_flags & FDO_HOR) && (KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
     undisplay_dollar();
@@ -9091,7 +9091,7 @@ ins_s_left()
 ins_right()
 {
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_HOR) && KeyTyped)
+    if ((fdo_flags & FDO_HOR) && (KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
     undisplay_dollar();
@@ -9141,7 +9141,7 @@ ins_right()
 ins_s_right()
 {
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_HOR) && KeyTyped)
+    if ((fdo_flags & FDO_HOR) && (KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
     undisplay_dollar();
diff --git ../vim-7.3.027/src/normal.c src/normal.c
index 1754e8a..0a6df97 100644
--- ../vim-7.3.027/src/normal.c
+++ src/normal.c
@@ -4248,7 +4248,9 @@ nv_gd(oap, nchar, thisblock)
 	    || find_decl(ptr, len, nchar == 'd', thisblock, 0) == FAIL)
 	clearopbeep(oap);
 #ifdef FEAT_FOLDING
-    else if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP)
+    else if ((fdo_flags & FDO_SEARCH)
+	     && (KeyTyped || (fdo_flags & FDO_MAP))
+	     && oap->op_type == OP_NOP)
 	foldOpenCursor();
 #endif
 }
@@ -5996,8 +5998,10 @@ nv_right(cap)
 #endif
     }
 #ifdef FEAT_FOLDING
-    if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped
-					       && cap->oap->op_type == OP_NOP)
+    if (n != cap->count1
+	&& (fdo_flags & FDO_HOR)
+	&& (KeyTyped || (fdo_flags & FDO_MAP))
+	&& cap->oap->op_type == OP_NOP)
 	foldOpenCursor();
 #endif
 }
@@ -6066,8 +6070,10 @@ nv_left(cap)
 	}
     }
 #ifdef FEAT_FOLDING
-    if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped
-					       && cap->oap->op_type == OP_NOP)
+    if (n != cap->count1
+	&& (fdo_flags & FDO_HOR)
+	&& (KeyTyped || (fdo_flags & FDO_MAP))
+	&& cap->oap->op_type == OP_NOP)
 	foldOpenCursor();
 #endif
 }
@@ -6222,7 +6228,9 @@ nv_dollar(cap)
 					 cap->oap->op_type == OP_NOP) == FAIL)
 	clearopbeep(cap->oap);
 #ifdef FEAT_FOLDING
-    else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+    else if ((fdo_flags & FDO_HOR)
+	     && (KeyTyped || (fdo_flags & FDO_MAP))
+	     && cap->oap->op_type == OP_NOP)
 	foldOpenCursor();
 #endif
 }
@@ -6299,7 +6307,9 @@ normal_search(cap, dir, pat, opt)
 	curwin->w_cursor.coladd = 0;
 #endif
 #ifdef FEAT_FOLDING
-	if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped)
+	if (cap->oap->op_type == OP_NOP
+	    && (fdo_flags & FDO_SEARCH)
+	    && (KeyTyped || (fdo_flags & FDO_MAP)))
 	    foldOpenCursor();
 #endif
     }
@@ -6349,7 +6359,9 @@ nv_csearch(cap)
 	adjust_for_sel(cap);
 #endif
 #ifdef FEAT_FOLDING
-	if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+	if ((fdo_flags & FDO_HOR)
+	    && (KeyTyped || (fdo_flags & FDO_MAP))
+	    && cap->oap->op_type == OP_NOP)
 	    foldOpenCursor();
 #endif
     }
@@ -6549,7 +6561,7 @@ nv_brackets(cap)
 	    curwin->w_cursor = *pos;
 	    curwin->w_set_curswant = TRUE;
 #ifdef FEAT_FOLDING
-	    if ((fdo_flags & FDO_BLOCK) && KeyTyped
+	    if ((fdo_flags & FDO_BLOCK) && (KeyTyped || (fdo_flags & FDO_MAP))
 					       && cap->oap->op_type == OP_NOP)
 		foldOpenCursor();
 #endif
@@ -6580,7 +6592,9 @@ nv_brackets(cap)
 	    if (cap->oap->op_type == OP_NOP)
 		beginline(BL_WHITE | BL_FIX);
 #ifdef FEAT_FOLDING
-	    if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
+	    if ((fdo_flags & FDO_BLOCK)
+		&& (KeyTyped || (fdo_flags & FDO_MAP))
+		&& cap->oap->op_type == OP_NOP)
 		foldOpenCursor();
 #endif
 	}
@@ -6671,7 +6685,9 @@ nv_brackets(cap)
 		break;
 	    }
 # ifdef FEAT_FOLDING
-	if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped)
+	if (cap->oap->op_type == OP_NOP
+	    && (fdo_flags & FDO_SEARCH)
+	    && (KeyTyped || (fdo_flags & FDO_MAP)))
 	    foldOpenCursor();
 # endif
     }
@@ -6739,7 +6755,7 @@ nv_percent(cap)
     if (cap->oap->op_type == OP_NOP
 	    && lnum != curwin->w_cursor.lnum
 	    && (fdo_flags & FDO_PERCENT)
-	    && KeyTyped)
+	    && (KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
 }
@@ -6768,7 +6784,9 @@ nv_brace(cap)
 	curwin->w_cursor.coladd = 0;
 #endif
 #ifdef FEAT_FOLDING
-	if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
+	if ((fdo_flags & FDO_BLOCK)
+	    && (KeyTyped || (fdo_flags & FDO_MAP))
+	    && cap->oap->op_type == OP_NOP)
 	    foldOpenCursor();
 #endif
     }
@@ -6808,7 +6826,9 @@ nv_findpar(cap)
 	curwin->w_cursor.coladd = 0;
 #endif
 #ifdef FEAT_FOLDING
-	if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
+	if ((fdo_flags & FDO_BLOCK)
+	    && (KeyTyped || (fdo_flags & FDO_MAP))
+	    && cap->oap->op_type == OP_NOP)
 	    foldOpenCursor();
 #endif
     }
@@ -7437,7 +7457,7 @@ nv_gomark(cap)
     if (cap->oap->op_type == OP_NOP
 	    && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum)
 	    && (fdo_flags & FDO_MARK)
-	    && old_KeyTyped)
+	    && (old_KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
 }
@@ -7484,7 +7504,7 @@ nv_pcmark(cap)
 	if (cap->oap->op_type == OP_NOP
 		&& (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum)
 		&& (fdo_flags & FDO_MARK)
-		&& old_KeyTyped)
+		&& (old_KeyTyped || (fdo_flags & FDO_MAP)))
 	    foldOpenCursor();
 # endif
     }
@@ -8547,7 +8567,9 @@ nv_bck_word(cap)
     if (bck_word(cap->count1, cap->arg, FALSE) == FAIL)
 	clearopbeep(cap->oap);
 #ifdef FEAT_FOLDING
-    else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+    else if ((fdo_flags & FDO_HOR)
+	     && (KeyTyped || (fdo_flags & FDO_MAP))
+	     && cap->oap->op_type == OP_NOP)
 	foldOpenCursor();
 #endif
 }
@@ -8637,7 +8659,9 @@ nv_wordcmd(cap)
 	adjust_for_sel(cap);
 #endif
 #ifdef FEAT_FOLDING
-	if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+	if ((fdo_flags & FDO_HOR)
+	    && (KeyTyped || (fdo_flags & FDO_MAP))
+	    && cap->oap->op_type == OP_NOP)
 	    foldOpenCursor();
 #endif
     }
@@ -8688,7 +8712,9 @@ nv_beginline(cap)
     cap->oap->inclusive = FALSE;
     beginline(cap->arg);
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
+    if ((fdo_flags & FDO_HOR)
+	&& (KeyTyped || (fdo_flags & FDO_MAP))
+	&& cap->oap->op_type == OP_NOP)
 	foldOpenCursor();
 #endif
     ins_at_eol = FALSE;	    /* Don't move cursor past eol (only necessary in a
@@ -8800,7 +8826,9 @@ nv_goto(cap)
     curwin->w_cursor.lnum = lnum;
     beginline(BL_SOL | BL_FIX);
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP)
+    if ((fdo_flags & FDO_JUMP)
+	&& (KeyTyped || (fdo_flags & FDO_MAP))
+	&& cap->oap->op_type == OP_NOP)
 	foldOpenCursor();
 #endif
 }
diff --git ../vim-7.3.027/src/option.h src/option.h
index 0f697c2..001d63d 100644
--- ../vim-7.3.027/src/option.h
+++ src/option.h
@@ -456,7 +456,7 @@ EXTERN unsigned	fdo_flags;
 # ifdef IN_OPTION_C
 static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent",
 				 "quickfix", "search", "tag", "insert",
-				 "undo", "jump", NULL};
+				 "undo", "jump", "map", NULL};
 # endif
 # define FDO_ALL		0x001
 # define FDO_BLOCK		0x002
@@ -469,6 +469,7 @@ static char *(p_fdo_values[]) = {"all", "block", "hor", "mark", "percent",
 # define FDO_INSERT		0x100
 # define FDO_UNDO		0x200
 # define FDO_JUMP		0x400
+# define FDO_MAP		0x800
 #endif
 EXTERN char_u	*p_fp;		/* 'formatprg' */
 #ifdef HAVE_FSYNC
diff --git ../vim-7.3.027/src/quickfix.c src/quickfix.c
index 0249523..6167761 100644
--- ../vim-7.3.027/src/quickfix.c
+++ src/quickfix.c
@@ -1840,7 +1840,8 @@ win_found:
 	}
 
 #ifdef FEAT_FOLDING
-	if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped)
+	if ((fdo_flags & FDO_QUICKFIX)
+	    && (old_KeyTyped || (fdo_flags & FDO_MAP)))
 	    foldOpenCursor();
 #endif
 	if (print_message)
diff --git ../vim-7.3.027/src/tag.c src/tag.c
index 50c3ce6..83f91ae 100644
--- ../vim-7.3.027/src/tag.c
+++ src/tag.c
@@ -344,7 +344,8 @@ do_tag(tag, type, count, forceit, verbose)
 		curwin->w_set_curswant = TRUE;
 		check_cursor();
 #ifdef FEAT_FOLDING
-		if ((fdo_flags & FDO_TAG) && old_KeyTyped)
+		if ((fdo_flags & FDO_TAG)
+		    && (old_KeyTyped || (fdo_flags & FDO_MAP)))
 		    foldOpenCursor();
 #endif
 
@@ -3320,7 +3321,8 @@ jumpto_tag(lbuf, forceit, keep_help)
 	    if (curbuf->b_help)
 		set_topline(curwin, curwin->w_cursor.lnum);
 #ifdef FEAT_FOLDING
-	    if ((fdo_flags & FDO_TAG) && old_KeyTyped)
+	    if ((fdo_flags & FDO_TAG)
+		&& (old_KeyTyped || (fdo_flags & FDO_MAP)))
 		foldOpenCursor();
 #endif
 	}
diff --git ../vim-7.3.027/src/undo.c src/undo.c
index 376913d..b69d146 100644
--- ../vim-7.3.027/src/undo.c
+++ src/undo.c
@@ -2664,7 +2664,7 @@ u_undo_end(did_undo, absolute)
     char_u	msgbuf[80];
 
 #ifdef FEAT_FOLDING
-    if ((fdo_flags & FDO_UNDO) && KeyTyped)
+    if ((fdo_flags & FDO_UNDO) && (KeyTyped || (fdo_flags & FDO_MAP)))
 	foldOpenCursor();
 #endif
 

Raspunde prin e-mail lui