tweaks: pass any special undo/redo messages to the add_undo() function
For the three operations (justification, spell checking, and filtering) that need to undo or redo two suboperations (cutting and then pasting) in one go, pass the message that describes the operation to add_undo(), so that the undo item does not need to be modified after the call. This looks better, but does add some twenty NULL parameters elsewhere.master
parent
785efc2087
commit
d12191db5a
16
src/cut.c
16
src/cut.c
|
@ -42,7 +42,7 @@ void do_deletion(undo_type action)
|
|||
* line, create a new undo item, otherwise update the existing item. */
|
||||
if (action != openfile->last_action ||
|
||||
openfile->current->lineno != openfile->current_undo->lineno)
|
||||
add_undo(action);
|
||||
add_undo(action, NULL);
|
||||
else
|
||||
update_undo(action);
|
||||
|
||||
|
@ -68,13 +68,13 @@ void do_deletion(undo_type action)
|
|||
!ISSET(NO_NEWLINES)) {
|
||||
#ifndef NANO_TINY
|
||||
if (action == BACK)
|
||||
add_undo(BACK);
|
||||
add_undo(BACK, NULL);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(action);
|
||||
add_undo(action, NULL);
|
||||
#endif
|
||||
/* Add the contents of the next line to those of the current one. */
|
||||
openfile->current->data = charealloc(openfile->current->data,
|
||||
|
@ -182,7 +182,7 @@ void chop_word(bool forward)
|
|||
openfile->current_x = is_current_x;
|
||||
|
||||
/* Now kill the marked region and a word is gone. */
|
||||
add_undo(CUT);
|
||||
add_undo(CUT, NULL);
|
||||
do_snip(FALSE, TRUE, FALSE, FALSE);
|
||||
update_undo(CUT);
|
||||
|
||||
|
@ -385,7 +385,7 @@ void cut_text(void)
|
|||
* the current cut is not contiguous with the previous cutting. */
|
||||
if (openfile->last_action != CUT || !keep_cutbuffer) {
|
||||
keep_cutbuffer = FALSE;
|
||||
add_undo(CUT);
|
||||
add_undo(CUT, NULL);
|
||||
}
|
||||
|
||||
do_snip(FALSE, openfile->mark != NULL, FALSE, FALSE);
|
||||
|
@ -436,7 +436,7 @@ void cut_till_eof(void)
|
|||
return;
|
||||
}
|
||||
|
||||
add_undo(CUT_TO_EOF);
|
||||
add_undo(CUT_TO_EOF, NULL);
|
||||
do_snip(FALSE, FALSE, TRUE, FALSE);
|
||||
update_undo(CUT_TO_EOF);
|
||||
wipe_statusbar();
|
||||
|
@ -454,7 +454,7 @@ void zap_text(void)
|
|||
/* Add a new undo item only when the current item is not a ZAP or when
|
||||
* the current zap is not contiguous with the previous zapping. */
|
||||
if (openfile->last_action != ZAP || !keep_cutbuffer)
|
||||
add_undo(ZAP);
|
||||
add_undo(ZAP, NULL);
|
||||
|
||||
/* Use the cutbuffer from the ZAP undo item, so the cut can be undone. */
|
||||
cutbuffer = openfile->current_undo->cutbuffer;
|
||||
|
@ -482,7 +482,7 @@ void paste_text(void)
|
|||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(PASTE);
|
||||
add_undo(PASTE, NULL);
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
was_leftedge = leftedge_for(xplustabs(), openfile->current);
|
||||
|
|
10
src/files.c
10
src/files.c
|
@ -525,8 +525,7 @@ bool replace_buffer(const char *filename, undo_type action, bool marked)
|
|||
return FALSE;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(COUPLE_BEGIN);
|
||||
openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction"));
|
||||
add_undo(COUPLE_BEGIN, "spelling correction");
|
||||
#endif
|
||||
|
||||
/* When nothing is marked, start at the top of the buffer. */
|
||||
|
@ -538,7 +537,7 @@ bool replace_buffer(const char *filename, undo_type action, bool marked)
|
|||
/* Throw away the marked region or the whole buffer. */
|
||||
cutbuffer = NULL;
|
||||
#ifndef NANO_TINY
|
||||
add_undo(action);
|
||||
add_undo(action, NULL);
|
||||
#endif
|
||||
do_snip(FALSE, marked, !marked, FALSE);
|
||||
#ifndef NANO_TINY
|
||||
|
@ -551,8 +550,7 @@ bool replace_buffer(const char *filename, undo_type action, bool marked)
|
|||
read_file(f, descriptor, filename, TRUE);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(COUPLE_END);
|
||||
openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction"));
|
||||
add_undo(COUPLE_END, "spelling correction");
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -719,7 +717,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
|
|||
|
||||
#ifndef NANO_TINY
|
||||
if (undoable)
|
||||
add_undo(INSERT);
|
||||
add_undo(INSERT, NULL);
|
||||
|
||||
if (ISSET(SOFTWRAP))
|
||||
was_leftedge = leftedge_for(xplustabs(), openfile->current);
|
||||
|
|
|
@ -1839,7 +1839,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
|
|||
if (openfile->last_action != ADD ||
|
||||
openfile->current_undo->mark_begin_lineno != openfile->current->lineno ||
|
||||
openfile->current_undo->mark_begin_x != openfile->current_x)
|
||||
add_undo(ADD);
|
||||
add_undo(ADD, NULL);
|
||||
|
||||
/* Note that current_x has not yet been incremented. */
|
||||
if (openfile->current == openfile->mark &&
|
||||
|
|
|
@ -525,7 +525,7 @@ void do_enter(void);
|
|||
RETSIGTYPE cancel_command(int signal);
|
||||
bool execute_command(const char *command);
|
||||
void discard_until(const undostruct *thisitem, openfilestruct *thefile, bool keep);
|
||||
void add_undo(undo_type action);
|
||||
void add_undo(undo_type action, const char *message);
|
||||
void update_multiline_undo(ssize_t lineno, char *indentation);
|
||||
void update_undo(undo_type action);
|
||||
#endif /* !NANO_TINY */
|
||||
|
|
|
@ -598,7 +598,7 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
|
|||
size_t length_change;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(REPLACE);
|
||||
add_undo(REPLACE, NULL);
|
||||
#endif
|
||||
copy = replace_line(needle);
|
||||
|
||||
|
|
37
src/text.c
37
src/text.c
|
@ -159,7 +159,7 @@ void do_indent(void)
|
|||
indentation[1] = '\0';
|
||||
}
|
||||
|
||||
add_undo(INDENT);
|
||||
add_undo(INDENT, NULL);
|
||||
|
||||
/* Go through each of the lines, adding an indent to the non-empty ones,
|
||||
* and recording whatever was added in the undo item. */
|
||||
|
@ -264,7 +264,7 @@ void do_unindent(void)
|
|||
if (top == bot->next)
|
||||
return;
|
||||
|
||||
add_undo(UNINDENT);
|
||||
add_undo(UNINDENT, NULL);
|
||||
|
||||
/* Go through each of the lines, removing their leading indent where
|
||||
* possible, and saving the removed whitespace in the undo item. */
|
||||
|
@ -424,7 +424,7 @@ void do_comment(void)
|
|||
/* If all selected lines are blank, we comment them. */
|
||||
action = all_empty ? COMMENT : action;
|
||||
|
||||
add_undo(action);
|
||||
add_undo(action, NULL);
|
||||
|
||||
/* Store the comment sequence used for the operation, because it could
|
||||
* change when the file name changes; we need to know what it was. */
|
||||
|
@ -892,7 +892,7 @@ void do_enter(void)
|
|||
openfile->current->data[openfile->current_x] = '\0';
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(ENTER);
|
||||
add_undo(ENTER, NULL);
|
||||
|
||||
/* Adjust the mark if it was on the current line after the cursor. */
|
||||
if (openfile->mark == openfile->current &&
|
||||
|
@ -1018,13 +1018,12 @@ bool execute_command(const char *command)
|
|||
} else
|
||||
#endif
|
||||
{
|
||||
add_undo(COUPLE_BEGIN);
|
||||
openfile->undotop->strdata = mallocstrcpy(NULL, _("filtering"));
|
||||
add_undo(COUPLE_BEGIN, "filtering");
|
||||
if (openfile->mark == NULL) {
|
||||
openfile->current = openfile->filetop;
|
||||
openfile->current_x = 0;
|
||||
}
|
||||
add_undo(CUT);
|
||||
add_undo(CUT, NULL);
|
||||
do_snip(FALSE, openfile->mark != NULL, openfile->mark == NULL, FALSE);
|
||||
update_undo(CUT);
|
||||
}
|
||||
|
@ -1063,8 +1062,7 @@ bool execute_command(const char *command)
|
|||
read_file(stream, 0, "pipe", TRUE);
|
||||
|
||||
if (should_pipe && !ISSET(MULTIBUFFER)) {
|
||||
add_undo(COUPLE_END);
|
||||
openfile->undotop->strdata = mallocstrcpy(NULL, _("filtering"));
|
||||
add_undo(COUPLE_END, "filtering");
|
||||
}
|
||||
|
||||
/* Wait for the external command (and possibly data sender) to terminate. */
|
||||
|
@ -1118,7 +1116,7 @@ void discard_until(const undostruct *thisitem, openfilestruct *thefile, bool kee
|
|||
}
|
||||
|
||||
/* Add a new undo item of the given type to the top of the current pile. */
|
||||
void add_undo(undo_type action)
|
||||
void add_undo(undo_type action, const char *message)
|
||||
{
|
||||
undostruct *u = nmalloc(sizeof(undostruct));
|
||||
|
||||
|
@ -1227,6 +1225,7 @@ void add_undo(undo_type action)
|
|||
case INSERT:
|
||||
case COUPLE_BEGIN:
|
||||
case COUPLE_END:
|
||||
u->strdata = mallocstrcpy(NULL, _(message));
|
||||
break;
|
||||
case INDENT:
|
||||
case UNINDENT:
|
||||
|
@ -1321,7 +1320,7 @@ void update_undo(undo_type action)
|
|||
} else {
|
||||
/* They deleted *elsewhere* on the line: start a new undo item. */
|
||||
free(char_buf);
|
||||
add_undo(u->type);
|
||||
add_undo(u->type, NULL);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
@ -1435,7 +1434,7 @@ bool do_wrap(void)
|
|||
if (ISSET(AUTOINDENT) && wrap_loc == indent_length(line->data))
|
||||
return FALSE;
|
||||
|
||||
add_undo(SPLIT_BEGIN);
|
||||
add_undo(SPLIT_BEGIN, NULL);
|
||||
#endif
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
bool autowhite = ISSET(AUTOINDENT);
|
||||
|
@ -1460,7 +1459,7 @@ bool do_wrap(void)
|
|||
/* If the remainder doesn't end in a blank, add a space. */
|
||||
if (!is_blank_mbchar(remainder + step_left(remainder, rest_length))) {
|
||||
#ifndef NANO_TINY
|
||||
add_undo(ADD);
|
||||
add_undo(ADD, NULL);
|
||||
#endif
|
||||
line->data = charealloc(line->data, line_len + 2);
|
||||
line->data[line_len] = ' ';
|
||||
|
@ -1539,7 +1538,7 @@ bool do_wrap(void)
|
|||
openfile->placewewant = xplustabs();
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(SPLIT_END);
|
||||
add_undo(SPLIT_END, NULL);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
|
@ -2039,14 +2038,13 @@ void do_justify(bool full_justify)
|
|||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(COUPLE_BEGIN);
|
||||
openfile->undotop->strdata = mallocstrcpy(NULL, _("justification"));
|
||||
add_undo(COUPLE_BEGIN, "justification");
|
||||
|
||||
/* Store the original cursor position, in case we unjustify. */
|
||||
openfile->undotop->lineno = was_lineno;
|
||||
openfile->undotop->begin = was_current_x;
|
||||
|
||||
add_undo(CUT);
|
||||
add_undo(CUT, NULL);
|
||||
#endif
|
||||
|
||||
/* Do the equivalent of a marked cut into an empty cutbuffer. */
|
||||
|
@ -2150,15 +2148,14 @@ void do_justify(bool full_justify)
|
|||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
add_undo(PASTE);
|
||||
add_undo(PASTE, NULL);
|
||||
#endif
|
||||
/* Do the equivalent of a paste of the justified text. */
|
||||
ingraft_buffer(cutbuffer);
|
||||
#ifndef NANO_TINY
|
||||
update_undo(PASTE);
|
||||
|
||||
add_undo(COUPLE_END);
|
||||
openfile->undotop->strdata = mallocstrcpy(NULL, _("justification"));
|
||||
add_undo(COUPLE_END, "justification");
|
||||
|
||||
/* If we justified marked text, restore mark or cursor position. */
|
||||
if (openfile->mark) {
|
||||
|
|
Loading…
Reference in New Issue