moving: make the generic paragraph movement functions work on any buffer
The functions do_para_begin() and do_para_end() can now move through any buffer, while the functions do_para_begin_void() and do_para_end_void() operate on the current buffer. The latter function also returns TRUE if the last line in the buffer is part of the paragraph.master
parent
4c0572a799
commit
c8e5c85113
56
src/move.c
56
src/move.c
|
@ -172,39 +172,41 @@ void do_page_down(void)
|
|||
#ifdef ENABLE_JUSTIFY
|
||||
/* Move to the beginning of the first-found beginning-of-paragraph line
|
||||
* before the current line. */
|
||||
void do_para_begin(void)
|
||||
void do_para_begin(filestruct **line)
|
||||
{
|
||||
if (openfile->current != openfile->fileage)
|
||||
openfile->current = openfile->current->prev;
|
||||
if ((*line)->prev != NULL)
|
||||
*line = (*line)->prev;
|
||||
|
||||
while (!begpar(openfile->current, 0))
|
||||
openfile->current = openfile->current->prev;
|
||||
|
||||
openfile->current_x = 0;
|
||||
while (!begpar(*line, 0))
|
||||
*line = (*line)->prev;
|
||||
}
|
||||
|
||||
/* Move down to the beginning of the last line of the current paragraph.
|
||||
* Then move down one line farther if there is such a line, or to the
|
||||
* end of the current line if not. A line is the last line of a paragraph
|
||||
* if it is in a paragraph, and the next line either is the beginning line
|
||||
* of a paragraph or isn't in a paragraph. */
|
||||
void do_para_end(void)
|
||||
* end of the current line if not.
|
||||
* A line is the last line of a paragraph if it is
|
||||
* in a paragraph, and the next line either is the beginning line of a
|
||||
* paragraph or isn't in a paragraph. Return whether the last line of
|
||||
* the paragraph is part of the paragraph (instead of the line following
|
||||
* the paragraph). */
|
||||
bool do_para_end(filestruct **line)
|
||||
{
|
||||
while (openfile->current != openfile->filebot &&
|
||||
!inpar(openfile->current))
|
||||
openfile->current = openfile->current->next;
|
||||
while ((*line)->next != NULL &&
|
||||
!inpar(*line))
|
||||
*line = (*line)->next;
|
||||
|
||||
while (openfile->current != openfile->filebot &&
|
||||
inpar(openfile->current->next) &&
|
||||
!begpar(openfile->current->next, 0)) {
|
||||
openfile->current = openfile->current->next;
|
||||
while ((*line)->next != NULL &&
|
||||
inpar((*line)->next) &&
|
||||
!begpar((*line)->next, 0)) {
|
||||
*line = (*line)->next;
|
||||
}
|
||||
|
||||
if (openfile->current != openfile->filebot) {
|
||||
openfile->current = openfile->current->next;
|
||||
openfile->current_x = 0;
|
||||
} else
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
if ((*line)->next != NULL) {
|
||||
*line = (*line)->next;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Move up to first start of a paragraph before the current line. */
|
||||
|
@ -212,7 +214,8 @@ void do_para_begin_void(void)
|
|||
{
|
||||
filestruct *was_current = openfile->current;
|
||||
|
||||
do_para_begin();
|
||||
do_para_begin(&openfile->current);
|
||||
openfile->current_x = 0;
|
||||
|
||||
edit_redraw(was_current, CENTERING);
|
||||
}
|
||||
|
@ -222,7 +225,10 @@ void do_para_end_void(void)
|
|||
{
|
||||
filestruct *was_current = openfile->current;
|
||||
|
||||
do_para_end();
|
||||
if (do_para_end(&openfile->current))
|
||||
openfile->current_x = strlen(openfile->current->data);
|
||||
else
|
||||
openfile->current_x = 0;
|
||||
|
||||
edit_redraw(was_current, CENTERING);
|
||||
}
|
||||
|
|
|
@ -363,8 +363,8 @@ void to_last_line(void);
|
|||
void do_page_up(void);
|
||||
void do_page_down(void);
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
void do_para_begin(void);
|
||||
void do_para_end(void);
|
||||
void do_para_begin(filestruct **line);
|
||||
bool do_para_end(filestruct **line);
|
||||
void do_para_begin_void(void);
|
||||
void do_para_end_void(void);
|
||||
#endif
|
||||
|
|
|
@ -2131,7 +2131,8 @@ bool find_paragraph(size_t *const quote, size_t *const par)
|
|||
/* If the current line isn't in a paragraph, move forward to the
|
||||
* last line of the next paragraph, if any. */
|
||||
if (!inpar(openfile->current)) {
|
||||
do_para_end();
|
||||
if (do_para_end(&openfile->current))
|
||||
openfile->current_x = strlen(openfile->filebot->data);
|
||||
|
||||
/* If we end up past the beginning of the line, it means that
|
||||
* we're at the end of the last line of the file, and the line
|
||||
|
@ -2153,14 +2154,15 @@ bool find_paragraph(size_t *const quote, size_t *const par)
|
|||
/* If the current line is in a paragraph and isn't its first line, move
|
||||
* back to the first line of the paragraph. */
|
||||
if (inpar(openfile->current) && !begpar(openfile->current, 0))
|
||||
do_para_begin();
|
||||
do_para_begin(&openfile->current);
|
||||
|
||||
/* Now current is the first line of the paragraph. Set quote_len to
|
||||
* the quotation length of that line, and set par_len to the number
|
||||
* of lines in this paragraph. */
|
||||
quote_len = quote_length(openfile->current->data);
|
||||
current_save = openfile->current;
|
||||
do_para_end();
|
||||
if (do_para_end(&openfile->current))
|
||||
openfile->current_x = strlen(openfile->filebot->data);
|
||||
par_len = openfile->current->lineno - current_save->lineno;
|
||||
|
||||
/* If we end up past the beginning of the line, it means that we're at
|
||||
|
|
Loading…
Reference in New Issue