nano-devel
[Top][All Lists]
Advanced

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

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


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] new feature: the ability to set an anchor to which one can jump
Date: Sun, 28 Oct 2018 17:41:45 +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 of M-' will clear the anchor if the cursor is already at
the anchor, and otherwise will move the cursor to the anchor.
(The anchor is not visible in any way.)
---
 src/files.c  |  1 +
 src/global.c |  4 ++++
 src/nano.h   |  4 ++++
 src/proto.h  |  1 +
 src/text.c   | 18 ++++++++++++++++++
 5 files changed, 28 insertions(+)

diff --git a/src/files.c b/src/files.c
index 5878ff00..975a9cc7 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 e1d7930f..35968be3 100644
--- a/src/global.c
+++ b/src/global.c
@@ -995,6 +995,9 @@ void shortcut_init(void)
 #endif
        add_to_funcs(do_savefile, MMAIN,
                N_("Save"), WITHORSANS(savefile_gist), BLANKAFTER, NOVIEW);
+
+       add_to_funcs(do_anchor, MMAIN,
+               N_("Anchor"), WITHORSANS("Drop or clear or jump to anchor"), 
BLANKAFTER, VIEW);
 #endif
 
 #ifndef ENABLE_JUSTIFY
@@ -1140,6 +1143,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 3007881d..ec593c23 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 an "anchor" was dropped; NULL if none is. */
+       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 a157ece0..600e8afb 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -495,6 +495,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 8302c7dd..bd39d9b0 100644
--- a/src/text.c
+++ b/src/text.c
@@ -68,6 +68,24 @@ void do_mark(void)
                refresh_needed = TRUE;
        }
 }
+
+/* Clear an existing anchor when there, or jump to it, or drop a new one. */
+void do_anchor(void)
+{
+       if (openfile->current == openfile->anchor &&
+                               openfile->current_x == openfile->anchor_x) {
+               openfile->anchor = NULL;
+               statusbar(_("Cleared anchor"));
+       } else if (openfile->anchor) {
+               openfile->current = openfile->anchor;
+               openfile->current_x = openfile->anchor_x;
+               refresh_needed = TRUE;
+       } else {
+               openfile->anchor = openfile->current;
+               openfile->anchor_x = openfile->current_x;
+               statusbar(_("Dropped anchor"));
+       }
+}
 #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]