Skip to content

Commit

Permalink
Perform some renames in preparation for different word types
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Sep 25, 2014
1 parent 4e60bd3 commit 334e7f2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 47 deletions.
28 changes: 14 additions & 14 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ static bool vis_keypress(Key *key) {

static KeyBinding basic_movement[] = {
{ { KEY(LEFT) }, movement, { .i = MOVE_CHAR_PREV } },
{ { KEY(SLEFT) }, movement, { .i = MOVE_WORD_START_PREV } },
{ { KEY(SLEFT) }, movement, { .i = MOVE_LONGWORD_START_PREV } },
{ { KEY(RIGHT) }, movement, { .i = MOVE_CHAR_NEXT } },
{ { KEY(SRIGHT) }, movement, { .i = MOVE_WORD_START_NEXT } },
{ { KEY(SRIGHT) }, movement, { .i = MOVE_LONGWORD_START_NEXT } },
{ { KEY(UP) }, movement, { .i = MOVE_SCREEN_LINE_UP } },
{ { KEY(DOWN) }, movement, { .i = MOVE_SCREEN_LINE_DOWN } },
{ { KEY(PPAGE) }, wscroll, { .i = -PAGE } },
Expand All @@ -120,13 +120,13 @@ static KeyBinding vis_movements[] = {
{ { NONE('g'), NONE('_') }, movement, { .i = MOVE_LINE_FINISH } },
{ { NONE('$') }, movement, { .i = MOVE_LINE_LASTCHAR } },
{ { NONE('%') }, movement, { .i = MOVE_BRACKET_MATCH } },
{ { NONE('b') }, movement, { .i = MOVE_WORD_START_PREV } },
{ { NONE('B') }, movement, { .i = MOVE_WORD_START_PREV } },
{ { NONE('w') }, movement, { .i = MOVE_WORD_START_NEXT } },
{ { NONE('W') }, movement, { .i = MOVE_WORD_START_NEXT } },
{ { NONE('g'), NONE('e') }, movement, { .i = MOVE_WORD_END_PREV } },
{ { NONE('e') }, movement, { .i = MOVE_WORD_END_NEXT } },
{ { NONE('E') }, movement, { .i = MOVE_WORD_END_NEXT } },
{ { NONE('b') }, movement, { .i = MOVE_LONGWORD_START_PREV } },
{ { NONE('B') }, movement, { .i = MOVE_LONGWORD_START_PREV } },
{ { NONE('w') }, movement, { .i = MOVE_LONGWORD_START_NEXT } },
{ { NONE('W') }, movement, { .i = MOVE_LONGWORD_START_NEXT } },
{ { NONE('g'), NONE('e') }, movement, { .i = MOVE_LONGWORD_END_PREV } },
{ { NONE('e') }, movement, { .i = MOVE_LONGWORD_END_NEXT } },
{ { NONE('E') }, movement, { .i = MOVE_LONGWORD_END_NEXT } },
{ { NONE('{') }, movement, { .i = MOVE_PARAGRAPH_PREV } },
{ { NONE('}') }, movement, { .i = MOVE_PARAGRAPH_NEXT } },
{ { NONE('(') }, movement, { .i = MOVE_SENTENCE_PREV } },
Expand All @@ -153,7 +153,7 @@ static KeyBinding vis_movements[] = {
};

static KeyBinding vis_textobjs[] = {
{ { NONE('a'), NONE('w') }, textobj, { .i = TEXT_OBJ_WORD } },
{ { NONE('a'), NONE('w') }, textobj, { .i = TEXT_OBJ_LONGWORD } },
{ { NONE('a'), NONE('s') }, textobj, { .i = TEXT_OBJ_SENTENCE } },
{ { NONE('a'), NONE('p') }, textobj, { .i = TEXT_OBJ_PARAGRAPH } },
{ { NONE('a'), NONE('[') }, textobj, { .i = TEXT_OBJ_OUTER_SQUARE_BRACKET } },
Expand All @@ -173,7 +173,7 @@ static KeyBinding vis_textobjs[] = {
};

static KeyBinding vis_inner_textobjs[] = {
{ { NONE('i'), NONE('w') }, textobj, { .i = TEXT_OBJ_WORD } },
{ { NONE('i'), NONE('w') }, textobj, { .i = TEXT_OBJ_LONGWORD } },
{ { NONE('i'), NONE('s') }, textobj, { .i = TEXT_OBJ_SENTENCE } },
{ { NONE('i'), NONE('p') }, textobj, { .i = TEXT_OBJ_PARAGRAPH } },
{ { NONE('i'), NONE('[') }, textobj, { .i = TEXT_OBJ_INNER_SQUARE_BRACKET } },
Expand Down Expand Up @@ -450,7 +450,7 @@ static KeyBinding vis_mode_readline[] = {
{ { CONTROL('c') }, switchmode, { .i = VIS_MODE_NORMAL } },
BACKSPACE( call, f, editor_backspace_key ),
{ { CONTROL('D') }, call, { .f = editor_delete_key } },
{ { CONTROL('W') }, delete, { .i = MOVE_WORD_START_PREV } },
{ { CONTROL('W') }, delete, { .i = MOVE_LONGWORD_START_PREV } },
{ { CONTROL('U') }, delete, { .i = MOVE_LINE_BEGIN } },
{ /* empty last element, array terminator */ },
};
Expand Down Expand Up @@ -742,9 +742,9 @@ static KeyBinding nano_keys[] = {
{ { KEY(F(8)) }, wscroll, { .i = +PAGE } },
#if 0
// CONTROL(' ') == 0 which signals the end of array
{ { CONTROL(' ') }, movement, { .i = MOVE_WORD_START_NEXT } },
{ { CONTROL(' ') }, movement, { .i = MOVE_LONGWORD_START_NEXT } },
#endif
{ { META(' ') }, movement, { .i = MOVE_WORD_START_PREV } },
{ { META(' ') }, movement, { .i = MOVE_LONGWORD_START_PREV } },
{ { CONTROL('A') }, movement, { .i = MOVE_LINE_START } },
{ { CONTROL('E') }, movement, { .i = MOVE_LINE_END } },
{ { META(']') }, movement, { .i = MOVE_BRACKET_MATCH } },
Expand Down
8 changes: 4 additions & 4 deletions text-motions.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,19 @@ size_t text_word_boundry_end_prev(Text *txt, size_t pos, int (*isboundry)(int))
return it.pos;
}

size_t text_word_end_next(Text *txt, size_t pos) {
size_t text_longword_end_next(Text *txt, size_t pos) {
return text_word_boundry_end_next(txt, pos, isspace);
}

size_t text_word_end_prev(Text *txt, size_t pos) {
size_t text_longword_end_prev(Text *txt, size_t pos) {
return text_word_boundry_end_prev(txt, pos, isspace);
}

size_t text_word_start_next(Text *txt, size_t pos) {
size_t text_longword_start_next(Text *txt, size_t pos) {
return text_word_boundry_start_next(txt, pos, isspace);
}

size_t text_word_start_prev(Text *txt, size_t pos) {
size_t text_longword_start_prev(Text *txt, size_t pos) {
return text_word_boundry_start_prev(txt, pos, isspace);
}

Expand Down
8 changes: 4 additions & 4 deletions text-motions.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ size_t text_line_next(Text*, size_t pos);
* space. TODO?: An empty line is also considered to be a word.
* This is equivalant to a WORD in vim terminology.
*/
size_t text_word_end_next(Text*, size_t pos);
size_t text_word_end_prev(Text*, size_t pos);
size_t text_word_start_next(Text*, size_t pos);
size_t text_word_start_prev(Text*, size_t pos);
size_t text_longword_end_next(Text*, size_t pos);
size_t text_longword_end_prev(Text*, size_t pos);
size_t text_longword_start_next(Text*, size_t pos);
size_t text_longword_start_prev(Text*, size_t pos);
/*
* These are variants of the above with the additional possibility to implement
* a custom word detection logic. Can be used to implment the equivalent of a
Expand Down
26 changes: 13 additions & 13 deletions text-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@ Filerange text_object_word(Text *txt, size_t pos) {
text_iterator_byte_next(&it, &next);
if (isspace(c)) {
/* middle of two words, include leading white space */
r.start = text_char_next(txt, text_word_end_prev(txt, pos));
r.end = text_char_next(txt, text_word_end_next(txt, pos));
r.start = text_char_next(txt, text_longword_end_prev(txt, pos));
r.end = text_char_next(txt, text_longword_end_next(txt, pos));
} else if (isspace(prev) && isspace(next)) {
/* on a single character */
r.start = pos;
r.end = text_word_start_next(txt, pos);
r.end = text_longword_start_next(txt, pos);
} else if (isspace(prev)) {
/* at start of a word */
r.start = pos;
r.end = text_word_start_next(txt, text_word_end_next(txt, pos));
r.end = text_longword_start_next(txt, text_longword_end_next(txt, pos));
} else if (isspace(next)) {
/* at end of a word */
r.start = text_word_start_prev(txt, pos);
r.end = text_word_start_next(txt, pos);
r.start = text_longword_start_prev(txt, pos);
r.end = text_longword_start_next(txt, pos);
} else {
/* in the middle of a word */
r.start = text_word_start_prev(txt, pos);
r.end = text_word_start_next(txt, text_word_end_next(txt, pos));
r.start = text_longword_start_prev(txt, pos);
r.end = text_longword_start_next(txt, text_longword_end_next(txt, pos));
}
return r;
}

Filerange text_object_word_raw(Text *txt, size_t pos) {
Filerange text_object_longword_raw(Text *txt, size_t pos) {
char c, prev = '0', next = '0';
Filerange r = text_range_empty();
Iterator it = text_iterator_get(txt, pos);
Expand All @@ -69,15 +69,15 @@ Filerange text_object_word_raw(Text *txt, size_t pos) {
} else if (isspace(prev)) {
/* at start of a word */
r.start = pos;
r.end = text_char_next(txt, text_word_end_next(txt, pos));
r.end = text_char_next(txt, text_longword_end_next(txt, pos));
} else if (isspace(next)) {
/* at end of a word */
r.start = text_word_start_prev(txt, pos);
r.start = text_longword_start_prev(txt, pos);
r.end = text_char_next(txt, pos);
} else {
/* in the middle of a word */
r.start = text_word_start_prev(txt, pos);
r.end = text_char_next(txt, text_word_end_next(txt, pos));
r.start = text_longword_start_prev(txt, pos);
r.end = text_char_next(txt, text_longword_end_next(txt, pos));
}

return r;
Expand Down
2 changes: 1 addition & 1 deletion text-objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Filerange text_object_word(Text*, size_t pos);
/* word which happens to be at pos, _not_ including any white spaces. if pos
* is not part of a word, an empty range is returned */
Filerange text_object_word_raw(Text*, size_t pos);
Filerange text_object_longword_raw(Text*, size_t pos);
Filerange text_object_line(Text*, size_t pos);
Filerange text_object_sentence(Text*, size_t pos);
Filerange text_object_paragraph(Text*, size_t pos);
Expand Down
22 changes: 11 additions & 11 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ enum {
MOVE_COLUMN,
MOVE_CHAR_PREV,
MOVE_CHAR_NEXT,
MOVE_WORD_START_PREV,
MOVE_WORD_START_NEXT,
MOVE_WORD_END_PREV,
MOVE_WORD_END_NEXT,
MOVE_LONGWORD_START_PREV,
MOVE_LONGWORD_START_NEXT,
MOVE_LONGWORD_END_PREV,
MOVE_LONGWORD_END_NEXT,
MOVE_SENTENCE_PREV,
MOVE_SENTENCE_NEXT,
MOVE_PARAGRAPH_PREV,
Expand Down Expand Up @@ -274,10 +274,10 @@ static Movement moves[] = {
[MOVE_COLUMN] = { .cmd = column, .type = CHARWISE|IDEMPOTENT},
[MOVE_CHAR_PREV] = { .win = window_char_prev },
[MOVE_CHAR_NEXT] = { .win = window_char_next },
[MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE },
[MOVE_WORD_START_NEXT] = { .txt = text_word_start_next, .type = CHARWISE },
[MOVE_WORD_END_PREV] = { .txt = text_word_end_prev, .type = CHARWISE|INCLUSIVE },
[MOVE_WORD_END_NEXT] = { .txt = text_word_end_next, .type = CHARWISE|INCLUSIVE },
[MOVE_LONGWORD_START_PREV] = { .txt = text_longword_start_prev, .type = CHARWISE },
[MOVE_LONGWORD_START_NEXT] = { .txt = text_longword_start_next, .type = CHARWISE },
[MOVE_LONGWORD_END_PREV] = { .txt = text_longword_end_prev, .type = CHARWISE|INCLUSIVE },
[MOVE_LONGWORD_END_NEXT] = { .txt = text_longword_end_next, .type = CHARWISE|INCLUSIVE },
[MOVE_SENTENCE_PREV] = { .txt = text_sentence_prev, .type = LINEWISE },
[MOVE_SENTENCE_NEXT] = { .txt = text_sentence_next, .type = LINEWISE },
[MOVE_PARAGRAPH_PREV] = { .txt = text_paragraph_prev, .type = LINEWISE },
Expand All @@ -301,7 +301,7 @@ static Movement moves[] = {

/* these can be passed as int argument to textobj(&(const Arg){ .i = TEXT_OBJ_* }) */
enum {
TEXT_OBJ_WORD,
TEXT_OBJ_LONGWORD,
TEXT_OBJ_LINE_UP,
TEXT_OBJ_LINE_DOWN,
TEXT_OBJ_SENTENCE,
Expand All @@ -323,7 +323,7 @@ enum {
};

static TextObject textobjs[] = {
[TEXT_OBJ_WORD] = { text_object_word },
[TEXT_OBJ_LONGWORD] = { text_object_word },
[TEXT_OBJ_LINE_UP] = { text_object_line },
[TEXT_OBJ_LINE_DOWN] = { text_object_line },
[TEXT_OBJ_SENTENCE] = { text_object_sentence },
Expand Down Expand Up @@ -604,7 +604,7 @@ static size_t search_word(const Arg *arg) {
size_t pos = window_cursor_get(vis->win->win);
/* TODO: to make this useful the other variant breaking on special symbols
* should be used here */
Filerange word = text_object_word_raw(vis->win->text, pos);
Filerange word = text_object_longword_raw(vis->win->text, pos);
if (!text_range_valid(&word))
return pos;
size_t len = word.end - word.start;
Expand Down

0 comments on commit 334e7f2

Please sign in to comment.