Commit 3f12ada4 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

add various fill-related cleanups, plus some related cosmetic and

formatting fixes


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2934 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 58 additions and 59 deletions
+58 -59
...@@ -108,6 +108,13 @@ CVS code - ...@@ -108,6 +108,13 @@ CVS code -
copy_from_filestruct(), do_delete(), do_enter(), do_wrap(), copy_from_filestruct(), do_delete(), do_enter(), do_wrap(),
do_justify(), do_alt_speller(), do_wordlinechar_count(), do_justify(), do_alt_speller(), do_wordlinechar_count(),
new_magicline(), remove_magicline(), and do_cursorpos(). (DLR) 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: - color.c:
- Remove unneeded string.h and fcntl.h includes. (DLR) - Remove unneeded string.h and fcntl.h includes. (DLR)
- chars.c: - chars.c:
...@@ -180,6 +187,8 @@ CVS code - ...@@ -180,6 +187,8 @@ CVS code -
- When opening files with "+LINE,COLUMN" arguments on the - When opening files with "+LINE,COLUMN" arguments on the
command line, don't update the screen when moving to their command line, don't update the screen when moving to their
specified lines and columns. (DLR) specified lines and columns. (DLR)
- Rename variable fill_flag_used to fill_used, for consistency.
(DLR)
- nano.h: - nano.h:
- Since we only use vsnprintf() now, remove the #ifdef block for - Since we only use vsnprintf() now, remove the #ifdef block for
HAVE_SNPRINTF. (DLR) HAVE_SNPRINTF. (DLR)
......
...@@ -28,15 +28,13 @@ ...@@ -28,15 +28,13 @@
/* Global variables */ /* Global variables */
#ifndef DISABLE_WRAPJUSTIFY #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; ssize_t wrap_at = -CHARS_FROM_EOL;
/* The position that corresponds to /* The position where we will wrap
* fill. If it's greater than zero, * lines. fill is equal to this if it's
* fill is equal to it. Otherwise, fill * greater than zero, and equal to
* is equal to the number of screen * (COLS + this) if it isn't. */
* columns less it. This allows
* dynamic wrapping based on the current
* screen width. */
#endif #endif
char *last_search = NULL; /* Last string we searched for */ char *last_search = NULL; /* Last string we searched for */
......
...@@ -619,33 +619,21 @@ void die_save_file(const char *die_filename) ...@@ -619,33 +619,21 @@ void die_save_file(const char *die_filename)
free(retval); free(retval);
} }
/* Die with an error message that the screen was too small if, well, the void window_init(void)
* screen is too small. */
void check_die_too_small(void)
{ {
/* If the screen height is too small, get out. */
editwinrows = LINES - 5 + no_more_space() + no_help(); editwinrows = LINES - 5 + no_more_space() + no_help();
if (editwinrows < MIN_EDITOR_ROWS) if (editwinrows < MIN_EDITOR_ROWS)
die(_("Window size is too small for nano...\n")); 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 #ifndef DISABLE_WRAPJUSTIFY
/* Set up fill, based on the screen width. */
fill = wrap_at; fill = wrap_at;
if (fill <= 0) if (fill <= 0)
fill += COLS; fill += COLS;
if (fill < 0) if (fill < 0)
fill = 0; fill = 0;
#endif #endif
}
void window_init(void)
{
check_die_too_small();
if (topwin != NULL) if (topwin != NULL)
delwin(topwin); delwin(topwin);
...@@ -1370,9 +1358,6 @@ void handle_sigwinch(int s) ...@@ -1370,9 +1358,6 @@ void handle_sigwinch(int s)
COLS = win.ws_col; COLS = win.ws_col;
LINES = win.ws_row; LINES = win.ws_row;
/* Reinitialize the window size variables. */
window_size_init();
/* If we've partitioned the filestruct, unpartition it now. */ /* If we've partitioned the filestruct, unpartition it now. */
if (filepart != NULL) if (filepart != NULL)
unpartition_filestruct(&filepart); unpartition_filestruct(&filepart);
...@@ -1880,7 +1865,7 @@ int main(int argc, char **argv) ...@@ -1880,7 +1865,7 @@ int main(int argc, char **argv)
ssize_t startcol = 1; ssize_t startcol = 1;
/* Column to try and start at. */ /* Column to try and start at. */
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
bool fill_flag_used = FALSE; bool fill_used = FALSE;
/* Was the fill option used? */ /* Was the fill option used? */
#endif #endif
#ifdef ENABLE_MULTIBUFFER #ifdef ENABLE_MULTIBUFFER
...@@ -2102,7 +2087,7 @@ int main(int argc, char **argv) ...@@ -2102,7 +2087,7 @@ int main(int argc, char **argv)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
exit(1); exit(1);
} }
fill_flag_used = TRUE; fill_used = TRUE;
break; break;
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
...@@ -2191,7 +2176,7 @@ int main(int argc, char **argv) ...@@ -2191,7 +2176,7 @@ int main(int argc, char **argv)
} }
#endif #endif
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
if (fill_flag_used) if (fill_used)
wrap_at = wrap_at_cpy; wrap_at = wrap_at_cpy;
#endif #endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
...@@ -2317,20 +2302,20 @@ int main(int argc, char **argv) ...@@ -2317,20 +2302,20 @@ int main(int argc, char **argv)
/* Turn the cursor on for sure. */ /* Turn the cursor on for sure. */
curs_set(1); curs_set(1);
/* Initialize the window size variables. */ #ifdef DEBUG
window_size_init(); fprintf(stderr, "Main: set up windows\n");
#endif
/* Set up the shortcuts. */ /* Initialize all the windows based on the current screen
shortcut_init(FALSE); * dimensions. */
window_init();
/* Set up the signal handlers. */ /* Set up the signal handlers. */
signal_init(); signal_init();
#ifdef DEBUG /* Set up the shortcut lists. */
fprintf(stderr, "Main: set up windows\n"); shortcut_init(FALSE);
#endif
window_init();
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
mouse_init(); mouse_init();
#endif #endif
......
...@@ -369,8 +369,6 @@ void print_view_warning(void); ...@@ -369,8 +369,6 @@ void print_view_warning(void);
void finish(void); void finish(void);
void die(const char *msg, ...); void die(const char *msg, ...);
void die_save_file(const char *die_filename); void die_save_file(const char *die_filename);
void check_die_too_small(void);
void window_size_init(void);
void window_init(void); void window_init(void);
#ifndef DISABLE_MOUSE #ifndef DISABLE_MOUSE
void mouse_init(void); void mouse_init(void);
......
...@@ -342,22 +342,29 @@ void wrap_reset(void) ...@@ -342,22 +342,29 @@ void wrap_reset(void)
bool do_wrap(filestruct *line) bool do_wrap(filestruct *line)
{ {
size_t line_len; size_t line_len;
/* Length of the line we wrap. */ /* The length of the line we wrap. */
ssize_t wrap_loc; ssize_t wrap_loc;
/* Index of line->data where we wrap. */ /* The index of line->data where we wrap. */
#ifndef NANO_SMALL #ifndef NANO_SMALL
const char *indent_string = NULL; const char *indent_string = NULL;
/* Indentation to prepend to the new line. */ /* 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 #endif
const char *after_break; /* The text after the wrap point. */ const char *after_break;
size_t after_break_len; /* The length of after_break. */ /* The text after the wrap point. */
bool wrapping = FALSE; /* Do we prepend to the next line? */ 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; const char *next_line = NULL;
/* The next line, minus indentation. */ /* The next line, minus indentation. */
size_t next_line_len = 0; /* The length of next_line. */ size_t next_line_len = 0;
char *new_line = NULL; /* The line we create. */ /* The length of next_line. */
size_t new_line_len = 0; /* The eventual length of new_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 /* There are three steps. First, we decide where to wrap. Then, we
* create the new wrap line. Finally, we clean up. */ * create the new wrap line. Finally, we clean up. */
...@@ -1085,11 +1092,12 @@ bool find_paragraph(size_t *const quote, size_t *const par) ...@@ -1085,11 +1092,12 @@ bool find_paragraph(size_t *const quote, size_t *const par)
void do_justify(bool full_justify) void do_justify(bool full_justify)
{ {
filestruct *first_par_line = NULL; filestruct *first_par_line = NULL;
/* Will be the first line of the resulting justified paragraph. /* Will be the first line of the justified paragraph. For
* For restoring after unjustify. */ * restoring after unjustify. */
filestruct *last_par_line; filestruct *last_par_line;
/* Will be the line containing the newline after the last 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 /* We save these variables to be restored if the user
* unjustifies. */ * unjustifies. */
...@@ -1264,17 +1272,17 @@ void do_justify(bool full_justify) ...@@ -1264,17 +1272,17 @@ void do_justify(bool full_justify)
justify_format(openfile->current, quote_len + justify_format(openfile->current, quote_len +
indent_length(openfile->current->data + quote_len)); indent_length(openfile->current->data + quote_len));
while (par_len > 0 && while (par_len > 0 && strlenpt(openfile->current->data) >
strlenpt(openfile->current->data) > fill) { fill) {
size_t line_len = strlen(openfile->current->data); size_t line_len = strlen(openfile->current->data);
indent_len = strlen(indent_string); indent_len = strlen(indent_string);
/* If this line is too long, try to wrap it to the next line /* If this line is too long, try to wrap it to the next line
* to make it short enough. */ * to make it short enough. */
break_pos = break_pos = break_line(openfile->current->data + indent_len,
break_line(openfile->current->data + indent_len, fill - fill - strnlenpt(openfile->current->data, indent_len),
strnlenpt(openfile->current->data, indent_len), FALSE); FALSE);
/* We can't break the line, or don't need to, so get out. */ /* We can't break the line, or don't need to, so get out. */
if (break_pos == -1 || break_pos + indent_len == line_len) if (break_pos == -1 || break_pos + indent_len == line_len)
...@@ -1888,6 +1896,10 @@ const char *do_alt_speller(char *tempfile_name) ...@@ -1888,6 +1896,10 @@ const char *do_alt_speller(char *tempfile_name)
/* Turn the cursor back on for sure. */ /* Turn the cursor back on for sure. */
curs_set(1); 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) || if (!WIFEXITED(alt_spell_status) ||
WEXITSTATUS(alt_spell_status) != 0) { WEXITSTATUS(alt_spell_status) != 0) {
char *altspell_error; char *altspell_error;
...@@ -1922,9 +1934,6 @@ const char *do_alt_speller(char *tempfile_name) ...@@ -1922,9 +1934,6 @@ const char *do_alt_speller(char *tempfile_name)
} }
#endif #endif
/* Set up the window size. */
window_size_init();
/* Reinitialize the text of the current buffer. */ /* Reinitialize the text of the current buffer. */
free_filestruct(openfile->fileage); free_filestruct(openfile->fileage);
initialize_buffer_text(); initialize_buffer_text();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment