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
Этот коммит содержится в:
родитель
520a90c8d9
Коммит
3f12ada4ef
@ -108,6 +108,13 @@ CVS code -
|
||||
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:
|
||||
@ -180,6 +187,8 @@ CVS code -
|
||||
- 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)
|
||||
|
14
src/global.c
14
src/global.c
@ -28,15 +28,13 @@
|
||||
|
||||
/* 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 */
|
||||
|
45
src/nano.c
45
src/nano.c
@ -619,33 +619,21 @@ void die_save_file(const char *die_filename)
|
||||
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);
|
||||
@ -1370,9 +1358,6 @@ void handle_sigwinch(int s)
|
||||
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);
|
||||
@ -1880,7 +1865,7 @@ int main(int argc, char **argv)
|
||||
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
|
||||
@ -2102,7 +2087,7 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
||||
fill_flag_used = TRUE;
|
||||
fill_used = TRUE;
|
||||
break;
|
||||
#endif
|
||||
#ifndef DISABLE_SPELLER
|
||||
@ -2191,7 +2176,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
#ifndef DISABLE_WRAPJUSTIFY
|
||||
if (fill_flag_used)
|
||||
if (fill_used)
|
||||
wrap_at = wrap_at_cpy;
|
||||
#endif
|
||||
#ifndef NANO_SMALL
|
||||
@ -2317,20 +2302,20 @@ int main(int argc, char **argv)
|
||||
/* Turn the cursor on for sure. */
|
||||
curs_set(1);
|
||||
|
||||
/* Initialize the window size variables. */
|
||||
window_size_init();
|
||||
|
||||
/* Set up the shortcuts. */
|
||||
shortcut_init(FALSE);
|
||||
|
||||
/* Set up the signal handlers. */
|
||||
signal_init();
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Main: set up windows\n");
|
||||
#endif
|
||||
|
||||
/* Initialize all the windows based on the current screen
|
||||
* dimensions. */
|
||||
window_init();
|
||||
|
||||
/* Set up the signal handlers. */
|
||||
signal_init();
|
||||
|
||||
/* Set up the shortcut lists. */
|
||||
shortcut_init(FALSE);
|
||||
|
||||
#ifndef DISABLE_MOUSE
|
||||
mouse_init();
|
||||
#endif
|
||||
|
@ -369,8 +369,6 @@ void print_view_warning(void);
|
||||
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);
|
||||
|
49
src/text.c
49
src/text.c
@ -342,22 +342,29 @@ void wrap_reset(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. */
|
||||
@ -1085,11 +1092,12 @@ bool find_paragraph(size_t *const quote, size_t *const par)
|
||||
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. */
|
||||
@ -1264,17 +1272,17 @@ void do_justify(bool full_justify)
|
||||
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)
|
||||
@ -1888,6 +1896,10 @@ const char *do_alt_speller(char *tempfile_name)
|
||||
/* 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;
|
||||
@ -1922,9 +1934,6 @@ const char *do_alt_speller(char *tempfile_name)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set up the window size. */
|
||||
window_size_init();
|
||||
|
||||
/* Reinitialize the text of the current buffer. */
|
||||
free_filestruct(openfile->fileage);
|
||||
initialize_buffer_text();
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user