From e90f0b8a33d4d27eed958f9345ea9d047742e853 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sun, 12 Jun 2005 23:20:20 +0000 Subject: [PATCH] when the mark is on, only do a word count on the marked text git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2635 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- src/nano.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/nano.c b/src/nano.c index 1aa6d398..e49a24df 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1636,8 +1636,26 @@ void do_word_count(void) size_t words = 0; size_t current_x_save = current_x, pww_save = placewewant; filestruct *current_save = current; + bool old_mark_set = ISSET(MARK_ISSET); + bool added_magicline = FALSE; + /* Whether we added a magicline after filebot. */ + filestruct *top, *bot; + size_t top_x, bot_x; + + if (old_mark_set) { + /* If the mark is on, partition the filestruct so that it + * contains only the marked text, keep track of whether the text + * will need a magicline added while we're counting words, add + * the magicline if necessary, and turn the mark off. */ + mark_order((const filestruct **)&top, &top_x, + (const filestruct **)&bot, &bot_x, NULL); + filepart = partition_filestruct(top, top_x, bot, bot_x); + if ((added_magicline = (filebot->data[0] != '\0'))) + new_magicline(); + UNSET(MARK_ISSET); + } - /* Start at the beginning of the file. */ + /* Start at the top of the file. */ current = fileage; current_x = 0; placewewant = 0; @@ -1650,13 +1668,26 @@ void do_word_count(void) words++; } - /* Go back to where we were before. */ + if (old_mark_set) { + /* If the mark was on and we added a magicline, remove it + * now. */ + if (added_magicline) + remove_magicline(); + + /* Unpartition the filestruct so that it contains all the text + * again, and turn the mark back on. */ + unpartition_filestruct(&filepart); + SET(MARK_ISSET); + } + + /* Restore where we were. */ current = current_save; current_x = current_x_save; placewewant = pww_save; /* Display the total word count on the statusbar. */ - statusbar(_("Word count: %lu"), (unsigned long)words); + statusbar("%s: %lu", old_mark_set ? _("Word Count in Selection") : + _("Word Count"), (unsigned long)words); } void do_mark(void) -- 2.39.5