diff --git a/src/files.c b/src/files.c index 6a6bb1ca..bf8d8f05 100644 --- a/src/files.c +++ b/src/files.c @@ -68,6 +68,7 @@ void make_new_buffer(void) /* Make the first open file the only element in the list. */ newnode->prev = newnode; newnode->next = newnode; + firstfile = newnode; } else { /* Add the new open file after the current one in the list. */ newnode->prev = openfile; @@ -669,8 +670,10 @@ bool close_buffer(void) /* Switch to the next file buffer. */ switch_to_adjacent_buffer(TRUE); - /* Close the file buffer we had open before. */ + /* Delete the old file buffer, and adjust the count in the top bar. */ unlink_opennode(openfile->prev); + if (!inhelp) + titlebar(NULL); /* If now just one buffer remains open, show "Exit" in the help lines. */ if (openfile == openfile->next) diff --git a/src/global.c b/src/global.c index e2017115..328d20f2 100644 --- a/src/global.c +++ b/src/global.c @@ -119,6 +119,8 @@ partition *filepart = NULL; /* The "partition" where we store a portion of the current file. */ openfilestruct *openfile = NULL; /* The list of all open file buffers. */ +openfilestruct *firstfile = NULL; + /* The first open buffer. */ #ifndef NANO_TINY char *matchbrackets = NULL; diff --git a/src/nano.c b/src/nano.c index f29cea90..e706c3c1 100644 --- a/src/nano.c +++ b/src/nano.c @@ -507,6 +507,9 @@ void unlink_opennode(openfilestruct *fileptr) { assert(fileptr != fileptr->prev && fileptr != fileptr->next); + if (fileptr == firstfile) + firstfile = firstfile->next; + fileptr->prev->next = fileptr->next; fileptr->next->prev = fileptr->prev; diff --git a/src/proto.h b/src/proto.h index 8a3043ce..13cc5369 100644 --- a/src/proto.h +++ b/src/proto.h @@ -100,6 +100,7 @@ extern filestruct *cutbuffer; extern filestruct *cutbottom; extern partition *filepart; extern openfilestruct *openfile; +extern openfilestruct *firstfile; #ifndef NANO_TINY extern char *matchbrackets; diff --git a/src/winio.c b/src/winio.c index 0a27f8d6..ebc37008 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1977,6 +1977,19 @@ char *display_string(const char *buf, size_t column, size_t span, bool isdata) return converted; } +/* Determine the sequence number of the given buffer in the circular list. */ +int buffer_number(openfilestruct *buffer) +{ + int count = 1; + + while (buffer != firstfile) { + buffer = buffer->prev; + count++; + } + + return count; +} + /* If path is NULL, we're in normal editing mode, so display the current * version of nano, the current filename, and whether the current file * has been modified on the titlebar. If path isn't NULL, we're either @@ -1998,6 +2011,8 @@ void titlebar(const char *path) /* The state of the current buffer -- "Modified", "View", or "". */ char *caption; /* The presentable form of the pathname. */ + char *indicator = NULL; + /* The buffer sequence number plus buffer count. */ /* If the screen is too small, there is no titlebar. */ if (topwin == NULL) @@ -2014,6 +2029,14 @@ void titlebar(const char *path) * first sacrifice the version string, then eat up the side spaces, * then sacrifice the prefix, and only then start dottifying. */ + /* When multiple buffers are open, show which one out of how many. */ + if (path == NULL && firstfile != firstfile->next) { + indicator = charalloc(24); + sprintf(indicator, "[%i/%i]", buffer_number(openfile), + buffer_number(firstfile->prev)); + branding = indicator; + } + /* Figure out the path, prefix and state strings. */ if (inhelp) branding = ""; @@ -2064,6 +2087,8 @@ void titlebar(const char *path) } } + free(indicator); + /* If we have side spaces left, center the path name. */ if (verlen > 0) offset = verlen + (COLS - (verlen + pluglen + statelen) -