diff --git a/vimode/README b/vimode/README index db6008e65..4dc84b53c 100644 --- a/vimode/README +++ b/vimode/README @@ -96,7 +96,7 @@ This is an incomplete list of known limitations of the plugin: * named registers and related commands are not implemented * Ctrl+X mode is not implemented * marks are not implemented -* fold commands are not implemented +* most fold commands are not implemented * most commands starting with "'", "z", and "g" are not implemented * most ex mode commands are not implemented (excluding basic stuff like search, replace, saving, etc.) @@ -413,6 +413,15 @@ a new command, please do not forget to update the table below.:: cursor [into register x] y ["x]y{motion} yank Nmove text [into register x] yy ["x]yy yank N lines [into register x] + zA zA open a closed fold or close an open fold + recursively + zC zC close folds recursively + zM zM set 'foldlevel' to zero + zO zO open folds recursively + zR zR set 'foldlevel' to the deepest fold + za za open a closed fold, close an open fold + zc zc close a fold + zo zo open fold bar | 1 cursor to column N ~ ~ 2 'tildeop' off: switch case of N characters under cursor and move the cursor N diff --git a/vimode/src/cmds/fold.c b/vimode/src/cmds/fold.c index 14401e0e9..9b0c26333 100644 --- a/vimode/src/cmds/fold.c +++ b/vimode/src/cmds/fold.c @@ -20,13 +20,13 @@ #include "utils.h" /* fold command does not depend on state of parents */ -#define FOLD_NONE 0 +#define GOTO_NEAREST_PARENT 0 /* fold command depend on state of parents */ -#define FOLD_PARENT 1 +#define GOTO_TOPMOST_PARENT 1 /* fold command depend on state of contracted parent if it exists */ -#define FOLD_CONTRACTED 2 +#define GOTO_CONTRACTED_PARENT 2 -static gint prepare_fold(CmdParams *p, gint filter) +static gint goto_above_fold(CmdParams *p, gint type) { /* foldparent of the next line */ gint line = SSM(p->sci, SCI_GETFOLDPARENT, p->line + 1, 0); @@ -39,12 +39,12 @@ static gint prepare_fold(CmdParams *p, gint filter) line = SSM(p->sci, SCI_GETFOLDPARENT, p->line, 0); } - /* retreive first parent when filter != FOLD_NONE - when filter == FOLD_CONTRACTED we stop on first contracted parent if exist + /* retreive first parent when type != GOTO_NEAREST_PARENT + when type == GOTO_CONTRACTED_PARENT we stop on first contracted parent if exist */ - if (filter == FOLD_CONTRACTED && line != -1 && ! SSM(p->sci, SCI_GETFOLDEXPANDED, line, 0)) - ; /* this fold point is contracted and filter == FOLD_CONTRACTED */ - else if (filter != FOLD_NONE) + if (type == GOTO_CONTRACTED_PARENT && line != -1 && ! SSM(p->sci, SCI_GETFOLDEXPANDED, line, 0)) + ; /* this fold point is contracted and type == GOTO_CONTRACTED_PARENT */ + else if (type != GOTO_NEAREST_PARENT) { gint prev_line = line; while (prev_line != -1) @@ -53,13 +53,12 @@ static gint prepare_fold(CmdParams *p, gint filter) if (prev_line != -1) { line = prev_line; - if (filter == FOLD_CONTRACTED && ! SSM(p->sci, SCI_GETFOLDEXPANDED, line, 0)) + if (type == GOTO_CONTRACTED_PARENT && ! SSM(p->sci, SCI_GETFOLDEXPANDED, line, 0)) break; } } } - if (line != -1) { /* move the cursor on the visible line before the fold */ @@ -73,7 +72,7 @@ static gint prepare_fold(CmdParams *p, gint filter) void cmd_toggle_fold(CmdContext *c, CmdParams *p) { - gint line = prepare_fold(p, FOLD_NONE); + gint line = goto_above_fold(p, GOTO_NEAREST_PARENT); if (line != -1) SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_TOGGLE); } @@ -81,7 +80,7 @@ void cmd_toggle_fold(CmdContext *c, CmdParams *p) void cmd_open_fold(CmdContext *c, CmdParams *p) { - gint line = prepare_fold(p, FOLD_NONE); + gint line = goto_above_fold(p, GOTO_NEAREST_PARENT); if (line != -1) SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_EXPAND); } @@ -89,7 +88,7 @@ void cmd_open_fold(CmdContext *c, CmdParams *p) void cmd_close_fold(CmdContext *c, CmdParams *p) { - gint line = prepare_fold(p, FOLD_NONE); + gint line = goto_above_fold(p, GOTO_NEAREST_PARENT); if (line != -1) SSM(p->sci, SCI_FOLDLINE, (uptr_t) line, SC_FOLDACTION_CONTRACT); } @@ -97,7 +96,7 @@ void cmd_close_fold(CmdContext *c, CmdParams *p) void cmd_toggle_fold_child(CmdContext *c, CmdParams *p) { - gint line = prepare_fold(p, FOLD_CONTRACTED); + gint line = goto_above_fold(p, GOTO_CONTRACTED_PARENT); if (line != -1) SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_TOGGLE); } @@ -105,14 +104,14 @@ void cmd_toggle_fold_child(CmdContext *c, CmdParams *p) void cmd_open_fold_child(CmdContext *c, CmdParams *p) { - gint line = prepare_fold(p, FOLD_NONE); + gint line = goto_above_fold(p, GOTO_NEAREST_PARENT); SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_EXPAND); } void cmd_close_fold_child(CmdContext *c, CmdParams *p) { - gint line = prepare_fold(p, FOLD_PARENT); + gint line = goto_above_fold(p, GOTO_TOPMOST_PARENT); if (line != -1) SSM(p->sci, SCI_FOLDCHILDREN, (uptr_t) line, SC_FOLDACTION_CONTRACT); } @@ -126,5 +125,6 @@ void cmd_open_fold_all(CmdContext *c, CmdParams *p) void cmd_close_fold_all(CmdContext *c, CmdParams *p) { + goto_above_fold(p, GOTO_TOPMOST_PARENT); SSM(p->sci, SCI_FOLDALL, SC_FOLDACTION_CONTRACT | SC_FOLDACTION_CONTRACT_EVERY_LEVEL, 0); }