convert do_para_search() to use an enum to specify its search type
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1761 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
родитель
32d19ce47c
Коммит
2e3aeae5bc
@ -107,6 +107,8 @@ CVS code -
|
||||
- Remove redundant assignment. (DLR)
|
||||
do_para_search()
|
||||
- Remove unneeded edit_update() calls. (David Benbennick)
|
||||
- Convert to use an enum to specify the search type: JUSTIFY,
|
||||
BEGIN, or END. (DLR)
|
||||
do_justify()
|
||||
- Remove unneeded edit_update() calls, and add a few minor
|
||||
efficiency tweaks. (David Benbennick)
|
||||
@ -167,6 +169,7 @@ CVS code -
|
||||
- nano.h:
|
||||
- Since REGEXP_COMPILED is only used in search.c, convert it
|
||||
from a flag to a static int there. (DLR)
|
||||
- Add justbegend enum, used in do_para_search(). (DLR)
|
||||
- proto.h:
|
||||
- Remove unused xpt() and add_marked_sameline() prototypes.
|
||||
(DLR)
|
||||
|
41
src/nano.c
41
src/nano.c
@ -2104,16 +2104,17 @@ int break_line(const char *line, int goal, int force)
|
||||
return space_loc;
|
||||
}
|
||||
|
||||
/* Search a paragraph. If search_type is 0, search for the beginning of
|
||||
* the current paragraph or, if we're at the end of it, the beginning of
|
||||
* the next paragraph. If search_type is 1, search for the beginning of
|
||||
* the current paragraph or, if we're already there, the beginning of
|
||||
* the previous paragraph. If search_type is 2, search for the end of
|
||||
* the current paragraph or, if we're already there, the end of the next
|
||||
* paragraph. Afterwards, save the quote length, paragraph length, and
|
||||
* indentation length in *quote, *par, and *indent if they aren't NULL,
|
||||
* and refresh the screen if do_refresh is TRUE. Return 0 if we found a
|
||||
* paragraph, or 1 if there was an error or we didn't find a paragraph.
|
||||
/* Search a paragraph. If search_type is JUSTIFY, search for the
|
||||
* beginning of the current paragraph or, if we're at the end of it, the
|
||||
* beginning of the next paragraph. If search_type is BEGIN, search for
|
||||
* the beginning of the current paragraph or, if we're already there,
|
||||
* the beginning of the previous paragraph. If search_type is END,
|
||||
* search for the end of the current paragraph or, if we're already
|
||||
* there, the end of the next paragraph. Afterwards, save the quote
|
||||
* length, paragraph length, and indentation length in *quote, *par, and
|
||||
* *indent if they aren't NULL, and refresh the screen if do_refresh is
|
||||
* TRUE. Return 0 if we found a paragraph, or 1 if there was an error
|
||||
* or we didn't find a paragraph.
|
||||
*
|
||||
* To explain the searching algorithm, I first need to define some
|
||||
* phrases about paragraphs and quotation:
|
||||
@ -2142,8 +2143,8 @@ int break_line(const char *line, int goal, int force)
|
||||
* A contiguous set of lines is a "paragraph" if each line is part of
|
||||
* a paragraph and only the first line is the beginning of a
|
||||
* paragraph. */
|
||||
int do_para_search(int search_type, size_t *quote, size_t *par, size_t
|
||||
*indent, int do_refresh)
|
||||
int do_para_search(justbegend search_type, size_t *quote, size_t *par,
|
||||
size_t *indent, int do_refresh)
|
||||
{
|
||||
size_t quote_len;
|
||||
/* Length of the initial quotation of the paragraph we
|
||||
@ -2215,7 +2216,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
|
||||
current = current->prev;
|
||||
current_y--;
|
||||
}
|
||||
} else if (search_type == 1) {
|
||||
} else if (search_type == BEGIN) {
|
||||
/* This line is not part of a paragraph. Move up until we get
|
||||
* to a non "blank" line, and then move down once. */
|
||||
do {
|
||||
@ -2284,7 +2285,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
|
||||
par_len++;
|
||||
}
|
||||
|
||||
if (search_type == 1) {
|
||||
if (search_type == BEGIN) {
|
||||
/* We're on the same line we started on. Move up until we get
|
||||
* to a non-"blank" line, restart the search from there until we
|
||||
* find a line that's part of a paragraph, and search once more
|
||||
@ -2328,7 +2329,7 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
|
||||
|
||||
/* If we're searching for the end of the paragraph, move down the
|
||||
* number of lines in the paragraph. */
|
||||
if (search_type == 2) {
|
||||
if (search_type == END) {
|
||||
for (; par_len > 0; current_y++, par_len--)
|
||||
current = current->next;
|
||||
}
|
||||
@ -2351,12 +2352,12 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
|
||||
|
||||
int do_para_begin(void)
|
||||
{
|
||||
return do_para_search(1, NULL, NULL, NULL, TRUE);
|
||||
return do_para_search(BEGIN, NULL, NULL, NULL, TRUE);
|
||||
}
|
||||
|
||||
int do_para_end(void)
|
||||
{
|
||||
return do_para_search(2, NULL, NULL, NULL, TRUE);
|
||||
return do_para_search(END, NULL, NULL, NULL, TRUE);
|
||||
}
|
||||
|
||||
/* If full_justify is TRUE, justify the entire file. Otherwise, justify
|
||||
@ -2412,7 +2413,8 @@ int do_justify(int full_justify)
|
||||
* where it'll be anyway if we've searched the entire file, and
|
||||
* break out of the loop; otherwise, refresh the screen and get
|
||||
* out. */
|
||||
if (do_para_search(0, "e_len, &par_len, &indent_len, FALSE) != 0) {
|
||||
if (do_para_search(JUSTIFY, "e_len, &par_len, &indent_len,
|
||||
FALSE) != 0) {
|
||||
if (full_justify) {
|
||||
/* This should be safe in the event of filebot->prev's
|
||||
* being NULL, since only last_par_line->next is used if
|
||||
@ -2542,7 +2544,8 @@ int do_justify(int full_justify)
|
||||
if (mark_beginx <= indent_len)
|
||||
mark_beginx = line_len + 1;
|
||||
else
|
||||
mark_beginx = line_len + 1 + mark_beginx - indent_len;
|
||||
mark_beginx = line_len + 1 + mark_beginx -
|
||||
indent_len;
|
||||
} else
|
||||
mark_beginx -= break_pos + 1;
|
||||
}
|
||||
|
@ -463,6 +463,10 @@ typedef enum {
|
||||
TOP, CENTER, NONE
|
||||
} topmidnone;
|
||||
|
||||
typedef enum {
|
||||
JUSTIFY, BEGIN, END
|
||||
} justbegend;
|
||||
|
||||
/* Minimum editor window rows required for nano to work correctly. */
|
||||
#define MIN_EDITOR_ROWS 3
|
||||
|
||||
|
@ -324,8 +324,8 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t
|
||||
quote_len);
|
||||
int breakable(const char *line, int goal);
|
||||
int break_line(const char *line, int goal, int force);
|
||||
int do_para_search(int search_type, size_t *quote, size_t *par, size_t
|
||||
*indent, int do_refresh);
|
||||
int do_para_search(justbegend search_type, size_t *quote, size_t *par,
|
||||
size_t *indent, int do_refresh);
|
||||
int do_para_begin(void);
|
||||
int do_para_end(void);
|
||||
int do_justify(int justify_all);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user