nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH 1/3 V13] new feature: bindable functions for togglin


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 1/3 V13] new feature: bindable functions for toggling and jumping to bookmarks
Date: Mon, 17 Dec 2018 15:12:26 +0100

From: Marco Diego Aurélio Mesquita <address@hidden>

With the 'bookmark' function, the user can place a bookmark on any
line in the buffer.  Multiple lines can be bookmarked in this way.
With 'prevbookmark' and 'nextbookmark', the user can then easily
return to the bookmarked lines.  The search for a bookmark wraps
around, as if start and end of buffer are connected.

When a bookmarked line is deleted, the bookmark is deleted too.  When
such a deleted line is pasted elsewhere, the bookmark reappears with it.
A bookmark is not visible in any way.

Signed-off-by: Marco Diego Aurélio Mesquita <address@hidden>
---
 src/global.c | 16 ++++++++++++++++
 src/nano.c   |  6 ++++++
 src/nano.h   |  4 ++++
 src/proto.h  |  3 +++
 src/search.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 75 insertions(+)

diff --git a/src/global.c b/src/global.c
index 26a8f3e8..d8b4ecd9 100644
--- a/src/global.c
+++ b/src/global.c
@@ -640,6 +640,9 @@ void shortcut_init(void)
 #ifndef NANO_TINY
        const char *recordmacro_gist = N_("Start/stop recording a macro");
        const char *runmacro_gist = N_("Run the last recorded macro");
+       const char *bookmark_gist = N_("Set or remove a bookmark on the current 
line");
+       const char *prevbookmark_gist = N_("Go to previous bookmark");
+       const char *nextbookmark_gist = N_("Go to next bookmark");
 #endif
        const char *case_gist =
                N_("Toggle the case sensitivity of the search");
@@ -976,6 +979,13 @@ void shortcut_init(void)
        add_to_funcs(run_macro, MMAIN,
                N_("Run Macro"), WITHORSANS(runmacro_gist), BLANKAFTER, VIEW);
 
+       add_to_funcs(bookmark, MMAIN,
+               N_("Bookmark"), WITHORSANS(bookmark_gist), TOGETHER, NOVIEW);
+       add_to_funcs(to_prev_bookmark, MMAIN,
+               N_("Previous mark"), WITHORSANS(prevbookmark_gist), TOGETHER, 
NOVIEW);
+       add_to_funcs(to_next_bookmark, MMAIN,
+               N_("Next mark"), WITHORSANS(nextbookmark_gist), BLANKAFTER, 
NOVIEW);
+
        add_to_funcs(zap_text, MMAIN,
                N_("Zap Text"), WITHORSANS(zap_gist), BLANKAFTER, NOVIEW);
 
@@ -1521,6 +1531,12 @@ sc *strtosc(const char *input)
                s->func = record_macro;
        else if (!strcasecmp(input, "runmacro"))
                s->func = run_macro;
+       else if (!strcasecmp(input, "bookmark"))
+               s->func = bookmark;
+       else if (!strcasecmp(input, "prevbookmark"))
+               s->func = to_prev_bookmark;
+       else if (!strcasecmp(input, "nextbookmark"))
+               s->func = to_next_bookmark;
        else if (!strcasecmp(input, "undo"))
                s->func = do_undo;
        else if (!strcasecmp(input, "redo"))
diff --git a/src/nano.c b/src/nano.c
index b7525aaf..f42044cf 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -78,6 +78,9 @@ filestruct *make_new_node(filestruct *prevnode)
        newnode->prev = prevnode;
        newnode->next = NULL;
        newnode->lineno = (prevnode != NULL) ? prevnode->lineno + 1 : 1;
+#ifndef NANO_TINY
+       newnode->bookmarked = FALSE;
+#endif
 
 #ifdef ENABLE_COLOR
        newnode->multidata = NULL;
@@ -95,6 +98,9 @@ filestruct *copy_node(const filestruct *src)
        dst->next = src->next;
        dst->prev = src->prev;
        dst->lineno = src->lineno;
+#ifndef NANO_TINY
+       dst->bookmarked = src->bookmarked;
+#endif
 
 #ifdef ENABLE_COLOR
        dst->multidata = NULL;
diff --git a/src/nano.h b/src/nano.h
index 04aa3150..2237a5fd 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -283,6 +283,10 @@ typedef struct filestruct {
        short *multidata;
                /* Array of which multi-line regexes apply to this line. */
 #endif
+#ifndef NANO_TINY
+       bool bookmarked;
+               /* Whether the user bookmarked this line. */
+#endif
 } filestruct;
 
 typedef struct partition {
diff --git a/src/proto.h b/src/proto.h
index 9e6175c4..ab6034a3 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -486,6 +486,9 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool 
use_answer,
 void do_gotolinecolumn_void(void);
 #ifndef NANO_TINY
 void do_find_bracket(void);
+void bookmark(void);
+void to_prev_bookmark(void);
+void to_next_bookmark(void);
 #endif
 
 /* Most functions in text.c. */
diff --git a/src/search.c b/src/search.c
index a8b14291..245df044 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1022,4 +1022,50 @@ void do_find_bracket(void)
                }
        }
 }
+
+/* Set a bookmark on the current line, or remove an existing one. */
+void bookmark(void)
+{
+       openfile->current->bookmarked = !openfile->current->bookmarked;
+
+       statusbar(openfile->current->bookmarked ?
+                               _("Bookmarked this line") : _("Removed 
bookmark"));
+}
+
+/* Jump to the next or previous bookmark, if any. */
+static void go_to_bookmark(bool forward)
+{
+       filestruct *line = openfile->current;
+
+       do {
+               line = (forward ? line->next : line->prev);
+
+               if (line == NULL)
+                       line = (forward ? openfile->fileage : 
openfile->filebot);
+
+               if (line == openfile->current) {
+                       statusbar(line->bookmarked ?
+                                       _("This is the only bookmark") : _("No 
bookmark found"));
+                       return;
+               }
+       } while (!line->bookmarked);
+
+       openfile->current = line;
+       openfile->current_x = 0;
+
+       edit_redraw(openfile->current, CENTERING);
+       statusbar(_("Jumped to bookmark"));
+}
+
+/* Jump to the first bookmark before the current line. */
+void to_prev_bookmark(void)
+{
+       go_to_bookmark(BACKWARD);
+}
+
+/* Jump to the first bookmark after the current line. */
+void to_next_bookmark(void)
+{
+       go_to_bookmark(FORWARD);
+}
 #endif /* !NANO_TINY */
-- 
2.19.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]