Up Next:
-* context sensitive selection of words, commands, line numbers, or filenames.
* Implement X Selection protocol for handling clipboard and primary selections
* Tag line count should account for wrapped lines
* ctrl+alt+f should find next occurence of previous search term
unsigned buf_eow(Buf* buf, unsigned pos);
unsigned buf_lscan(Buf* buf, unsigned pos, Rune r);
unsigned buf_rscan(Buf* buf, unsigned pos, Rune r);
+
+void buf_getword(Buf* buf, bool (*isword)(Rune), Sel* sel);
void buf_getblock(Buf* buf, Rune beg, Rune end, Sel* sel);
unsigned buf_byrune(Buf* buf, unsigned pos, int count);
void view_byword(View* view, int move, bool extsel);
void view_byline(View* view, int move, bool extsel);
-char* view_fetch(View* view, size_t row, size_t col);
+char* view_fetchcmd(View* view, size_t row, size_t col);
void view_find(View* view, int dir, size_t row, size_t col);
void view_findstr(View* view, int dir, char* str);
void view_insert(View* view, bool indent, Rune rune);
bool risfile(Rune r);
bool riscmd(Rune r);
bool risblank(Rune r);
+bool risbigword(Rune r);
+
return (buf_get(buf, off) == r ? off : pos);
}
+void buf_getword(Buf* buf, bool (*isword)(Rune), Sel* sel) {
+ for (; isword(buf_get(buf, sel->beg-1)); sel->beg--);
+ for (; isword(buf_get(buf, sel->end)); sel->end++);
+ sel->end--;
+}
+
void buf_getblock(Buf* buf, Rune first, Rune last, Sel* sel) {
int balance = 0, dir;
unsigned beg = sel->end, end = sel->end, off;
/*****************************************************************************/
-int dir = +1;
-
void buf_find(Buf* buf, int dir, size_t* beg, size_t* end) {
unsigned dbeg = *beg, dend = *end;
unsigned mbeg = dbeg+dir, mend = dend+dir;
bool risblank(Rune r) {
return (r == ' ' || r == '\t' || r == '\n' || r == '\r' || r == RUNE_CRLF);
}
+
+bool risbigword(Rune r) {
+ return !risblank(r);
+}
+
int move = (scrln - midrow);
unsigned count = (move < 0 ? -move : move);
for (; count > 0; count--)
- if (move < 0)
- scroll_up(view);
- else
- scroll_dn(view);
+ (move < 0 ? scroll_up : scroll_dn)(view);
}
static void sync_view(View* view, size_t csr) {
sel->beg = bol;
sel->end = buf_eol(buf, sel->end);
} else if (risword(r)) {
- sel->beg = buf_bow(buf, sel->end);
- sel->end = buf_eow(buf, sel->end++);
+ buf_getword(buf, risword, sel);
} else if (r == '(' || r == ')') {
buf_getblock(buf, '(', ')', sel);
} else if (r == '[' || r == ']') {
} else if (r == '{' || r == '}') {
buf_getblock(buf, '{', '}', sel);
} else {
- selbigword(view, sel);
+ buf_getword(buf, risbigword, sel);
}
}
buf_loglock(&(view->buffer));
view_setcursor(view, row, col);
Sel sel = view->selection;
- selbigword(view, &sel);
+ buf_getword(&(view->buffer), risbigword, &(sel));
sel.end++;
view->selection = sel;
}
return num_selected(view->selection);
}
-char* view_fetch(View* view, size_t row, size_t col) {
- char* str = NULL;
+char* view_fetchcmd(View* view, size_t row, size_t col) {
+ char* str = NULL;
size_t off = getoffset(view, row, col);
if (off != SIZE_MAX) {
Sel sel = { .beg = off, .end = off };
if (in_selection(view->selection, off)) {
sel = view->selection;
} else {
- selcontext(view, &sel);
+ buf_getword(&(view->buffer), riscmd, &sel);
sel.end++;
}
str = view_getstr(view, &sel);
buf_findstr(&(view->buffer), dir, str, &sel.beg, &sel.end);
view->selection = sel;
view->sync_needed = true;
- view->sync_center = true;
+ view->sync_center = true;
}
void view_insert(View* view, bool indent, Rune rune) {
}
void view_putstr(View* view, char* str) {
+ unsigned beg = view->selection.beg;
buf_loglock(&(view->buffer));
while (*str) {
Rune rune = 0;
view_insert(view, false, rune);
}
buf_loglock(&(view->buffer));
+ view->selection.beg = beg;
}
void view_append(View* view, char* str) {
/* load the buffer views */
view_init(getview(TAGS), NULL);
view_putstr(getview(TAGS), DEFAULT_TAGS);
+ view_selprev(getview(TAGS)); // clear the selection
buf_logclear(getbuf(TAGS));
view_init(getview(EDIT), (argc > 1 ? argv[1] : NULL));
/* initialize the display engine */
view_append(getview(TAGS), chomp(error));
if (output) {
view_putstr(getview(dest), output);
- view_selprev(getview(dest));
Focused = dest;
}
/* cleanup */
if (MouseBtns[MOUSE_BTN_LEFT].pressed) {
cut();
} else {
- #if 0
- char* str = view_selcmd(getview(id), row, col);
+ char* str = view_fetchcmd(getview(id), row, col);
if (str) exec(str);
free(str);
- #else
- char* str = view_fetch(getview(id), row, col);
- if (str) exec(str);
- free(str);
- #endif
}
}