[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH] moving: allow specifying negative numbers in "Go To
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH] moving: allow specifying negative numbers in "Go To Line" |
Date: |
Tue, 21 Jun 2016 09:59:30 +0200 |
The negatives are taken to mean: from the end of the file,
and: from the end of the line.
This fulfills https://savannah.gnu.org/bugs/?48248.
---
src/search.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/search.c b/src/search.c
index f724157..837767f 100644
--- a/src/search.c
+++ b/src/search.c
@@ -930,13 +930,10 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool
use_answer,
return;
}
- /* Do a bounds check. Display a warning on an out-of-bounds
- * line or column number only if we hit Enter at the statusbar
- * prompt. */
- if (!parse_line_column(answer, &line, &column) ||
- line < 1 || column < 1) {
+ /* Extract one or two numbers from the user's response. */
+ if (!parse_line_column(answer, &line, &column)) {
if (i == 0)
- statusbar(_("Invalid line or column number"));
+ statusbar(_("Misformatted number"));
display_main_list();
return;
}
@@ -948,10 +945,24 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool
use_answer,
column = openfile->placewewant + 1;
}
+ /* Take a negative line number to mean: from the end of the file. */
+ if (line < 0)
+ line = openfile->filebot->lineno + line;
+ if (line < 1)
+ line = 1;
+
+ /* Iterate to the requested line. */
for (openfile->current = openfile->fileage; line > 1 &&
openfile->current != openfile->filebot; line--)
openfile->current = openfile->current->next;
+ /* Take a negative column number to mean: from the end of the line. */
+ if (column < 0)
+ column = strlenpt(openfile->current->data) + column + 1;
+ if (column < 1)
+ column = 1;
+
+ /* Set the x position that corresponds to the requested column. */
openfile->current_x = actual_x(openfile->current->data, column - 1);
openfile->placewewant = column - 1;
--
2.8.4
- [Nano-devel] [PATCH] moving: allow specifying negative numbers in "Go To Line",
Benno Schulenberg <=