nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH V2] new feature: the ability to set an anchor to whi


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH V2] new feature: the ability to set an anchor to which one can jump back
Date: Thu, 8 Nov 2018 19:56:39 +0100

The function is bound by default to M-'.  A first press of M-'
will set the anchor at the current cursor position.  A second
press will jump to this anchor (if the cursor has moved in the
meantime) and will clear it.

The anchor is not visible in any way.
---
 src/files.c  |  1 +
 src/global.c |  5 +++++
 src/nano.h   |  4 ++++
 src/proto.h  |  1 +
 src/text.c   | 16 ++++++++++++++++
 5 files changed, 27 insertions(+)

diff --git a/src/files.c b/src/files.c
index bbdcd289..857be2cc 100644
--- a/src/files.c
+++ b/src/files.c
@@ -97,6 +97,7 @@ void make_new_buffer(void)
        openfile->modified = FALSE;
 #ifndef NANO_TINY
        openfile->mark = NULL;
+       openfile->anchor = NULL;
 
        openfile->fmt = NIX_FILE;
 
diff --git a/src/global.c b/src/global.c
index 611649d6..aea8b562 100644
--- a/src/global.c
+++ b/src/global.c
@@ -645,6 +645,7 @@ void shortcut_init(void)
                N_("Comment/uncomment the current line (or marked lines)");
 #endif
        const char *savefile_gist = N_("Save file without prompting");
+       const char *anchor_gist = N_("Place an anchor, or jump to it and clear 
it");
        const char *findprev_gist = N_("Search next occurrence backward");
        const char *findnext_gist = N_("Search next occurrence forward");
 #ifndef NANO_TINY
@@ -988,6 +989,9 @@ void shortcut_init(void)
        add_to_funcs(run_macro, MMAIN,
                N_("Run Macro"), WITHORSANS(runmacro_gist), BLANKAFTER, VIEW);
 
+       add_to_funcs(do_anchor, MMAIN,
+               N_("Anchor"), WITHORSANS(anchor_gist), BLANKAFTER, VIEW);
+
        add_to_funcs(zap_text, MMAIN,
                N_("Zap Text"), WITHORSANS(zap_gist), BLANKAFTER, NOVIEW);
 
@@ -1145,6 +1149,7 @@ void shortcut_init(void)
        add_to_sclist(MMAIN, "M-A", 0, do_mark, 0);
        add_to_sclist(MMAIN, "^6", 0, do_mark, 0);
        add_to_sclist(MMAIN, "^^", 0, do_mark, 0);
+       add_to_sclist(MMAIN, "M-'", 0, do_anchor, 0);
        add_to_sclist(MMAIN, "M-6", 0, do_copy_text, 0);
        add_to_sclist(MMAIN, "M-^", 0, do_copy_text, 0);
        add_to_sclist(MMAIN, "M-}", 0, do_indent, 0);
diff --git a/src/nano.h b/src/nano.h
index 04aa3150..1bd82c88 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -390,6 +390,10 @@ typedef struct openfilestruct {
                /* The mark's x position in the above line. */
        mark_type kind_of_mark;
                /* Whether it is a soft (with Shift) or a hard mark. */
+       filestruct *anchor;
+               /* The line where the "anchor" was dropped; NULL if it isn't. */
+       size_t anchor_x;
+               /* The x position of the anchor in the above line. */
        file_format fmt;
                /* The file's format -- Unix or DOS or Mac or mixed. */
        undo *undotop;
diff --git a/src/proto.h b/src/proto.h
index b6c50e58..87eedec2 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -496,6 +496,7 @@ void do_find_bracket(void);
 /* Most functions in text.c. */
 #ifndef NANO_TINY
 void do_mark(void);
+void do_anchor(void);
 #endif
 void do_delete(void);
 void do_backspace(void);
diff --git a/src/text.c b/src/text.c
index abdd243d..55a64a9d 100644
--- a/src/text.c
+++ b/src/text.c
@@ -68,6 +68,22 @@ void do_mark(void)
                refresh_needed = TRUE;
        }
 }
+
+/* Place an anchor when none exists, otherwise jump to it and clear it. */
+void do_anchor(void)
+{
+       if (openfile->anchor == NULL) {
+               openfile->anchor = openfile->current;
+               openfile->anchor_x = openfile->current_x;
+               statusbar(_("Placed anchor"));
+       } else {
+               openfile->current = openfile->anchor;
+               openfile->current_x = openfile->anchor_x;
+               statusbar(_("Jumped to anchor and cleared it"));
+               openfile->anchor = NULL;
+               refresh_needed = TRUE;
+       }
+}
 #endif /* !NANO_TINY */
 
 #if defined(ENABLE_COLOR) || defined(ENABLE_SPELLER)
-- 
2.19.1




reply via email to

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