From 94ce35e0860ad4ccb8eeee99485b0f9d737f0f53 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 18 May 2017 21:22:07 -0400 Subject: [PATCH] Addeded shortcut for joining lines --- docs/xedit.1 | 4 ++++ docs/xedit.1.md | 3 +++ inc/edit.h | 1 + inc/shortcuts.h | 11 +++++++++++ lib/view.c | 4 ++++ xedit.c | 13 +++++++------ 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/xedit.1 b/docs/xedit.1 index 9fc7b87..d70d416 100644 --- a/docs/xedit.1 +++ b/docs/xedit.1 @@ -181,6 +181,10 @@ Copy the selected text to the X11 CLIPBOARD selection\. If no text is selected t Paste the contents of the X11 CLIPBOARD selection to the active region\. . .TP +\fBCtrl+j\fR +Join the current line and the next line\. +. +.TP \fBDelete\fR Delete the character to the right\. . diff --git a/docs/xedit.1.md b/docs/xedit.1.md index 55dd87c..7472123 100644 --- a/docs/xedit.1.md +++ b/docs/xedit.1.md @@ -218,6 +218,9 @@ position. * `Ctrl+v`: Paste the contents of the X11 CLIPBOARD selection to the active region. +* `Ctrl+j`: + Join the current line and the next line. + * `Delete`: Delete the character to the right. diff --git a/inc/edit.h b/inc/edit.h index e4a2b1f..55a4196 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -171,6 +171,7 @@ void view_selword(View* view, size_t row, size_t col); void view_select(View* view, size_t row, size_t col); void view_jumpto(View* view, bool extsel, size_t off); void view_scrollto(View* view, size_t csr); +Rune view_getrune(View* view); /* Command Executions *****************************************************************************/ diff --git a/inc/shortcuts.h b/inc/shortcuts.h index 9ada8c1..f18471f 100644 --- a/inc/shortcuts.h +++ b/inc/shortcuts.h @@ -4,6 +4,17 @@ static void select_line(void) { view_selctx(view); } +static void join_lines(void) { + View* view = win_view(FOCUSED); + view_eol(view, false); + view_delete(view, RIGHT, false); + Rune r = view_getrune(view); + for (; r == '\t' || r == ' '; r = view_getrune(view)) + view_delete(view, RIGHT, false); + if (r != '\n' && r != RUNE_CRLF) + view_insert(view, false, ' '); +} + static void delete(void) { bool byword = x11_keymodsset(ModCtrl); view_delete(win_view(FOCUSED), RIGHT, byword); diff --git a/lib/view.c b/lib/view.c index 9567bae..996c965 100644 --- a/lib/view.c +++ b/lib/view.c @@ -578,3 +578,7 @@ void view_indent(View* view, int dir) { } while (off && off >= view->selection.beg); } + +Rune view_getrune(View* view) { + return buf_get(&(view->buffer), view->selection.end); +} diff --git a/xedit.c b/xedit.c index 234488d..0809f49 100644 --- a/xedit.c +++ b/xedit.c @@ -365,12 +365,13 @@ static KeyBinding Bindings[] = { { ModCtrl, 'e', cursor_eol }, /* Standard Text Editing Shortcuts */ - { ModCtrl, 's', save }, - { ModCtrl, 'z', undo }, - { ModCtrl, 'y', redo }, - { ModCtrl, 'x', cut }, - { ModCtrl, 'c', copy }, - { ModCtrl, 'v', paste }, + { ModCtrl, 's', save }, + { ModCtrl, 'z', undo }, + { ModCtrl, 'y', redo }, + { ModCtrl, 'x', cut }, + { ModCtrl, 'c', copy }, + { ModCtrl, 'v', paste }, + { ModCtrl, 'j', join_lines }, /* Block Indent */ { ModCtrl, '[', del_indent }, -- 2.51.0