Branch: refs/heads/master Author: Frank Lanitz frank@frank.uvena.de Committer: GitHub noreply@github.com Date: Wed, 29 Sep 2021 17:10:37 UTC Commit: b7eb47d96a5e5e668db5060e88dec96085d3700b https://github.com/geany/geany-plugins/commit/b7eb47d96a5e5e668db5060e88dec9...
Log Message: ----------- Merge pull request #1105 from techee/vim_more_ex_commands
vimode: add some more ex commands
Modified Paths: -------------- vimode/README vimode/src/Makefile.am vimode/src/cmd-params.c vimode/src/cmds/excmds.c vimode/src/cmds/excmds.h vimode/src/excmd-params.h vimode/src/excmd-runner.c vimode/src/excmds/excmds.c
Modified: vimode/README 12 lines changed, 12 insertions(+), 0 deletions(-) =================================================================== @@ -550,16 +550,28 @@ a new command, please do not forget to update the table below.:: tag command action ------------------------------------------------------------------------------ :& :& repeat last ":substitute" + :< :< shift lines one 'shiftwidth' left + :> :> shift lines one 'shiftwidth' right + :copy :co[py] copy lines :cquit :cq[uit] quit Vim with an error code + :delete :d[elete] delete lines :exit :exi[t] same as ":xit" + :join :j[oin] join lines + :move :m[ove] move lines + :put :pu[t] insert contents of register in the text :quit :q[uit] quit current window (when one window quit Vim) :quitall :quita[ll] quit Vim :qall :qa[ll] quit Vim + :redo :red[o] redo one undone change :substitute :s[ubstitute] find and replace text + :t :t same as ":copy" + :undo :u[ndo] undo last change(s) :update :up[date] write buffer if modified :write :w[rite] write to a file :wall :wa[ll] write all (changed) buffers :wq :wq write to a file and quit window or Vim :wqall :wqa[ll] write all changed buffers and quit Vim :xit :x[it] write if buffer changed and quit window or Vim :xall :xa[ll] same as ":wqall" + :yank :y[ank] yank lines into a register + :~ :~ repeat last ":substitute"
Modified: vimode/src/Makefile.am 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -36,8 +36,8 @@ vi_srcs = \ cmds/special.c \ cmds/edit.h \ cmds/edit.c \ - excmds/excmds.h \ - excmds/excmds.c + cmds/excmds.h \ + cmds/excmds.c
vimode_la_SOURCES = \ backends/backend-geany.c \
Modified: vimode/src/cmd-params.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -26,7 +26,7 @@ void cmd_params_init(CmdParams *param, ScintillaObject *sci,
param->num = num; param->num_present = num_present; - param->last_kp = g_slist_nth_data(kpl, 0); + param->last_kp = kpl != NULL ? g_slist_nth_data(kpl, 0) : NULL; param->is_operator_cmd = is_operator_cmd;
param->sel_start = sel_start;
Modified: vimode/src/cmds/excmds.c 163 lines changed, 163 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,163 @@ +/* + * Copyright 2018 Jiri Techet techet@gmail.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "cmds/excmds.h" +#include "cmds/edit.h" +#include "utils.h" + +void excmd_save(CmdContext *c, ExCmdParams *p) +{ + c->cb->on_save(p->force); +} + + +void excmd_save_all(CmdContext *c, ExCmdParams *p) +{ + c->cb->on_save_all(p->force); +} + + +void excmd_quit(CmdContext *c, ExCmdParams *p) +{ + c->cb->on_quit(p->force); +} + + +void excmd_save_quit(CmdContext *c, ExCmdParams *p) +{ + if (c->cb->on_save(p->force)) + c->cb->on_quit(p->force); +} + + +void excmd_save_all_quit(CmdContext *c, ExCmdParams *p) +{ + if (c->cb->on_save_all(p->force)) + c->cb->on_quit(p->force); +} + + +void excmd_repeat_subst(CmdContext *c, ExCmdParams *p) +{ + const gchar *flags = p->param1; + if (!flags) + flags = "g"; + perform_substitute(c->sci, c->substitute_text, p->range_from, p->range_to, flags); +} + + +void excmd_repeat_subst_orig_flags(CmdContext *c, ExCmdParams *p) +{ + perform_substitute(c->sci, c->substitute_text, p->range_from, p->range_to, NULL); +} + + +static void prepare_cmd_params(CmdParams *params, CmdContext *c, ExCmdParams *p) +{ + gint start = SSM(c->sci, SCI_POSITIONFROMLINE, p->range_from, 0); + SET_POS(c->sci, start, TRUE); + cmd_params_init(params, c->sci, p->range_to - p->range_from + 1, FALSE, NULL, FALSE, 0, 0); +} + + +void excmd_yank(CmdContext *c, ExCmdParams *p) +{ + CmdParams params; + prepare_cmd_params(¶ms, c, p); + cmd_copy_line(c, ¶ms); +} + + +void excmd_put(CmdContext *c, ExCmdParams *p) +{ + CmdParams params; + prepare_cmd_params(¶ms, c, p); + cmd_paste_after(c, ¶ms); +} + + +void excmd_undo(CmdContext *c, ExCmdParams *p) +{ + SSM(c->sci, SCI_UNDO, 0, 0); +} + + +void excmd_redo(CmdContext *c, ExCmdParams *p) +{ + SSM(c->sci, SCI_REDO, 0, 0); +} + + +void excmd_shift_left(CmdContext *c, ExCmdParams *p) +{ + CmdParams params; + prepare_cmd_params(¶ms, c, p); + cmd_unindent(c, ¶ms); +} + + +void excmd_shift_right(CmdContext *c, ExCmdParams *p) +{ + CmdParams params; + prepare_cmd_params(¶ms, c, p); + cmd_indent(c, ¶ms); +} + + +void excmd_delete(CmdContext *c, ExCmdParams *p) +{ + CmdParams params; + prepare_cmd_params(¶ms, c, p); + cmd_delete_line(c, ¶ms); +} + +void excmd_join(CmdContext *c, ExCmdParams *p) +{ + CmdParams params; + prepare_cmd_params(¶ms, c, 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 14 lines changed, 12 insertions(+), 2 deletions(-) =================================================================== @@ -16,8 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-#ifndef __VIMODE_EXCMDS_EXCMDS_H__ -#define __VIMODE_EXCMDS_EXCMDS_H__ +#ifndef __VIMODE_CMDS_EXCMDS_H__ +#define __VIMODE_CMDS_EXCMDS_H__
#include "excmd-params.h" #include "context.h" @@ -29,5 +29,15 @@ void excmd_save_quit(CmdContext *c, ExCmdParams *p); void excmd_save_all_quit(CmdContext *c, ExCmdParams *p); void excmd_repeat_subst(CmdContext *c, ExCmdParams *p); void excmd_repeat_subst_orig_flags(CmdContext *c, ExCmdParams *p); +void excmd_yank(CmdContext *c, ExCmdParams *p); +void excmd_put(CmdContext *c, ExCmdParams *p); +void excmd_undo(CmdContext *c, ExCmdParams *p); +void excmd_redo(CmdContext *c, ExCmdParams *p); +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 33 lines changed, 32 insertions(+), 1 deletions(-) =================================================================== @@ -18,7 +18,7 @@
#include "excmd-runner.h" #include "excmd-params.h" -#include "excmds/excmds.h" +#include "cmds/excmds.h" #include "utils.h"
#include <string.h> @@ -64,8 +64,35 @@ ExCmdDef ex_cmds[] = { {excmd_repeat_subst, "s"}, {excmd_repeat_subst, "substitute"}, {excmd_repeat_subst, "&"}, + {excmd_repeat_subst, "~"}, {excmd_repeat_subst_orig_flags, "&&"},
+ {excmd_yank, "yank"}, + {excmd_yank, "y"}, + {excmd_put, "put"}, + {excmd_put, "pu"}, + + {excmd_undo, "undo"}, + {excmd_undo, "u"}, + {excmd_redo, "redo"}, + {excmd_redo, "red"}, + + {excmd_shift_left, "<"}, + {excmd_shift_right, ">"}, + + {excmd_delete, "delete"}, + {excmd_delete, "d"}, + + {excmd_join, "join"}, + {excmd_join, "j"}, + + {excmd_copy, "copy"}, + {excmd_copy, "co"}, + {excmd_copy, "t"}, + + {excmd_move, "move"}, + {excmd_move, "m"}, + {NULL, NULL} };
@@ -413,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; } }
Modified: vimode/src/excmds/excmds.c 66 lines changed, 0 insertions(+), 66 deletions(-) =================================================================== @@ -1,66 +0,0 @@ -/* - * Copyright 2018 Jiri Techet techet@gmail.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "excmds/excmds.h" -#include "utils.h" - -void excmd_save(CmdContext *c, ExCmdParams *p) -{ - c->cb->on_save(p->force); -} - - -void excmd_save_all(CmdContext *c, ExCmdParams *p) -{ - c->cb->on_save_all(p->force); -} - - -void excmd_quit(CmdContext *c, ExCmdParams *p) -{ - c->cb->on_quit(p->force); -} - - -void excmd_save_quit(CmdContext *c, ExCmdParams *p) -{ - if (c->cb->on_save(p->force)) - c->cb->on_quit(p->force); -} - - -void excmd_save_all_quit(CmdContext *c, ExCmdParams *p) -{ - if (c->cb->on_save_all(p->force)) - c->cb->on_quit(p->force); -} - - -void excmd_repeat_subst(CmdContext *c, ExCmdParams *p) -{ - const gchar *flags = p->param1; - if (!flags) - flags = "g"; - perform_substitute(c->sci, c->substitute_text, p->range_from, p->range_to, flags); -} - - -void excmd_repeat_subst_orig_flags(CmdContext *c, ExCmdParams *p) -{ - perform_substitute(c->sci, c->substitute_text, p->range_from, p->range_to, NULL); -}
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).