nano

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

commit 063a8b087047e1eb6925700ef4e57083da74674d
parent ecc9211afc2bdf6e240cedc1c23f55a537be17d9
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 12 Jul 2018 13:09:17 +0200

startup: show the correct number of lines when opening multiple files

When switching to a different buffer, don't just show its name but
also the number of lines it contains.  This is useful extra info.

Then use this same message when at startup multiple files are opened
and (after reading them all) we switch back to the first buffer.

(This loses, when multiple files are opened, the information about
format conversion that nano still shows when a single file is opened,
but... this bug has shown that people don't really look at this line
anyway, so... let it be.  The info can still be seen when writing out
the file with ^O.)

This addresses https://savannah.gnu.org/bugs/?54047.

Diffstat:
Msrc/files.c | 17+++++++++++++----
Msrc/nano.c | 5++++-
Msrc/proto.h | 1+
3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/files.c b/src/files.c @@ -585,6 +585,17 @@ void prepare_for_display(void) } #ifdef ENABLE_MULTIBUFFER +/* Show name of current buffer and its number of lines on the status bar. */ +void mention_name_and_linecount(void) +{ + size_t count = openfile->filebot->lineno - + (openfile->filebot->data[0] == '\0' ? 1 : 0); + + statusline(HUSH, P_("%s -- %zu line", "%s -- %zu lines", count), + openfile->filename[0] == '\0' ? + _("New Buffer") : tail(openfile->filename), count); +} + /* Switch to a neighbouring file buffer; to the next if to_next is TRUE; * otherwise, to the previous one. */ void switch_to_adjacent_buffer(bool to_next) @@ -615,10 +626,8 @@ void switch_to_adjacent_buffer(bool to_next) /* Ensure that the main loop will redraw the help lines. */ currmenu = MMOST; - /* Indicate the switch on the statusbar. */ - statusline(HUSH, _("Switched to %s"), - ((openfile->filename[0] == '\0') ? - _("New Buffer") : openfile->filename)); + /* Indicate on the status bar where we switched to. */ + mention_name_and_linecount(); #ifdef DEBUG dump_filestruct(openfile->current); diff --git a/src/nano.c b/src/nano.c @@ -2652,8 +2652,11 @@ int main(int argc, char **argv) UNSET(VIEW_MODE); } #ifdef ENABLE_MULTIBUFFER - else + else { openfile = openfile->next; + if (more_than_one) + mention_name_and_linecount(); + } #endif #ifdef DEBUG diff --git a/src/proto.h b/src/proto.h @@ -273,6 +273,7 @@ void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x, #endif void prepare_for_display(void); #ifdef ENABLE_MULTIBUFFER +void mention_name_and_linecount(void); void switch_to_prev_buffer(void); void switch_to_next_buffer(void); bool close_buffer(void);