void buf_findstr(Buf* buf, char* str, size_t* beg, size_t* end);
unsigned buf_end(Buf* buf);
unsigned buf_byrune(Buf* buf, unsigned pos, int count);
+unsigned buf_byword(Buf* buf, unsigned pos, int count);
unsigned buf_byline(Buf* buf, unsigned pos, int count);
unsigned buf_getcol(Buf* buf, unsigned pos);
unsigned buf_setcol(Buf* buf, unsigned pos, unsigned col);
void buf_lastins(Buf* buf, size_t* beg, size_t* end);
void buf_loglock(Buf* buf);
-/*
-void buf_load(Buf* buf, char* path);
-void buf_save(Buf* buf);
-void buf_init(Buf* buf);
-void buf_ins(Buf* buf, Sel csr, Rune);
-void buf_del(Buf* buf, Sel csr);
-Sel buf_undo(Buf* buf, Sel csr);
-Sel buf_redo(Buf* buf, Sel csr);
-Rune buf_get(Buf* buf, Sel csr);
-void buf_setlocked(Buf* buf, bool locked);
-bool buf_locked(Buf* buf);
-bool buf_iseol(Buf* buf, Sel csr);
-Sel buf_bol(Buf* buf, Sel csr);
-Sel buf_eol(Buf* buf, Sel csr);
-Sel buf_bow(Buf* buf, Sel csr);
-Sel buf_eow(Buf* buf, Sel csr);
-Sel buf_lscan(Buf* buf, Sel csr, Rune r);
-Sel buf_rscan(Buf* buf, Sel csr, Rune r);
-Sel buf_find(Buf* buf, Sel csr);
-Sel buf_end(Buf* buf);
-Sel buf_byrune(Buf* buf, Sel csr, int count);
-Sel buf_byline(Buf* buf, Sel csr, int count);
-Sel buf_getcol(Buf* buf, Sel csr);
-Sel buf_setcol(Buf* buf, Sel csr, unsigned col);
-char* buf_getstr(Buf* buf, Sel csr);
-Sel buf_putstr(Buf* buf, Sel csr, char* str);
-*/
-
/* Charset Handling
*****************************************************************************/
enum {
void view_update(View* view, size_t* csrx, size_t* csry);
Row* view_getrow(View* view, size_t row);
void view_byrune(View* view, int move, bool extsel);
+void view_byword(View* view, int move, bool extsel);
void view_byline(View* view, int move, bool extsel);
void view_setcursor(View* view, size_t row, size_t col);
void view_selext(View* view, size_t row, size_t col);
return pos;
}
+unsigned buf_byword(Buf* buf, unsigned off, int count) {
+ int move = (count < 0 ? -1 : 1);
+ unsigned end = buf_end(buf);
+ if (move < 0) {
+ for (; off > 0 && !risword(buf_get(buf, off-1)); off--);
+ for (; off > 0 && risword(buf_get(buf, off-1)); off--);
+ } else {
+ for (; off < end && risword(buf_get(buf, off+1)); off++);
+ for (; off < end && !risword(buf_get(buf, off+1)); off++);
+ off++;
+ }
+ return off;
+}
+
unsigned buf_byline(Buf* buf, unsigned pos, int count) {
int move = (count < 0 ? -1 : 1);
count *= move; // remove the sign if there is one
view->sync_needed = true;
}
+void view_byword(View* view, int move, bool extsel) {
+ Sel sel = view->selection;
+ sel.end = buf_byword(&(view->buffer), sel.end, move);
+ if (!extsel) sel.beg = sel.end;
+ sel.col = buf_getcol(&(view->buffer), sel.end);
+ view->selection = sel;
+ view->sync_needed = true;
+}
+
void view_byline(View* view, int move, bool extsel) {
Sel sel = view->selection;
sel.end = buf_byline(&(view->buffer), sel.end, move);
// UI Callbacks
static void delete(void);
static void del_to_bol(void);
+static void del_to_bow(void);
static void backspace(void);
static void cursor_home(void);
static void cursor_end(void);
/* Standard Unix Shortcuts */
{ ModCtrl, 'u', del_to_bol },
- //{ KEY_CTRL_W, del_to_bow },
+ { ModCtrl, 'w', del_to_bow },
{ ModCtrl, 'h', backspace },
{ ModCtrl, 'a', cursor_home },
{ ModCtrl, 'e', cursor_end },
delete();
}
+static void del_to_bow(void) {
+ view_byword(currview(), LEFT, true);
+ delete();
+}
+
static void backspace(void) {
bool byword = x11_keymodsset(ModCtrl);
view_delete(currview(), LEFT, byword);
static void cursor_left(void) {
bool extsel = x11_keymodsset(ModShift);
- view_byrune(currview(), LEFT, extsel);
+ if (x11_keymodsset(ModCtrl))
+ view_byword(currview(), LEFT, extsel);
+ else
+ view_byrune(currview(), LEFT, extsel);
}
static void cursor_right(void) {
bool extsel = x11_keymodsset(ModShift);
- view_byrune(currview(), RIGHT, extsel);
+ if (x11_keymodsset(ModCtrl))
+ view_byword(currview(), RIGHT, extsel);
+ else
+ view_byrune(currview(), RIGHT, extsel);
}
static void page_up(void) {