nano

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

commit d2e261d87382ec6c506fe206f2df850d30f22235
parent 2525291ef0c7227e081f0c23ce2bac347493f3ae
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu,  3 Jul 2025 10:55:31 +0200

history: do not forget anchors when line number is given on command line

When a line number is given on the command line, the position-history
file needs to be read first, because it might contain saved anchors.

(Before placing the cursor on the given line, or searching for a given
string, the current position now needs to be set back to top-of-file,
as otherwise the saved column position is likely to be inherited, or
the search will start from the inherited position.)

This fixes https://savannah.gnu.org/bugs/?67272.

Bug existed since version 8.5, commit 60e2f2ba,
since the saving of anchors was introduced.

Diffstat:
Msrc/nano.c | 16+++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -2580,11 +2580,21 @@ int main(int argc, char **argv) continue; } +#ifdef ENABLE_HISTORIES + if (ISSET(POSITIONLOG) && openfile->filename[0] != '\0') + restore_cursor_position_if_any(); +#endif + /* If a position was given on the command line, go there. */ - if (givenline != 0 || givencol != 0) + if (givenline != 0 || givencol != 0) { + openfile->current = openfile->filetop; + openfile->placewewant = 0; goto_line_and_column(givenline, givencol, FALSE, FALSE); + } #ifndef NANO_TINY else if (searchstring != NULL) { + openfile->current = openfile->filetop; + openfile->current_x = 0; if (ISSET(USE_REGEXP)) regexp_init(searchstring); if (!findnextstr(searchstring, FALSE, JUSTFIND, NULL, @@ -2601,10 +2611,6 @@ int main(int argc, char **argv) searchstring = NULL; } #endif -#ifdef ENABLE_HISTORIES - else if (ISSET(POSITIONLOG) && openfile->filename[0] != '\0') - restore_cursor_position_if_any(); -#endif } /* After handling the files on the command line, allow inserting files. */