Skip to content

Commit

Permalink
Vimode: constants and functions renamed and README completed
Browse files Browse the repository at this point in the history
  • Loading branch information
scresto09 committed May 23, 2024
1 parent c902da4 commit e0252c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
11 changes: 10 additions & 1 deletion vimode/README
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions vimode/src/cmds/fold.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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 */
Expand All @@ -73,46 +72,46 @@ 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);
}


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);
}


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);
}


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);
}


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);
}
Expand All @@ -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);
}

0 comments on commit e0252c9

Please sign in to comment.