[geany/geany-plugins] f20a71: vimode: add :copy and :move ex commands
Jiří Techet
git-noreply at xxxxx
Wed Sep 29 17:10:42 UTC 2021
Branch: refs/heads/master
Author: Jiří Techet <techet at gmail.com>
Committer: Jiří Techet <techet at gmail.com>
Date: Thu, 02 Sep 2021 15:23:17 UTC
Commit: f20a71d0d063f8c064acfc5ad5de7074e0271b39
https://github.com/geany/geany-plugins/commit/f20a71d0d063f8c064acfc5ad5de7074e0271b39
Log Message:
-----------
vimode: add :copy and :move ex commands
Modified Paths:
--------------
vimode/src/cmds/excmds.c
vimode/src/cmds/excmds.h
vimode/src/excmd-params.h
vimode/src/excmd-runner.c
Modified: vimode/src/cmds/excmds.c
28 lines changed, 28 insertions(+), 0 deletions(-)
===================================================================
@@ -133,3 +133,31 @@ void excmd_join(CmdContext *c, ExCmdParams *p)
cmd_join_lines(c, ¶ms);
}
+
+void excmd_copy(CmdContext *c, ExCmdParams *p)
+{
+ CmdParams params;
+ gint dest = SSM(c->sci, SCI_POSITIONFROMLINE, p->dest, 0);
+ excmd_yank(c, p);
+ SET_POS(c->sci, dest, TRUE);
+ cmd_params_init(¶ms, c->sci, 1, FALSE, NULL, FALSE, 0, 0);
+ cmd_paste_after(c, ¶ms);
+}
+
+
+void excmd_move(CmdContext *c, ExCmdParams *p)
+{
+ CmdParams params;
+ gint dest;
+
+ if (p->dest >= p->range_from && p->dest <= p->range_to)
+ return;
+
+ excmd_delete(c, p);
+ if (p->dest > p->range_to)
+ p->dest -= p->range_to - p->range_from + 1;
+ dest = SSM(c->sci, SCI_POSITIONFROMLINE, p->dest, 0);
+ SET_POS(c->sci, dest, TRUE);
+ cmd_params_init(¶ms, c->sci, 1, FALSE, NULL, FALSE, 0, 0);
+ cmd_paste_after(c, ¶ms);
+}
Modified: vimode/src/cmds/excmds.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -37,5 +37,7 @@ void excmd_shift_left(CmdContext *c, ExCmdParams *p);
void excmd_shift_right(CmdContext *c, ExCmdParams *p);
void excmd_delete(CmdContext *c, ExCmdParams *p);
void excmd_join(CmdContext *c, ExCmdParams *p);
+void excmd_copy(CmdContext *c, ExCmdParams *p);
+void excmd_move(CmdContext *c, ExCmdParams *p);
#endif
Modified: vimode/src/excmd-params.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -30,6 +30,8 @@ typedef struct
/* ex range start and end */
gint range_from;
gint range_to;
+ /* "address" destination for copy/move */
+ gint dest;
} ExCmdParams;
typedef void (*ExCmd)(CmdContext *c, ExCmdParams *p);
Modified: vimode/src/excmd-runner.c
11 lines changed, 11 insertions(+), 0 deletions(-)
===================================================================
@@ -86,6 +86,13 @@ ExCmdDef ex_cmds[] = {
{excmd_join, "join"},
{excmd_join, "j"},
+ {excmd_copy, "copy"},
+ {excmd_copy, "co"},
+ {excmd_copy, "t"},
+
+ {excmd_move, "move"},
+ {excmd_move, "m"},
+
{NULL, NULL}
};
@@ -433,7 +440,11 @@ static void perform_simple_ex_cmd(CmdContext *ctx, const gchar *cmd)
ExCmdDef *def = &ex_cmds[i];
if (strcmp(def->name, cmd_name) == 0)
{
+ if (def->cmd == excmd_copy || def->cmd == excmd_move)
+ parse_ex_range(&(params.param1), ctx, &(params.dest), &(params.dest));
+ SSM(ctx->sci, SCI_BEGINUNDOACTION, 0, 0);
def->cmd(ctx, ¶ms);
+ SSM(ctx->sci, SCI_ENDUNDOACTION, 0, 0);
break;
}
}
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Plugins-Commits
mailing list