[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH 12/15] tweaks: switch from referencing NO_NEWLINES t
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH 12/15] tweaks: switch from referencing NO_NEWLINES to referencing FINAL_NEWLINE |
Date: |
Thu, 31 Jan 2019 19:14:47 +0100 |
---
src/cut.c | 14 +++++++-------
src/files.c | 8 ++++----
src/nano.c | 11 +++--------
src/search.c | 2 +-
src/text.c | 18 +++++++++---------
5 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/src/cut.c b/src/cut.c
index abc8d2e8..fecf6b1a 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -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);
@@ -289,7 +289,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. */
@@ -311,7 +311,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) {
@@ -349,7 +349,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 */
@@ -368,8 +368,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
@@ -438,7 +438,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;
diff --git a/src/files.c b/src/files.c
index b1025ce9..7fe8a604 100644
--- a/src/files.c
+++ b/src/files.c
@@ -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"));
@@ -2059,7 +2059,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;
}
diff --git a/src/nano.c b/src/nano.c
index 79ddd433..06b20f71 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -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();
}
@@ -1895,7 +1895,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;
@@ -2415,11 +2415,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
diff --git a/src/search.c b/src/search.c
index 33ced4c9..71e1027b 100644
--- a/src/search.c
+++ b/src/search.c
@@ -681,7 +681,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;
diff --git a/src/text.c b/src/text.c
index 9992521c..14c2c5ec 100644
--- a/src/text.c
+++ b/src/text.c
@@ -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;
@@ -2559,7 +2559,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)
--
2.19.2
- [Nano-devel] [PATCH 02/15] options: add -f, --finalnewline, the counterpart of --nonewlines, (continued)
- [Nano-devel] [PATCH 02/15] options: add -f, --finalnewline, the counterpart of --nonewlines, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 03/15] options: add -j, --jumpyscrolling, the counterpart of --smooth, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 04/15] options: add -e, --emptyline, the counterpart of --morespace, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 05/15] rcfile: add the options that correspond to -b, -f, -j, and -e, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 06/15] options: when a nanorc unsets an old flag, set the corresponding new flag, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 07/15] options: let --fill no longer imply automatic hard-wrapping, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 08/15] docs: stop saying that --fill switches on automatic hard-wrapping, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 09/15] docs: describe the four new options (-b, -f, -j, -e) [*incomplete*], Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 10/15] options: warn when -L, -O, -S, or -w are given, and ignore them, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 11/15] tweaks: switch from referencing NO_WRAP to referencing BREAK_LONG_LINES, Benno Schulenberg, 2019/01/31
- [Nano-devel] [PATCH 12/15] tweaks: switch from referencing NO_NEWLINES to referencing FINAL_NEWLINE,
Benno Schulenberg <=