>From e9dc45feadd733cb7256d63b1002be4b1f3a0d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Mon, 12 Nov 2018 18:30:47 -0200 Subject: [PATCH] new feature: ability to toogle and jump to bookmarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Toggling bookmarks is bound to M-Ins. A buffer can have multiple bookmarks but it can only have one bookmark per line. Jumping to next bookmark is bound to M-PgDn and jumping to previous bookmark is bound to M-PgUp. (Bookmarks are not visible in any way.) Signed-off-by: Marco Diego Aurélio Mesquita --- src/global.c | 5 ++++- src/nano.c | 4 ++++ src/nano.h | 7 +++++++ src/proto.h | 5 ++++- src/text.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/winio.c | 6 ++++++ 6 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/global.c b/src/global.c index 611649d6..a27356af 100644 --- a/src/global.c +++ b/src/global.c @@ -76,7 +76,7 @@ int shiftleft, shiftright, shiftup, shiftdown; int shiftcontrolleft, shiftcontrolright, shiftcontrolup, shiftcontroldown; int shiftcontrolhome, shiftcontrolend; int altleft, altright, altup, altdown; -int altdelete; +int altinsert, altdelete, altpageup, altpagedown; int shiftaltleft, shiftaltright, shiftaltup, shiftaltdown; #endif @@ -1157,7 +1157,10 @@ void shortcut_init(void) add_to_sclist(MMAIN, "M-E", 0, do_redo, 0); add_to_sclist(MMAIN, "Sh-^Del", CONTROL_SHIFT_DELETE, do_cut_prev_word, 0); add_to_sclist(MMAIN, "^Del", CONTROL_DELETE, do_cut_next_word, 0); + add_to_sclist(MMAIN, "M-Ins", ALT_INSERT, do_bookmark, 0); add_to_sclist(MMAIN, "M-Del", ALT_DELETE, zap_text, 0); + add_to_sclist(MMAIN, "M-PgUp", ALT_PAGEUP, do_bookmark_previous, 0); + add_to_sclist(MMAIN, "M-PgDn", ALT_PAGEDOWN, do_bookmark_next, 0); #endif #ifdef ENABLE_WORDCOMPLETION add_to_sclist(MMAIN, "^]", 0, complete_a_word, 0); diff --git a/src/nano.c b/src/nano.c index e121722a..b696aded 100644 --- a/src/nano.c +++ b/src/nano.c @@ -78,6 +78,7 @@ filestruct *make_new_node(filestruct *prevnode) newnode->prev = prevnode; newnode->next = NULL; newnode->lineno = (prevnode != NULL) ? prevnode->lineno + 1 : 1; + newnode->bookmarked = FALSE; #ifdef ENABLE_COLOR newnode->multidata = NULL; @@ -2594,7 +2595,10 @@ int main(int argc, char **argv) altright = get_keycode("kRIT3", ALT_RIGHT); altup = get_keycode("kUP3", ALT_UP); altdown = get_keycode("kDN3", ALT_DOWN); + altinsert = get_keycode("kIC3", ALT_INSERT); altdelete = get_keycode("kDC3", ALT_DELETE); + altpageup = get_keycode("kPRV3", ALT_PAGEUP); + altpagedown = get_keycode("kNXT3", ALT_PAGEDOWN); shiftaltleft = get_keycode("kLFT4", SHIFT_ALT_LEFT); shiftaltright = get_keycode("kRIT4", SHIFT_ALT_RIGHT); diff --git a/src/nano.h b/src/nano.h index 04aa3150..808ae740 100644 --- a/src/nano.h +++ b/src/nano.h @@ -279,6 +279,10 @@ typedef struct filestruct { /* Next node. */ struct filestruct *prev; /* Previous node. */ + bool bookmarked; + /* Whether this line is bookmarked. */ + size_t bookmark_x; + /* Bookmark position for this line. */ #ifdef ENABLE_COLOR short *multidata; /* Array of which multi-line regexes apply to this line. */ @@ -594,7 +598,10 @@ enum #define ALT_RIGHT 0x422 #define ALT_UP 0x423 #define ALT_DOWN 0x424 +#define ALT_INSERT 0x42C #define ALT_DELETE 0x42D +#define ALT_PAGEUP 0x427 +#define ALT_PAGEDOWN 0x428 #define SHIFT_ALT_LEFT 0x431 #define SHIFT_ALT_RIGHT 0x432 #define SHIFT_ALT_UP 0x433 diff --git a/src/proto.h b/src/proto.h index b6c50e58..309daf63 100644 --- a/src/proto.h +++ b/src/proto.h @@ -67,7 +67,7 @@ extern int shiftcontrolup, shiftcontroldown; extern int shiftcontrolhome, shiftcontrolend; extern int altleft, altright; extern int altup, altdown; -extern int altdelete; +extern int altinsert, altdelete, altpageup, altpagedown; extern int shiftaltleft, shiftaltright; extern int shiftaltup, shiftaltdown; #endif @@ -496,6 +496,9 @@ void do_find_bracket(void); /* Most functions in text.c. */ #ifndef NANO_TINY void do_mark(void); +void do_bookmark(void); +void do_bookmark_next(void); +void do_bookmark_previous(void); #endif void do_delete(void); void do_backspace(void); diff --git a/src/text.c b/src/text.c index abdd243d..836fda00 100644 --- a/src/text.c +++ b/src/text.c @@ -68,6 +68,49 @@ void do_mark(void) refresh_needed = TRUE; } } + +/* Toggles bookmark. */ +void do_bookmark(void) +{ + openfile->current->bookmarked = !openfile->current->bookmarked; + openfile->current->bookmark_x = openfile->current_x; + + statusbar(openfile->current->bookmarked ? + _("Bookmark added.") : + _("Bookmark removed.")); +} + +/* Goes to next or previous bookmark. */ +void go_to_book_mark(bool next) +{ + filestruct *aux = openfile->current; + + do + aux = next ? aux->next : aux->prev; + while(aux != NULL && !aux->bookmarked); + + if (aux == NULL) { + statusbar(next ? + _("No Bookmark after this point.") : + _("No bookmark before this point.")); + return; + } + + openfile->current = aux; + openfile->current_x = aux->bookmark_x; + refresh_needed = TRUE; +} + +void do_bookmark_next(void) +{ + go_to_book_mark(TRUE); +} + +void do_bookmark_previous(void) +{ + go_to_book_mark(FALSE); +} + #endif /* !NANO_TINY */ #if defined(ENABLE_COLOR) || defined(ENABLE_SPELLER) diff --git a/src/winio.c b/src/winio.c index 908225db..cf19c182 100644 --- a/src/winio.c +++ b/src/winio.c @@ -570,8 +570,14 @@ int parse_kbinput(WINDOW *win) return ALT_UP; else if (retval == altdown) return ALT_DOWN; + else if (retval == altinsert) + return ALT_INSERT; else if (retval == altdelete) return ALT_DELETE; + else if (retval == altpageup) + return ALT_PAGEUP; + else if (retval == altpagedown) + return ALT_PAGEDOWN; else if (retval == shiftaltleft) { shift_held = TRUE; return KEY_HOME; -- 2.11.0