nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH] text: let indenting/commenting skip the last line i


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] text: let indenting/commenting skip the last line if its x is zero
Date: Tue, 19 Dec 2017 20:03:28 +0100

If the marked region ends at the start of a line, do not include that
line in the indenting/undenting or commenting/uncommenting.
---
 src/proto.h |  2 ++
 src/text.c  | 12 ++++++------
 src/utils.c | 13 +++++++++++++
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/proto.h b/src/proto.h
index 2232e269..7a5c208c 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -609,6 +609,8 @@ void remove_magicline(void);
 #ifndef NANO_TINY
 void mark_order(const filestruct **top, size_t *top_x, const filestruct
        **bot, size_t *bot_x, bool *right_side_up);
+void get_region(const filestruct **top, size_t *top_x,
+        const filestruct **bot, size_t *bot_x);
 #endif
 size_t get_totsize(const filestruct *begin, const filestruct *end);
 #ifndef NANO_TINY
diff --git a/src/text.c b/src/text.c
index a01bcc86..e43319b8 100644
--- a/src/text.c
+++ b/src/text.c
@@ -300,8 +300,8 @@ void do_indent(void)
 
     /* Use either all the marked lines or just the current line. */
     if (openfile->mark)
-       mark_order((const filestruct **)&top, &top_x,
-                       (const filestruct **)&bot, &bot_x, NULL);
+       get_region((const filestruct **)&top, &top_x,
+                       (const filestruct **)&bot, &bot_x);
     else {
        top = openfile->current;
        bot = top;
@@ -405,8 +405,8 @@ void do_unindent(void)
 
     /* Use either all the marked lines or just the current line. */
     if (openfile->mark)
-       mark_order((const filestruct **)&top, &top_x,
-                       (const filestruct **)&bot, &bot_x, NULL);
+       get_region((const filestruct **)&top, &top_x,
+                       (const filestruct **)&bot, &bot_x);
     else {
        top = openfile->current;
        bot = top;
@@ -509,8 +509,8 @@ void do_comment(void)
 
     /* Determine which lines to work on. */
     if (openfile->mark)
-       mark_order((const filestruct **)&top, &top_x,
-                       (const filestruct **)&bot, &bot_x, NULL);
+       get_region((const filestruct **)&top, &top_x,
+                       (const filestruct **)&bot, &bot_x);
     else {
        top = openfile->current;
        bot = top;
diff --git a/src/utils.c b/src/utils.c
index 8d5be6db..06013deb 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -532,6 +532,19 @@ void mark_order(const filestruct **top, size_t *top_x, 
const filestruct
     }
 }
 
+/* Get the start and end points of the marked region, but
+ * push the end point back if it's at the start of a line. */
+void get_region(const filestruct **top, size_t *top_x,
+       const filestruct **bot, size_t *bot_x)
+{
+    mark_order(top, top_x, bot, bot_x, NULL);
+
+    if (*bot_x == 0) {
+       *bot = (*bot)->prev;
+       *bot_x = mbstrlen((*bot)->data);
+    }
+}
+
 /* Given a line number, return a pointer to the corresponding struct. */
 filestruct *fsfromline(ssize_t lineno)
 {
-- 
2.14.3




reply via email to

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