nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 2a51d35e25287db60319a44611ceabc89a39f6a0
parent d7e427daaced1aa5defca416eb344bd4bf4c4a88
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Fri,  4 Jul 2025 16:27:25 +0200

tweaks: split the goto function into an interactive and command-line one

Diffstat:
Msrc/history.c | 2+-
Msrc/nano.c | 2+-
Msrc/prototypes.h | 4++--
Msrc/search.c | 44++++++++++++++++++++++++--------------------
4 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/src/history.c b/src/history.c @@ -595,6 +595,6 @@ void restore_cursor_position_if_any(void) if (item && item->anchors) restore_anchors(item->anchors); if (item) - goto_line_and_column(item->linenumber, item->columnnumber, FALSE, FALSE); + goto_line_and_column(item->linenumber, item->columnnumber, FALSE); } #endif /* ENABLE_HISTORIES */ diff --git a/src/nano.c b/src/nano.c @@ -2589,7 +2589,7 @@ int main(int argc, char **argv) if (givenline != 0 || givencol != 0) { openfile->current = openfile->filetop; openfile->placewewant = 0; - goto_line_and_column(givenline, givencol, FALSE, FALSE); + goto_line_and_column(givenline, givencol, FALSE); } #ifndef NANO_TINY else if (searchstring != NULL) { diff --git a/src/prototypes.h b/src/prototypes.h @@ -484,8 +484,8 @@ void ask_for_and_do_replacements(void); #if !defined(NANO_TINY) || defined(ENABLE_SPELLER) || defined (ENABLE_LINTER) || defined (ENABLE_FORMATTER) void goto_line_posx(ssize_t line, size_t pos_x); #endif -void goto_line_and_column(ssize_t line, ssize_t column, bool retain_answer, - bool interactive); +void ask_for_line_and_column(bool retain_answer); +void goto_line_and_column(ssize_t line, ssize_t column, bool interactive); void do_gotolinecolumn(void); #ifndef NANO_TINY void do_find_bracket(void); diff --git a/src/search.c b/src/search.c @@ -155,7 +155,7 @@ void search_init(bool replacing, bool retain_answer) } else replacing = !replacing; } else if (function == flip_goto) { - goto_line_and_column(0, 0, TRUE, TRUE); + ask_for_line_and_column(TRUE); break; } else break; @@ -762,18 +762,12 @@ void goto_line_posx(ssize_t linenumber, size_t pos_x) } #endif -/* Go to the specified line and column, or ask for them if interactive - * is TRUE. In the latter case also update the screen afterwards. - * Note that both the line and column number should be one-based. */ -void goto_line_and_column(ssize_t line, ssize_t column, bool retain_answer, - bool interactive) +/* Ask for a line and maybe column number, and then jump there. */ +void ask_for_line_and_column(bool retain_answer) { - if (line == 0) - line = openfile->current->lineno; - if (column == 0) - column = openfile->placewewant + 1; + ssize_t line = openfile->current->lineno; + ssize_t column = openfile->placewewant + 1; - if (interactive) { /* Ask for the line and column. */ int response = do_prompt(MGOTOLINE, retain_answer ? answer : "", NULL, /* TRANSLATORS: This is a prompt. */ @@ -809,7 +803,20 @@ void goto_line_and_column(ssize_t line, ssize_t column, bool retain_answer, if (doublesign) line += openfile->current->lineno; - } + + goto_line_and_column(line, column, TRUE); + + adjust_viewport((*answer == ',') ? STATIONARY : CENTERING); + refresh_needed = TRUE; +} + +/* Go to the specified line and column. (Note that both are one-based.) */ +void goto_line_and_column(ssize_t line, ssize_t column, bool interactive) +{ + if (line == 0) + line = openfile->current->lineno; + if (column == 0) + column = openfile->placewewant + 1; /* Take a negative line number to mean: from the end of the file. */ if (line < 0) @@ -844,12 +851,10 @@ void goto_line_and_column(ssize_t line, ssize_t column, bool retain_answer, openfile->placewewant = breadth(openfile->current->data); #endif - /* When a line number was manually given, center the target line. */ - if (interactive) { - adjust_viewport((*answer == ',') ? STATIONARY : CENTERING); - refresh_needed = TRUE; - } else { - int rows_from_tail; + if (interactive) + return; + + int rows_from_tail; #ifndef NANO_TINY if (ISSET(SOFTWRAP)) { @@ -871,13 +876,12 @@ void goto_line_and_column(ssize_t line, ssize_t column, bool retain_answer, adjust_viewport(STATIONARY); } else adjust_viewport(CENTERING); - } } /* Go to the specified line and column, asking for them beforehand. */ void do_gotolinecolumn(void) { - goto_line_and_column(0, 0, FALSE, TRUE); + ask_for_line_and_column(FALSE); } #ifndef NANO_TINY