Skip to content

Commit

Permalink
vis: convert gn and gN text objects to use "/ register content
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Mar 13, 2016
1 parent 3ffd4e7 commit 46cb07d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion vis-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ struct Vis {
Macro *recording, *last_recording; /* currently (if non NULL) and least recently recorded macro */
Macro *macro_operator; /* special macro used to repeat certain operators */
Mode *mode_before_prompt; /* user mode which was active before entering prompt */
Regex *search_pattern; /* last used search pattern */
char search_char[8]; /* last used character to search for via 'f', 'F', 't', 'T' */
int last_totill; /* last to/till movement used for ';' and ',' */
int tabwidth; /* how many spaces should be used to display a tab */
Expand Down
14 changes: 12 additions & 2 deletions vis-text-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@ bool vis_textobject(Vis *vis, enum VisTextObject id) {
}

static Filerange search_forward(Vis *vis, Text *txt, size_t pos) {
return text_object_search_forward(txt, pos, vis->search_pattern);
Filerange range = text_range_empty();
Regex *regex = vis_regex(vis, NULL);
if (regex)
range = text_object_search_forward(txt, pos, regex);
text_regex_free(regex);
return range;
}

static Filerange search_backward(Vis *vis, Text *txt, size_t pos) {
return text_object_search_backward(txt, pos, vis->search_pattern);
Filerange range = text_range_empty();
Regex *regex = vis_regex(vis, NULL);
if (regex)
range = text_object_search_backward(txt, pos, regex);
text_regex_free(regex);
return range;
}

const TextObject vis_textobjects[] = {
Expand Down
3 changes: 0 additions & 3 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ Vis *vis_new(Ui *ui, VisEvent *event) {
vis->registers[VIS_REG_BLACKHOLE].type = REGISTER_BLACKHOLE;
vis->registers[VIS_REG_CLIPBOARD].type = REGISTER_CLIPBOARD;
action_reset(&vis->action);
if (!(vis->search_pattern = text_regex_new()))
goto err;
if (!(vis->command_file = file_new_internal(vis, NULL)))
goto err;
if (!(vis->search_file = file_new_internal(vis, NULL)))
Expand Down Expand Up @@ -364,7 +362,6 @@ void vis_free(Vis *vis) {
vis_window_close(vis->windows);
file_free(vis, vis->command_file);
file_free(vis, vis->search_file);
text_regex_free(vis->search_pattern);
for (int i = 0; i < LENGTH(vis->registers); i++)
register_release(&vis->registers[i]);
vis->ui->free(vis->ui);
Expand Down
2 changes: 1 addition & 1 deletion vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ enum VisRegister {
VIS_REG_PROMPT, /* internal register which shadows DEFAULT in PROMPT mode */
VIS_MACRO_OPERATOR, /* records entered keys after an operator */
VIS_MACRO_REPEAT, /* copy of the above macro once the recording is finished */
VIS_REG_SEARCH,
VIS_REG_SEARCH, /* last used search pattern "/ */
VIS_REG_INVALID, /* has to be the last 'real' register */
VIS_REG_A, VIS_REG_B, VIS_REG_C, VIS_REG_D, VIS_REG_E,
VIS_REG_F, VIS_REG_G, VIS_REG_H, VIS_REG_I, VIS_REG_J,
Expand Down

0 comments on commit 46cb07d

Please sign in to comment.