Accordingly, remove the globals. Changes to pretty much
every function. Rename global_init() resize_init(), rename
add_open_file() make_new_buffer(), rename load_buffer()
- open_buffer(), rename open_prevnext_file()
- switch_to_prevnext_buffer(), rename open_prevfile_void()
- switch_to_prev_buffer(), rename open_nextfile_void()
- switch_to_next_buffer(), remove load_file(), and remove
- load_open_file(). (DLR)
+ open_buffer(), rename load_open_file() load_buffer(), rename
+ open_prevnext_file() switch_to_prevnext_buffer(), rename
+ open_prevfile_void() switch_to_prev_buffer(), rename
+ open_nextfile_void() switch_to_next_buffer(), remove
+ load_file(), rename cancel_fork() cancel_command(),
+ rename open_pipe() execute_command(), and remove
+ execute_command(). (DLR)
- files.c:
open_file()
- Assert that filename isn't NULL, and don't do anything special
#endif
}
- /* If we have a file, move back to the first line of it if we're
- * loading into a new buffer. Then update the titlebar, the colors
- * (if applicable), and the edit window. */
- if (rc != -1) {
- if (new_buffer)
- openfile->current = openfile->fileage;
+ /* If we have a file and we're loading into a new buffer, move back
+ * to the first line of the buffer. */
+ if (rc != -1 && new_buffer)
+ openfile->current = openfile->fileage;
+}
+/* Update the screen to account for the current buffer. */
+void load_buffer(void)
+{
titlebar(NULL);
#ifdef ENABLE_COLOR
update_color();
#endif
edit_refresh();
- }
}
#ifdef ENABLE_MULTIBUFFER
fprintf(stderr, "filename is %s\n", openfile->filename);
#endif
+ /* Update the screen to account for the current buffer. */
+ load_buffer();
+
/* Indicate the switch on the statusbar. */
statusbar(_("Switched to %s"),
((openfile->filename[0] == '\0') ? _("New Buffer") :
return buf;
}
-#ifndef NANO_SMALL
-void execute_command(const char *command)
-{
-#ifdef ENABLE_MULTIBUFFER
- if (ISSET(MULTIBUFFER))
- /* Add a new entry to the openfile structure. */
- open_buffer("");
-#endif
-
- open_pipe(command);
-}
-#endif /* !NANO_SMALL */
-
void do_insertfile(
#ifndef NANO_SMALL
bool execute
#endif
#ifndef NANO_SMALL
- if (execute)
+ if (execute) {
+#ifdef ENABLE_MULTIBUFFER
+ if (ISSET(MULTIBUFFER))
+ /* Open a new blank buffer. */
+ open_buffer("");
+#endif
+
+ /* Save the command's output in the current buffer. */
execute_command(answer);
- else {
+ } else {
#endif
+ /* Make sure the path to the file specified in answer is
+ * tilde-expanded. */
answer = mallocstrassn(answer,
real_dir_from_tilde(answer));
+
+ /* Save the file specified in answer in the current
+ * buffer. */
open_buffer(answer);
#ifndef NANO_SMALL
}
#endif
#ifdef ENABLE_MULTIBUFFER
- if (!ISSET(MULTIBUFFER))
+ if (ISSET(MULTIBUFFER))
+ /* Update the screen to account for the current
+ * buffer. */
+ load_buffer();
+ else
#endif
{
filestruct *top_save = openfile->fileage;
* partition. */
renumber(top_save);
- /* Set edittop back to what it was before. */
+ /* Restore the old edittop. */
openfile->edittop = edittop_save;
- }
-#ifdef ENABLE_MULTIBUFFER
- if (ISSET(MULTIBUFFER))
- /* Update the titlebar. */
- titlebar(NULL);
- else {
-#endif
+ /* Restore the old place we want. */
+ openfile->placewewant = pww_save;
+
/* Mark the file as modified. */
set_modified();
- /* Restore the old place we want. */
- openfile->placewewant = pww_save;
-#ifdef ENABLE_MULTIBUFFER
+ /* Update the screen. */
+ edit_refresh();
}
-#endif
-
- /* Refresh the screen. */
- edit_refresh();
break;
}
static sigjmp_buf jmpbuf; /* Used to return to main() after a
SIGWINCH. */
static int pid; /* The PID of the newly forked process
- * in open_pipe(). It must be global
- * because the signal handler needs
- * it. */
+ * in execute_command(). It must be
+ * global because the signal handler
+ * needs it. */
#endif
#ifndef DISABLE_JUSTIFY
}
#ifndef NANO_SMALL
-void cancel_fork(int signal)
+void cancel_command(int signal)
{
if (kill(pid, SIGKILL) == -1)
nperror("kill");
}
/* Return TRUE on success. */
-bool open_pipe(const char *command)
+bool execute_command(const char *command)
{
int fd[2];
FILE *f;
sig_failed = TRUE;
nperror("sigaction");
} else {
- newaction.sa_handler = cancel_fork;
+ newaction.sa_handler = cancel_command;
if (sigaction(SIGINT, &newaction, &oldaction) == -1) {
sig_failed = TRUE;
nperror("sigaction");
UNSET(VIEW_MODE);
}
+ /* Update the screen to account for the current buffer. */
+ load_buffer();
+
#ifdef ENABLE_MULTIBUFFER
if (!old_multibuffer)
UNSET(MULTIBUFFER);
fprintf(stderr, "Main: top and bottom win\n");
#endif
- titlebar(NULL);
display_main_list();
if (startline > 1 || startcol > 1)
#endif
void make_new_buffer(void);
void open_buffer(const char *filename);
+void load_buffer(void);
#ifdef ENABLE_MULTIBUFFER
void switch_to_prevnext_buffer(bool next);
void switch_to_prev_buffer_void(void);
void read_file(FILE *f, const char *filename);
int open_file(const char *filename, bool newfie, FILE **f);
char *get_next_filename(const char *name, const char *suffix);
-#ifndef NANO_SMALL
-void execute_command(const char *command);
-#endif
void do_insertfile(
#ifndef NANO_SMALL
bool execute
int no_help(void);
void nano_disabled_msg(void);
#ifndef NANO_SMALL
-void cancel_fork(int signal);
-bool open_pipe(const char *command);
+void cancel_command(int signal);
+bool execute_command(const char *command);
#endif
void do_verbatim_input(void);
void do_backspace(void);