Thursday, April 1, 2010

Re: Why is there no :foldupdate?

From 62b32ea2cbc8ec8aba37dab994e2c63e84dfce0e Mon Sep 17 00:00:00 2001
From: Christian Brabandt <cb@256bit.org>
Date: Wed, 31 Mar 2010 22:43:07 +0200
Subject: [PATCH] Added :foldupdate and normal zU

---
runtime/doc/fold.txt | 10 ++++++++++
src/ex_cmds.h | 2 ++
src/ex_docmd.c | 9 +++++++++
src/normal.c | 6 ++++++
4 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/runtime/doc/fold.txt b/runtime/doc/fold.txt
index 60704c5..e08cd43 100644
--- a/runtime/doc/fold.txt
+++ b/runtime/doc/fold.txt
@@ -344,6 +344,16 @@ za When on a closed fold: open it. When folds are nested, you
zA When on a closed fold: open it recursively.
When on an open fold: close it recursively and set
'foldenable'.
+ *zU*
+zU Update folds and re-apply 'foldlevel'. This is usefull, to
+ reevaluate a fold-expression. For example, if you change the
+ buffer and you want that the 'foldexpression' is reevaluated
+ to update your folds, this will do it.
+
+
+
+:foldu[pdate] *:foldupdate*
+ Force updating folds. Works like "zU".

*zv*
zv View cursor line: Open just enough folds to make the line in
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
index bf66b40..319028c 100644
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -399,6 +399,8 @@ EX(CMD_folddoclosed, "folddoclosed", ex_folddo,
RANGE|DFLALL|NEEDARG|EXTRA|NOTRLCOM),
EX(CMD_foldopen, "foldopen", ex_foldopen,
RANGE|BANG|WHOLEFOLD|TRLBAR|SBOXOK|CMDWIN),
+EX(CMD_foldupdate, "foldupdate", ex_foldupdate,
+ TRLBAR),
EX(CMD_for, "for", ex_while,
EXTRA|NOTRLCOM|SBOXOK|CMDWIN),
EX(CMD_function, "function", ex_function,
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index f8795fa..1279451 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -423,10 +423,12 @@ static void ex_X __ARGS((exarg_T *eap));
static void ex_fold __ARGS((exarg_T *eap));
static void ex_foldopen __ARGS((exarg_T *eap));
static void ex_folddo __ARGS((exarg_T *eap));
+static void ex_foldupdate __ARGS(());
#else
# define ex_fold ex_ni
# define ex_foldopen ex_ni
# define ex_folddo ex_ni
+# define ex_foldupdate ex_ni
#endif
#if !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
&& (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)))
@@ -11104,6 +11106,13 @@ ex_X(eap)

#ifdef FEAT_FOLDING
static void
+ex_foldupdate()
+{
+ curwin->w_foldinvalid = TRUE;
+ newFoldLevel();
+}
+
+ static void
ex_fold(eap)
exarg_T *eap;
{
diff --git a/src/normal.c b/src/normal.c
index 8b9fea7..6acfe5b 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -4930,6 +4930,12 @@ dozet:
curwin->w_p_fen = TRUE;
break;

+ /* "zU": Update Folding, replay 'foldlevel' */
+ case 'U': curwin->w_p_fen = TRUE;
+ curwin->w_foldinvalid = TRUE;
+ old_fdl = -1; /* force an update */
+ break;
+
/* "zv": open folds at the cursor */
case 'v': foldOpenCursor();
break;
--
1.6.5.7

Hi Bram!

On Do, 01 Apr 2010, Bram Moolenaar wrote:

> One remark: in the help, add a bit more information about when this would
> be needed, why the folds are not updated automatically.

Attached is an updated patch. Is this better?

regards,
Christian

--
You received this message from the "vim_use" 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

To unsubscribe, reply using "remove me" as the subject.

No comments: