Commit a8824a19 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

per Mike Frysinger's suggestion, change the word detection functions'

behavior back to what it was before (for now, until there's a way for
the user to control it), as their new behavior makes them harder to use
when editing source code; by the same token, leave word count's behavior
the way it is, since it's generally not used when editing source code


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2765 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 86 additions and 44 deletions
+86 -44
...@@ -71,13 +71,12 @@ CVS code - ...@@ -71,13 +71,12 @@ CVS code -
mbrevstrcasestr(), etc.; removal of is_alnum_char() and mbrevstrcasestr(), etc.; removal of is_alnum_char() and
is_alnum_wchar(). (DLR) is_alnum_wchar(). (DLR)
- Implement word count via Meta-D at the main window. Note that - Implement word count via Meta-D at the main window. Note that
this is disabled when NANO_SMALL is defined. New functions this is disabled when NANO_SMALL is defined. Also, convert
do_word_count() and do_next_word_void(); changes to all word detection functions to use the same wrapper function
shortcut_init() and do_next_word(). (DLR) for ease of maintenance, and make them return more
- Detect words more accurately by taking punctuation into information. New functions is_punct_mbchar(),
account, and convert all word-detecting functions to use the is_word_mbchar(), do_next_word_void(), do_prev_word_void(),
same wrapper function for ease of maintenance. New functions and do_word_count(); changes to shortcut_init(),
is_punct_mbchar() and is_word_mbchar(); changes to
do_next_word(), do_prev_word(), is_whole_word(), do_next_word(), do_prev_word(), is_whole_word(),
do_statusbar_next_word(), and do_statusbar_prev_word(). (DLR) do_statusbar_next_word(), and do_statusbar_prev_word(). (DLR)
- Fix #ifdefs so that nano compiles with NANO_SMALL defined and - Fix #ifdefs so that nano compiles with NANO_SMALL defined and
......
...@@ -570,7 +570,7 @@ void shortcut_init(bool unjustify) ...@@ -570,7 +570,7 @@ void shortcut_init(bool unjustify)
sc_init_one(&main_list, NANO_NO_KEY, N_("Prev Word"), sc_init_one(&main_list, NANO_NO_KEY, N_("Prev Word"),
IFHELP(nano_prevword_msg, NANO_PREVWORD_KEY), NANO_NO_KEY, IFHELP(nano_prevword_msg, NANO_PREVWORD_KEY), NANO_NO_KEY,
NANO_NO_KEY, VIEW, do_prev_word); NANO_NO_KEY, VIEW, do_prev_word_void);
sc_init_one(&main_list, NANO_NO_KEY, N_("Word Count"), sc_init_one(&main_list, NANO_NO_KEY, N_("Word Count"),
IFHELP(nano_wordcount_msg, NANO_WORDCOUNT_KEY), NANO_NO_KEY, IFHELP(nano_wordcount_msg, NANO_WORDCOUNT_KEY), NANO_NO_KEY,
......
...@@ -1468,10 +1468,11 @@ void do_enter(void) ...@@ -1468,10 +1468,11 @@ void do_enter(void)
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* Move to the next word in the current filestruct. If allow_update is /* Move to the next word in the current filestruct. If allow_punct is
* FALSE, don't update the screen afterward. Return TRUE if we started * TRUE, treat punctuation as part of a word. If allow_update is TRUE,
* on a word, and FALSE otherwise. */ * update the screen afterward. Return TRUE if we started on a word,
bool do_next_word(bool allow_update) * and FALSE otherwise. */
bool do_next_word(bool allow_punct, bool allow_update)
{ {
size_t pww_save = placewewant; size_t pww_save = placewewant;
const filestruct *current_save = current; const filestruct *current_save = current;
...@@ -1491,7 +1492,7 @@ bool do_next_word(bool allow_update) ...@@ -1491,7 +1492,7 @@ bool do_next_word(bool allow_update)
/* If we've found it, stop moving forward through the current /* If we've found it, stop moving forward through the current
* line. */ * line. */
if (!is_word_mbchar(char_mb, TRUE)) if (!is_word_mbchar(char_mb, allow_punct))
break; break;
/* If we haven't found it, then we've started on a word, so set /* If we haven't found it, then we've started on a word, so set
...@@ -1512,7 +1513,7 @@ bool do_next_word(bool allow_update) ...@@ -1512,7 +1513,7 @@ bool do_next_word(bool allow_update)
/* If we've found it, stop moving forward through the /* If we've found it, stop moving forward through the
* current line. */ * current line. */
if (is_word_mbchar(char_mb, TRUE)) if (is_word_mbchar(char_mb, allow_punct))
break; break;
current_x += char_mb_len; current_x += char_mb_len;
...@@ -1543,19 +1544,24 @@ bool do_next_word(bool allow_update) ...@@ -1543,19 +1544,24 @@ bool do_next_word(bool allow_update)
return started_on_word; return started_on_word;
} }
/* Move to the next word in the current filestruct, not counting
* punctuation as part of a word, and updating the screen afterward. */
void do_next_word_void(void) void do_next_word_void(void)
{ {
do_next_word(TRUE); do_next_word(FALSE, TRUE);
} }
/* Move to the previous word in the current filestruct. */ /* Move to the previous word in the current filestruct. If allow_punct
void do_prev_word(void) * is TRUE, treat punctuation as part of a word. If allow_update is
* TRUE, update the screen afterward. Return TRUE if we started on a
* word, and FALSE otherwise. */
bool do_prev_word(bool allow_punct, bool allow_update)
{ {
size_t pww_save = placewewant; size_t pww_save = placewewant;
const filestruct *current_save = current; const filestruct *current_save = current;
char *char_mb; char *char_mb;
int char_mb_len; int char_mb_len;
bool begin_line = FALSE; bool begin_line = FALSE, started_on_word = FALSE;
assert(current != NULL && current->data != NULL); assert(current != NULL && current->data != NULL);
...@@ -1569,9 +1575,13 @@ void do_prev_word(void) ...@@ -1569,9 +1575,13 @@ void do_prev_word(void)
/* If we've found it, stop moving backward through the current /* If we've found it, stop moving backward through the current
* line. */ * line. */
if (!is_word_mbchar(char_mb, TRUE)) if (!is_word_mbchar(char_mb, allow_punct))
break; break;
/* If we haven't found it, then we've started on a word, so set
* started_on_word to TRUE. */
started_on_word = TRUE;
if (current_x == 0) if (current_x == 0)
begin_line = TRUE; begin_line = TRUE;
else else
...@@ -1592,7 +1602,7 @@ void do_prev_word(void) ...@@ -1592,7 +1602,7 @@ void do_prev_word(void)
/* If we've found it, stop moving backward through the /* If we've found it, stop moving backward through the
* current line. */ * current line. */
if (is_word_mbchar(char_mb, TRUE)) if (is_word_mbchar(char_mb, allow_punct))
break; break;
if (current_x == 0) if (current_x == 0)
...@@ -1631,7 +1641,7 @@ void do_prev_word(void) ...@@ -1631,7 +1641,7 @@ void do_prev_word(void)
/* If we've found it, stop moving backward through the /* If we've found it, stop moving backward through the
* current line. */ * current line. */
if (!is_word_mbchar(char_mb, TRUE)) if (!is_word_mbchar(char_mb, allow_punct))
break; break;
if (current_x == 0) if (current_x == 0)
...@@ -1650,8 +1660,19 @@ void do_prev_word(void) ...@@ -1650,8 +1660,19 @@ void do_prev_word(void)
placewewant = xplustabs(); placewewant = xplustabs();
/* Update the screen. */ /* If allow_update is TRUE, update the screen. */
edit_redraw(current_save, pww_save); if (allow_update)
edit_redraw(current_save, pww_save);
/* Return whether we started on a word. */
return started_on_word;
}
/* Move to the previous word in the current filestruct, not counting
* punctuation as part of a word, and updating the screen afterward. */
void do_prev_word_void(void)
{
do_prev_word(FALSE, TRUE);
} }
void do_word_count(void) void do_word_count(void)
...@@ -1683,11 +1704,13 @@ void do_word_count(void) ...@@ -1683,11 +1704,13 @@ void do_word_count(void)
current_x = 0; current_x = 0;
placewewant = 0; placewewant = 0;
/* Keep moving to the next word, without updating the screen, until /* Keep moving to the next word (counting punctuation characters as
* we reach the end of the file, incrementing the total word count * part of a word so that we match the output of "wc -w"), without
* whenever we're on a word just before moving. */ * updating the screen, until we reach the end of the file,
* incrementing the total word count whenever we're on a word just
* before moving. */
while (current != filebot || current_x != 0) { while (current != filebot || current_x != 0) {
if (do_next_word(FALSE)) if (do_next_word(TRUE, FALSE))
words++; words++;
} }
......
...@@ -412,9 +412,10 @@ void do_delete(void); ...@@ -412,9 +412,10 @@ void do_delete(void);
void do_tab(void); void do_tab(void);
void do_enter(void); void do_enter(void);
#ifndef NANO_SMALL #ifndef NANO_SMALL
bool do_next_word(bool allow_update); bool do_next_word(bool allow_punct, bool allow_update);
void do_next_word_void(void); void do_next_word_void(void);
void do_prev_word(void); bool do_prev_word(bool allow_punct, bool allow_update);
void do_prev_word_void(void);
void do_word_count(void); void do_word_count(void);
void do_mark(void); void do_mark(void);
#endif #endif
...@@ -642,8 +643,8 @@ void do_statusbar_backspace(void); ...@@ -642,8 +643,8 @@ void do_statusbar_backspace(void);
void do_statusbar_delete(void); void do_statusbar_delete(void);
void do_statusbar_cut_text(void); void do_statusbar_cut_text(void);
#ifndef NANO_SMALL #ifndef NANO_SMALL
void do_statusbar_next_word(void); bool do_statusbar_next_word(bool allow_punct);
void do_statusbar_prev_word(void); bool do_statusbar_prev_word(bool allow_punct);
#endif #endif
void do_statusbar_verbatim_input(bool *got_enter); void do_statusbar_verbatim_input(bool *got_enter);
void do_statusbar_output(char *output, size_t output_len, bool void do_statusbar_output(char *output, size_t output_len, bool
......
...@@ -1770,11 +1770,11 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t, ...@@ -1770,11 +1770,11 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t,
break; break;
#ifndef NANO_SMALL #ifndef NANO_SMALL
case NANO_NEXTWORD_KEY: case NANO_NEXTWORD_KEY:
do_statusbar_next_word(); do_statusbar_next_word(FALSE);
break; break;
case NANO_PREVWORD_KEY: case NANO_PREVWORD_KEY:
if (*meta_key == TRUE) if (*meta_key == TRUE)
do_statusbar_prev_word(); do_statusbar_prev_word(FALSE);
break; break;
#endif #endif
case NANO_VERBATIM_KEY: case NANO_VERBATIM_KEY:
...@@ -1905,11 +1905,14 @@ void do_statusbar_cut_text(void) ...@@ -1905,11 +1905,14 @@ void do_statusbar_cut_text(void)
} }
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* Move to the next word at the statusbar prompt. */ /* Move to the next word at the statusbar prompt. If allow_punct is
void do_statusbar_next_word(void) * TRUE, treat punctuation as part of a word. Return TRUE if we started
* on a word, and FALSE otherwise. */
bool do_statusbar_next_word(bool allow_punct)
{ {
char *char_mb; char *char_mb;
int char_mb_len; int char_mb_len;
bool started_on_word = FALSE;
assert(answer != NULL); assert(answer != NULL);
...@@ -1923,9 +1926,13 @@ void do_statusbar_next_word(void) ...@@ -1923,9 +1926,13 @@ void do_statusbar_next_word(void)
/* If we've found it, stop moving forward through the current /* If we've found it, stop moving forward through the current
* line. */ * line. */
if (!is_word_mbchar(char_mb, TRUE)) if (!is_word_mbchar(char_mb, allow_punct))
break; break;
/* If we haven't found it, then we've started on a word, so set
* started_on_word to TRUE. */
started_on_word = TRUE;
statusbar_x += char_mb_len; statusbar_x += char_mb_len;
} }
...@@ -1939,21 +1946,26 @@ void do_statusbar_next_word(void) ...@@ -1939,21 +1946,26 @@ void do_statusbar_next_word(void)
/* If we've found it, stop moving forward through the current /* If we've found it, stop moving forward through the current
* line. */ * line. */
if (is_word_mbchar(char_mb, TRUE)) if (is_word_mbchar(char_mb, allow_punct))
break; break;
statusbar_x += char_mb_len; statusbar_x += char_mb_len;
} }
free(char_mb); free(char_mb);
/* Return whether we started on a word. */
return started_on_word;
} }
/* Move to the previous word at the statusbar prompt. */ /* Move to the previous word at the statusbar prompt. If allow_punct is
void do_statusbar_prev_word(void) * TRUE, treat punctuation as part of a word. Return TRUE if we started
* on a word, and FALSE otherwise. */
bool do_statusbar_prev_word(bool allow_punct)
{ {
char *char_mb; char *char_mb;
int char_mb_len; int char_mb_len;
bool begin_line = FALSE; bool begin_line = FALSE, started_on_word = FALSE;
assert(answer != NULL); assert(answer != NULL);
...@@ -1967,9 +1979,13 @@ void do_statusbar_prev_word(void) ...@@ -1967,9 +1979,13 @@ void do_statusbar_prev_word(void)
/* If we've found it, stop moving backward through the current /* If we've found it, stop moving backward through the current
* line. */ * line. */
if (!is_word_mbchar(char_mb, TRUE)) if (!is_word_mbchar(char_mb, allow_punct))
break; break;
/* If we haven't found it, then we've started on a word, so set
* started_on_word to TRUE. */
started_on_word = TRUE;
if (statusbar_x == 0) if (statusbar_x == 0)
begin_line = TRUE; begin_line = TRUE;
else else
...@@ -1989,7 +2005,7 @@ void do_statusbar_prev_word(void) ...@@ -1989,7 +2005,7 @@ void do_statusbar_prev_word(void)
/* If we've found it, stop moving backward through the current /* If we've found it, stop moving backward through the current
* line. */ * line. */
if (is_word_mbchar(char_mb, TRUE)) if (is_word_mbchar(char_mb, allow_punct))
break; break;
if (statusbar_x == 0) if (statusbar_x == 0)
...@@ -2012,7 +2028,7 @@ void do_statusbar_prev_word(void) ...@@ -2012,7 +2028,7 @@ void do_statusbar_prev_word(void)
/* If we've found it, stop moving backward through the /* If we've found it, stop moving backward through the
* current line. */ * current line. */
if (!is_word_mbchar(char_mb, TRUE)) if (!is_word_mbchar(char_mb, allow_punct))
break; break;
if (statusbar_x == 0) if (statusbar_x == 0)
...@@ -2028,8 +2044,11 @@ void do_statusbar_prev_word(void) ...@@ -2028,8 +2044,11 @@ void do_statusbar_prev_word(void)
} }
free(char_mb); free(char_mb);
/* Return whether we started on a word. */
return started_on_word;
} }
#endif #endif /* !NANO_SMALL */
void do_statusbar_verbatim_input(bool *got_enter) void do_statusbar_verbatim_input(bool *got_enter)
{ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment