tweaks: switch from referencing NO_NEWLINES to referencing FINAL_NEWLINE

master
Benno Schulenberg 2019-01-29 20:17:21 +01:00
parent 54055b6174
commit b6a762232e
5 changed files with 24 additions and 29 deletions

View File

@ -67,7 +67,7 @@ void do_deletion(undo_type action)
/* If there is a magic line, and we're before it: don't eat it. */
if (joining == openfile->filebot && openfile->current_x != 0 &&
!ISSET(NO_NEWLINES)) {
ISSET(FINAL_NEWLINE)) {
#ifndef NANO_TINY
if (action == BACK)
add_undo(BACK);
@ -279,7 +279,7 @@ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append)
size_t cb_save_len = 0;
/* The length of the string at the current end of the cutbuffer,
* before we add text to it. */
bool using_magicline = !ISSET(NO_NEWLINES);
bool using_magicline = ISSET(FINAL_NEWLINE);
/* Whether an automatic newline should be added at end-of-buffer. */
bool right_side_up = TRUE;
/* There *is* no region, *or* it is marked forward. */
@ -301,7 +301,7 @@ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append)
cb_save_len = strlen(cutbottom->data);
}
/* Don't add a magic line when moving text to the cutbuffer. */
SET(NO_NEWLINES);
UNSET(FINAL_NEWLINE);
}
if (cut_till_eof) {
@ -339,7 +339,7 @@ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append)
}
/* Restore the magic-line behavior now that we're done fiddling. */
if (using_magicline)
UNSET(NO_NEWLINES);
SET(FINAL_NEWLINE);
} else
#endif /* !NANO_TINY */
@ -358,8 +358,8 @@ bool is_cuttable(bool test_cliff)
(openfile->mark == openfile->current &&
openfile->mark_x == openfile->current_x) ||
(test_cliff && openfile->current->data[openfile->current_x] == '\0' &&
((ISSET(NO_NEWLINES) && openfile->current == openfile->filebot) ||
(!ISSET(NO_NEWLINES) && openfile->current == openfile->filebot->prev))
((!ISSET(FINAL_NEWLINE) && openfile->current == openfile->filebot) ||
(ISSET(FINAL_NEWLINE) && openfile->current == openfile->filebot->prev))
#endif
)) {
#ifndef NANO_TINY
@ -428,7 +428,7 @@ void do_copy_text(void)
void do_cut_till_eof(void)
{
if ((openfile->current == openfile->filebot && openfile->current->data[0] == '\0') ||
(!ISSET(NO_NEWLINES) && openfile->current->next == openfile->filebot &&
(ISSET(FINAL_NEWLINE) && openfile->current->next == openfile->filebot &&
openfile->current->data[openfile->current_x] == '\0')) {
statusbar(_("Nothing was cut"));
return;

View File

@ -557,7 +557,7 @@ void replace_marked_buffer(const char *filename)
{
FILE *f;
int descriptor;
bool using_magicline = !ISSET(NO_NEWLINES);
bool using_magicline = ISSET(FINAL_NEWLINE);
filestruct *was_cutbuffer = cutbuffer;
descriptor = open_file(filename, FALSE, TRUE, &f);
@ -566,7 +566,7 @@ void replace_marked_buffer(const char *filename)
return;
/* Don't add a magic line when replacing text in the buffer. */
SET(NO_NEWLINES);
UNSET(FINAL_NEWLINE);
add_undo(COUPLE_BEGIN);
openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction"));
@ -584,7 +584,7 @@ void replace_marked_buffer(const char *filename)
/* Restore the magic-line behavior now that we're done fiddling. */
if (using_magicline)
UNSET(NO_NEWLINES);
SET(FINAL_NEWLINE);
add_undo(COUPLE_END);
openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction"));
@ -2054,7 +2054,7 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp,
/* If we are using a magic line, and the last line of the partition
* isn't blank, then add a newline at the end of the buffer. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0') {
if (ISSET(FINAL_NEWLINE) && openfile->filebot->data[0] != '\0') {
new_magicline();
added_magicline = TRUE;
}

View File

@ -389,7 +389,7 @@ void extract_buffer(filestruct **file_top, filestruct **file_bot,
renumber(top_save);
/* If the text doesn't end with a newline, and it should, add one. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
if (ISSET(FINAL_NEWLINE) && openfile->filebot->data[0] != '\0')
new_magicline();
}
@ -486,7 +486,7 @@ void ingraft_buffer(filestruct *somebuffer)
renumber(top_save);
/* If the text doesn't end with a newline, and it should, add one. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
if (ISSET(FINAL_NEWLINE) && openfile->filebot->data[0] != '\0')
new_magicline();
}
@ -1904,7 +1904,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
#endif
/* If we've added text to the magic line, create a new magic line. */
if (openfile->filebot == openfile->current && !ISSET(NO_NEWLINES)) {
if (openfile->filebot == openfile->current && ISSET(FINAL_NEWLINE)) {
new_magicline();
if (margin > 0)
refresh_needed = TRUE;
@ -2422,11 +2422,6 @@ int main(int argc, char **argv)
}
#endif /* ENABLE_NANORC */
if (ISSET(FINAL_NEWLINE))
UNSET(NO_NEWLINES);
else
SET(NO_NEWLINES);
if (ISSET(JUMPY_SCROLLING))
UNSET(SMOOTH_SCROLL);
else

View File

@ -682,7 +682,7 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
/* If "automatic newline" is enabled, and text has been added to the
* magic line, make a new magic line. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
if (ISSET(FINAL_NEWLINE) && openfile->filebot->data[0] != '\0')
new_magicline();
return numreplaced;

View File

@ -323,7 +323,7 @@ bool comment_line(undo_type action, filestruct *line, const char *comment_seq)
/* Length of postfix. */
size_t line_len = strlen(line->data);
if (!ISSET(NO_NEWLINES) && line == openfile->filebot)
if (ISSET(FINAL_NEWLINE) && line == openfile->filebot)
return FALSE;
if (action == COMMENT) {
@ -393,7 +393,7 @@ void do_comment(void)
get_range((const filestruct **)&top, (const filestruct **)&bot);
/* If only the magic line is selected, don't do anything. */
if (top == bot && bot == openfile->filebot && !ISSET(NO_NEWLINES)) {
if (top == bot && bot == openfile->filebot && ISSET(FINAL_NEWLINE)) {
statusbar(_("Cannot comment past end of file"));
return;
}
@ -480,7 +480,7 @@ void undo_cut(undo *u)
copy_from_buffer(u->cutbuffer);
/* If the final line was originally cut, remove the extra magic line. */
if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES) &&
if ((u->xflags & WAS_FINAL_LINE) && ISSET(FINAL_NEWLINE) &&
openfile->current != openfile->filebot)
remove_magicline();
@ -538,7 +538,7 @@ void do_undo(void)
/* TRANSLATORS: The next thirteen strings describe actions
* that are undone or redone. They are all nouns, not verbs. */
undidmsg = _("text add");
if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES))
if ((u->xflags & WAS_FINAL_LINE) && ISSET(FINAL_NEWLINE))
remove_magicline();
data = charalloc(strlen(f->data) - strlen(u->strdata) + 1);
strncpy(data, f->data, u->begin);
@ -578,7 +578,7 @@ void do_undo(void)
/* When the join was done by a Backspace at the tail of the file,
* and the nonewlines flag isn't set, do not re-add a newline that
* wasn't actually deleted; just position the cursor. */
if ((u->xflags & WAS_FINAL_BACKSPACE) && !ISSET(NO_NEWLINES)) {
if ((u->xflags & WAS_FINAL_BACKSPACE) && ISSET(FINAL_NEWLINE)) {
goto_line_posx(openfile->filebot->lineno, 0);
break;
}
@ -720,7 +720,7 @@ void do_redo(void)
switch (u->type) {
case ADD:
redidmsg = _("text add");
if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES))
if ((u->xflags & WAS_FINAL_LINE) && ISSET(FINAL_NEWLINE))
new_magicline();
data = charalloc(strlen(f->data) + strlen(u->strdata) + 1);
strncpy(data, f->data, u->begin);
@ -761,7 +761,7 @@ void do_redo(void)
/* When the join was done by a Backspace at the tail of the file,
* and the nonewlines flag isn't set, do not join anything, as
* nothing was actually deleted; just position the cursor. */
if ((u->xflags & WAS_FINAL_BACKSPACE) && !ISSET(NO_NEWLINES)) {
if ((u->xflags & WAS_FINAL_BACKSPACE) && ISSET(FINAL_NEWLINE)) {
goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
break;
}
@ -1398,7 +1398,7 @@ void update_undo(undo_type action)
if (u->lineno == u->mark_begin_lineno)
u->begin += u->mark_begin_x;
} else if (openfile->current == openfile->filebot &&
ISSET(NO_NEWLINES))
!ISSET(FINAL_NEWLINE))
u->begin = strlen(u->cutbottom->data);
}
break;
@ -2560,7 +2560,7 @@ void do_spell(void)
memcpy(stash, flags, sizeof(flags));
/* Don't add an extra newline when writing out the (selected) text. */
SET(NO_NEWLINES);
UNSET(FINAL_NEWLINE);
#ifndef NANO_TINY
if (openfile->mark)