speller: fix replacing marked text in the alternate spell checker
With read_file() revamped, it now uses partition_filestruct() indirectly via ingraft_buffer(), so we can't use partition_filestruct() to replace marked text in the alternate spell checker anymore without segfaulting. Add the new function replace_marked_buffer() to accomplish this instead. Based on replace_buffer(), it uses extract_buffer() to throw away the marked un-spell-checked text, and then uses read_file() to insert the spell-checked text at the position where the mark was. Accordingly, remove unneeded partitioning and related stuff from do_alt_speller(). Besides pasting the file into the buffer at current[current_x], ingraft_buffer() also deals with renumbering, updating totsize, and handling a magicline, so do_alt_speller() doesn't need to do those anymore.
This commit is contained in:
committed by
Benno Schulenberg
parent
0d9313763d
commit
234bd9c9be
33
src/files.c
33
src/files.c
@@ -545,6 +545,39 @@ void replace_buffer(const char *filename)
|
||||
/* Put current at a place that is certain to exist. */
|
||||
openfile->current = openfile->fileage;
|
||||
}
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* Open the specified file, and if that succeeds, blow away the text of
|
||||
* the current buffer at the given coordinates and read the file
|
||||
* contents into its place. */
|
||||
void replace_marked_buffer(const char *filename, filestruct *top, size_t top_x,
|
||||
filestruct *bot, size_t bot_x)
|
||||
{
|
||||
FILE *f;
|
||||
int descriptor;
|
||||
bool old_no_newlines = ISSET(NO_NEWLINES);
|
||||
filestruct *trash_top = NULL;
|
||||
filestruct *trash_bot = NULL;
|
||||
|
||||
descriptor = open_file(filename, FALSE, TRUE, &f);
|
||||
|
||||
if (descriptor < 0)
|
||||
return;
|
||||
|
||||
/* Don't add a magicline when replacing text in the buffer. */
|
||||
SET(NO_NEWLINES);
|
||||
|
||||
/* Throw away the text under the mark, and insert the processed file
|
||||
* where the marked text was. */
|
||||
extract_buffer(&trash_top, &trash_bot, top, top_x, bot, bot_x);
|
||||
free_filestruct(trash_top);
|
||||
read_file(f, descriptor, filename, FALSE, TRUE);
|
||||
|
||||
/* Restore the magicline behavior now that we're done fiddling. */
|
||||
if (!old_no_newlines)
|
||||
UNSET(NO_NEWLINES);
|
||||
}
|
||||
#endif /* !ENABLE_TINY */
|
||||
#endif /* !DISABLE_SPELLER */
|
||||
|
||||
/* Update the screen to account for the current buffer. */
|
||||
|
||||
Reference in New Issue
Block a user