startup: always open with the file that was mentioned first

Also when a dash is the first "file" mentioned on the command line,
nano should show this buffer at startup and not the next.

This fixes https://savannah.gnu.org/bugs/?51207.
master
Benno Schulenberg 2017-06-10 21:37:21 +02:00
parent 403e87c0a0
commit 8dffb00fd9
1 changed files with 11 additions and 38 deletions

View File

@ -1887,8 +1887,6 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int optchr; int optchr;
ssize_t startline = 0, startcol = 0;
/* Target line and column when specified on the command line. */
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
bool fill_used = FALSE; bool fill_used = FALSE;
/* Was the fill option used on the command line? */ /* Was the fill option used on the command line? */
@ -2523,15 +2521,6 @@ int main(int argc, char **argv)
fprintf(stderr, "Main: open file\n"); fprintf(stderr, "Main: open file\n");
#endif #endif
/* If there's a +LINE or +LINE,COLUMN flag here, it is the first
* non-option argument, and it is followed by at least one other
* argument, the filename it applies to. */
if (0 < optind && optind < argc - 1 && argv[optind][0] == '+') {
if (!parse_line_column(&argv[optind][1], &startline, &startcol))
statusline(ALERT, _("Invalid line or column number"));
optind++;
}
/* If one of the arguments is a dash, read text from standard input. */ /* If one of the arguments is a dash, read text from standard input. */
if (optind < argc && !strcmp(argv[optind], "-")) { if (optind < argc && !strcmp(argv[optind], "-")) {
stdin_pager(); stdin_pager();
@ -2541,20 +2530,21 @@ int main(int argc, char **argv)
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
old_multibuffer = ISSET(MULTIBUFFER); old_multibuffer = ISSET(MULTIBUFFER);
SET(MULTIBUFFER); SET(MULTIBUFFER);
#endif
/* Read all the files after the first one on the command line into /* Read the named files on the command line into new buffers. */
* new buffers. */
{ {
int i = optind + 1; int i = optind;
ssize_t iline = 0, icol = 0; ssize_t iline = 0, icol = 0;
for (; i < argc; i++) { for (; i < argc && (!openfile || ISSET(MULTIBUFFER)); i++) {
/* If there's a +LINE or +LINE,COLUMN flag here, it is followed /* If there's a +LINE or +LINE,COLUMN flag here, it is followed
* by at least one other argument: the filename it applies to. */ * by at least one other argument: the filename it applies to. */
if (i < argc - 1 && argv[i][0] == '+') { if (i < argc - 1 && argv[i][0] == '+') {
if (!parse_line_column(&argv[i][1], &iline, &icol)) if (!parse_line_column(&argv[i][1], &iline, &icol))
statusline(ALERT, _("Invalid line or column number")); statusline(ALERT, _("Invalid line or column number"));
} else { i++;
}
/* If opening fails, don't try to position the cursor. */ /* If opening fails, don't try to position the cursor. */
if (!open_buffer(argv[i], FALSE)) if (!open_buffer(argv[i], FALSE))
continue; continue;
@ -2576,38 +2566,21 @@ int main(int argc, char **argv)
#endif #endif
} }
} }
}
#endif /* ENABLE_MULTIBUFFER */
/* Now read the first file on the command line into a new buffer. */ /* If no filenames were given, or all of them were invalid things like
if (optind < argc) * directories, then open a blank buffer and allow editing. Otherwise,
open_buffer(argv[optind], FALSE); * switch from the last opened file to the next, that is: the first. */
/* If all the command-line arguments were invalid files like directories,
* or if there were no filenames given, we didn't open any file. In this
* case, load a blank buffer. Also, unset view mode to allow editing. */
if (openfile == NULL) { if (openfile == NULL) {
open_buffer("", FALSE); open_buffer("", FALSE);
UNSET(VIEW_MODE); UNSET(VIEW_MODE);
} } else
openfile = openfile->next;
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
if (!old_multibuffer) if (!old_multibuffer)
UNSET(MULTIBUFFER); UNSET(MULTIBUFFER);
#endif #endif
/* If a starting position was given on the command line, go there. */
if (startline > 0 || startcol > 0)
do_gotolinecolumn(startline, startcol, FALSE, FALSE);
#ifndef DISABLE_HISTORIES
else if (ISSET(POS_HISTORY)) {
ssize_t savedposline, savedposcol;
/* If the file was edited before, restore the last cursor position. */
if (has_old_position(argv[optind], &savedposline, &savedposcol))
do_gotolinecolumn(savedposline, savedposcol, FALSE, FALSE);
}
#endif
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Main: show title bar, and enter main loop\n"); fprintf(stderr, "Main: show title bar, and enter main loop\n");
#endif #endif