nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH] startup: show the correct number of lines when open


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] startup: show the correct number of lines when opening multiple files
Date: Thu, 12 Jul 2018 13:18:14 +0200

When switching to a different buffer, don't just show its name but
also the number of lines it contains.  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 the information about format conversion that nano shows
when a single file is opened, but... how often do we still uses DOS
or Mac files nowadays?)

This addresses https://savannah.gnu.org/bugs/?54047.
---
 src/files.c | 17 +++++++++++++----
 src/nano.c  |  4 +++-
 src/proto.h |  1 +
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/files.c b/src/files.c
index 41166230..39f4c2d8 100644
--- 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
index f48b4f53..a733685a 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2652,8 +2652,10 @@ int main(int argc, char **argv)
                UNSET(VIEW_MODE);
        }
 #ifdef ENABLE_MULTIBUFFER
-       else
+       else {
                openfile = openfile->next;
+               mention_name_and_linecount();
+       }
 #endif
 
 #ifdef DEBUG
diff --git a/src/proto.h b/src/proto.h
index 7e74eaef..b2edf4d0 100644
--- 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);
-- 
2.17.1




reply via email to

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