new bindable functions, 'findnext' and 'findprevious', which repeat
the last search command in a fixed direction without prompting.
* src/global.c (shortcut_init): Tweak a string.
+ * src/search.c, src/move.c: Improve a few of the comments.
2015-07-25 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (shortcut_init, strtosc), src/files.c (savefile),
{
int i, skipped = 0;
- /* If there's less than a page of text left on the screen, put the
- * cursor at the beginning of the first line of the file, and then
- * update the edit window. */
+ /* If the cursor is less than a page away from the top of the file,
+ * put it at the beginning of the first line. */
if (openfile->current->lineno == 1 || (
#ifndef NANO_TINY
!ISSET(SOFTWRAP) &&
{
int i;
- /* If there's less than a page of text left on the screen, put the
- * cursor at the beginning of the last line of the file, and then
- * update the edit window. */
+ /* If the cursor is less than a page away from the bottom of the file,
+ * put it at the end of the last line. */
if (openfile->current->lineno + maxrows - 2 >=
openfile->filebot->lineno) {
do_last_line();
#endif /* !NANO_TINY */
#ifdef HAVE_REGEX_H
+/* Calculate the size of the replacement line, taking possible
+ * subexpressions \1 to \9 into account. Return the replacement
+ * text in the passed string only when create is TRUE. */
int replace_regexp(char *string, bool create)
{
- /* We have a split personality here. If create is FALSE, just
- * calculate the size of the replacement line (necessary because of
- * subexpressions \1 to \9 in the replaced text). */
-
const char *c = last_replace;
size_t search_match_count = regmatches[0].rm_eo -
regmatches[0].rm_so;
}
#endif /* HAVE_REGEX_H */
+/* Return a copy of the current line with one needle replaced. */
char *replace_line(const char *needle)
{
char *copy;
size_t new_line_size, search_match_count;
- /* Calculate the size of the new line. */
+ /* First calculate the size of the new line. */
#ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP)) {
search_match_count = regmatches[0].rm_eo - regmatches[0].rm_so;
/* Create the buffer. */
copy = charalloc(new_line_size);
- /* The head of the original line. */
+ /* Copy the head of the original line. */
strncpy(copy, openfile->current->data, openfile->current_x);
- /* The replacement text. */
+ /* Add the replacement text. */
#ifdef HAVE_REGEX_H
if (ISSET(USE_REGEXP))
replace_regexp(copy + openfile->current_x, TRUE);
#endif
strcpy(copy + openfile->current_x, answer);
- /* The tail of the original line. */
assert(openfile->current_x + search_match_count <= strlen(openfile->current->data));
+ /* Copy the tail of the original line. */
strcat(copy, openfile->current->data + openfile->current_x +
search_match_count);
#endif
openfile->current_x += match_len + length_change - 1;
- /* Clean up. */
- openfile->totsize += mbstrlen(copy) -
- mbstrlen(openfile->current->data);
+ /* Update the file size, and put the changed line into place. */
+ openfile->totsize += mbstrlen(copy) - mbstrlen(openfile->current->data);
free(openfile->current->data);
openfile->current->data = copy;