>From 4ae7105ddbd6d7ee70c78785147471ec6e2c1acb 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 1/2] new feature: ability to toogle and jump to bookmarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added infrastructure to toogle and jump to bookmarks. A buffer can have multiple bookmarks but it can only have one bookmark per line. It is also possible jump to next or previous bookmark. For now, bookmarks are not visible in any way. Signed-off-by: Marco Diego Aurélio Mesquita --- src/nano.c | 3 +++ src/nano.h | 2 ++ src/proto.h | 3 +++ src/text.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/src/nano.c b/src/nano.c index e121722a..3cb4cb83 100644 --- a/src/nano.c +++ b/src/nano.c @@ -78,6 +78,8 @@ filestruct *make_new_node(filestruct *prevnode) newnode->prev = prevnode; newnode->next = NULL; newnode->lineno = (prevnode != NULL) ? prevnode->lineno + 1 : 1; + /* We'll use SIZE_MAX as a sentinel value for non-bookmarked lines.*/ + newnode->bookmark_x = SIZE_MAX; #ifdef ENABLE_COLOR newnode->multidata = NULL; @@ -95,6 +97,7 @@ filestruct *copy_node(const filestruct *src) dst->next = src->next; dst->prev = src->prev; dst->lineno = src->lineno; + dst->bookmark_x = src->bookmark_x; #ifdef ENABLE_COLOR dst->multidata = NULL; diff --git a/src/nano.h b/src/nano.h index 04aa3150..87aca1fe 100644 --- a/src/nano.h +++ b/src/nano.h @@ -279,6 +279,8 @@ typedef struct filestruct { /* Next node. */ struct filestruct *prev; /* Previous node. */ + size_t bookmark_x; + /* Bookmark position for this line. */ #ifdef ENABLE_COLOR short *multidata; /* Array of which multi-line regexes apply to this line. */ diff --git a/src/proto.h b/src/proto.h index 5923670f..8de46e90 100644 --- a/src/proto.h +++ b/src/proto.h @@ -493,6 +493,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 7190de5e..d5b35522 100644 --- a/src/text.c +++ b/src/text.c @@ -62,6 +62,58 @@ void do_mark(void) refresh_needed = TRUE; } } + +/* Whether the line is bookmarked. */ +bool is_bookmarked(filestruct *line) +{ + return line->bookmark_x != SIZE_MAX; +} + +/* Toggles bookmark. */ +void do_bookmark(void) +{ + openfile->current->bookmark_x = is_bookmarked(openfile->current) ? + SIZE_MAX : + openfile->current_x; + + statusbar(is_bookmarked(openfile->current) ? + _("Bookmark added.") : + _("Bookmark removed.")); + refresh_needed = TRUE; +} + +/* 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 && !is_bookmarked(aux)); + + 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; + openfile->placewewant = xplustabs(); + 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) -- 2.11.0