copy_from_filestruct(), do_delete(), do_enter(), do_wrap(),
do_justify(), do_alt_speller(), do_wordlinechar_count(),
new_magicline(), remove_magicline(), and do_cursorpos(). (DLR)
+ - Various fill-related cleanups. Move check_die_too_small() and
+ window_size_init()'s code into window_init(), as they really
+ belong there, remove associated separate calls to them, and
+ make sure window_init() is always called at the same time when
+ redrawing the screen. Changes to window_init(), main(), and
+ do_alt_speller(); removal of check_die_too_small() and
+ window_size_init(). (DLR)
- color.c:
- Remove unneeded string.h and fcntl.h includes. (DLR)
- chars.c:
- When opening files with "+LINE,COLUMN" arguments on the
command line, don't update the screen when moving to their
specified lines and columns. (DLR)
+ - Rename variable fill_flag_used to fill_used, for consistency.
+ (DLR)
- nano.h:
- Since we only use vsnprintf() now, remove the #ifdef block for
HAVE_SNPRINTF. (DLR)
/* Global variables */
#ifndef DISABLE_WRAPJUSTIFY
-ssize_t fill = 0; /* Where we will wrap lines. */
+ssize_t fill = 0; /* The column where we will wrap
+ * lines. */
ssize_t wrap_at = -CHARS_FROM_EOL;
- /* The position that corresponds to
- * fill. If it's greater than zero,
- * fill is equal to it. Otherwise, fill
- * is equal to the number of screen
- * columns less it. This allows
- * dynamic wrapping based on the current
- * screen width. */
+ /* The position where we will wrap
+ * lines. fill is equal to this if it's
+ * greater than zero, and equal to
+ * (COLS + this) if it isn't. */
#endif
char *last_search = NULL; /* Last string we searched for */
free(retval);
}
-/* Die with an error message that the screen was too small if, well, the
- * screen is too small. */
-void check_die_too_small(void)
+void window_init(void)
{
+ /* If the screen height is too small, get out. */
editwinrows = LINES - 5 + no_more_space() + no_help();
if (editwinrows < MIN_EDITOR_ROWS)
die(_("Window size is too small for nano...\n"));
-}
-
-/* Make sure the window size isn't too small, and reinitialize the fill
- * variable, since it depends on the window size. */
-void window_size_init(void)
-{
- check_die_too_small();
#ifndef DISABLE_WRAPJUSTIFY
+ /* Set up fill, based on the screen width. */
fill = wrap_at;
if (fill <= 0)
fill += COLS;
if (fill < 0)
fill = 0;
#endif
-}
-
-void window_init(void)
-{
- check_die_too_small();
if (topwin != NULL)
delwin(topwin);
COLS = win.ws_col;
LINES = win.ws_row;
- /* Reinitialize the window size variables. */
- window_size_init();
-
/* If we've partitioned the filestruct, unpartition it now. */
if (filepart != NULL)
unpartition_filestruct(&filepart);
ssize_t startcol = 1;
/* Column to try and start at. */
#ifndef DISABLE_WRAPJUSTIFY
- bool fill_flag_used = FALSE;
+ bool fill_used = FALSE;
/* Was the fill option used? */
#endif
#ifdef ENABLE_MULTIBUFFER
fprintf(stderr, "\n");
exit(1);
}
- fill_flag_used = TRUE;
+ fill_used = TRUE;
break;
#endif
#ifndef DISABLE_SPELLER
}
#endif
#ifndef DISABLE_WRAPJUSTIFY
- if (fill_flag_used)
+ if (fill_used)
wrap_at = wrap_at_cpy;
#endif
#ifndef NANO_SMALL
/* Turn the cursor on for sure. */
curs_set(1);
- /* Initialize the window size variables. */
- window_size_init();
+#ifdef DEBUG
+ fprintf(stderr, "Main: set up windows\n");
+#endif
- /* Set up the shortcuts. */
- shortcut_init(FALSE);
+ /* Initialize all the windows based on the current screen
+ * dimensions. */
+ window_init();
/* Set up the signal handlers. */
signal_init();
-#ifdef DEBUG
- fprintf(stderr, "Main: set up windows\n");
-#endif
+ /* Set up the shortcut lists. */
+ shortcut_init(FALSE);
- window_init();
#ifndef DISABLE_MOUSE
mouse_init();
#endif
void finish(void);
void die(const char *msg, ...);
void die_save_file(const char *die_filename);
-void check_die_too_small(void);
-void window_size_init(void);
void window_init(void);
#ifndef DISABLE_MOUSE
void mouse_init(void);
bool do_wrap(filestruct *line)
{
size_t line_len;
- /* Length of the line we wrap. */
+ /* The length of the line we wrap. */
ssize_t wrap_loc;
- /* Index of line->data where we wrap. */
+ /* The index of line->data where we wrap. */
#ifndef NANO_SMALL
const char *indent_string = NULL;
/* Indentation to prepend to the new line. */
- size_t indent_len = 0; /* The length of indent_string. */
+ size_t indent_len = 0;
+ /* The length of indent_string. */
#endif
- const char *after_break; /* The text after the wrap point. */
- size_t after_break_len; /* The length of after_break. */
- bool wrapping = FALSE; /* Do we prepend to the next line? */
+ const char *after_break;
+ /* The text after the wrap point. */
+ size_t after_break_len;
+ /* The length of after_break. */
+ bool wrapping = FALSE;
+ /* Do we prepend to the next line? */
const char *next_line = NULL;
/* The next line, minus indentation. */
- size_t next_line_len = 0; /* The length of next_line. */
- char *new_line = NULL; /* The line we create. */
- size_t new_line_len = 0; /* The eventual length of new_line. */
+ size_t next_line_len = 0;
+ /* The length of next_line. */
+ char *new_line = NULL;
+ /* The line we create. */
+ size_t new_line_len = 0;
+ /* The eventual length of new_line. */
/* There are three steps. First, we decide where to wrap. Then, we
* create the new wrap line. Finally, we clean up. */
void do_justify(bool full_justify)
{
filestruct *first_par_line = NULL;
- /* Will be the first line of the resulting justified paragraph.
- * For restoring after unjustify. */
+ /* Will be the first line of the justified paragraph. For
+ * restoring after unjustify. */
filestruct *last_par_line;
/* Will be the line containing the newline after the last line
- * of the result. Also for restoring after unjustify. */
+ * of the justified paragraph. Also for restoring after
+ * unjustify. */
/* We save these variables to be restored if the user
* unjustifies. */
justify_format(openfile->current, quote_len +
indent_length(openfile->current->data + quote_len));
- while (par_len > 0 &&
- strlenpt(openfile->current->data) > fill) {
+ while (par_len > 0 && strlenpt(openfile->current->data) >
+ fill) {
size_t line_len = strlen(openfile->current->data);
indent_len = strlen(indent_string);
/* If this line is too long, try to wrap it to the next line
* to make it short enough. */
- break_pos =
- break_line(openfile->current->data + indent_len, fill -
- strnlenpt(openfile->current->data, indent_len), FALSE);
+ break_pos = break_line(openfile->current->data + indent_len,
+ fill - strnlenpt(openfile->current->data, indent_len),
+ FALSE);
/* We can't break the line, or don't need to, so get out. */
if (break_pos == -1 || break_pos + indent_len == line_len)
/* Turn the cursor back on for sure. */
curs_set(1);
+ /* The screen might have been resized. If it has, reinitialize all
+ * the windows based on the new screen dimensions. */
+ window_init();
+
if (!WIFEXITED(alt_spell_status) ||
WEXITSTATUS(alt_spell_status) != 0) {
char *altspell_error;
}
#endif
- /* Set up the window size. */
- window_size_init();
-
/* Reinitialize the text of the current buffer. */
free_filestruct(openfile->fileage);
initialize_buffer_text();