[geany/geany-plugins] 02494d: SpellCheck: Treat underscore as word seperator

Enrico Tröger git-noreply at xxxxx
Wed Dec 28 21:34:00 UTC 2016


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Wed, 28 Dec 2016 21:34:00 UTC
Commit:      02494df3a85f9ef8d03d8bd19b6bc3a280176955
             https://github.com/geany/geany-plugins/commit/02494df3a85f9ef8d03d8bd19b6bc3a280176955

Log Message:
-----------
SpellCheck: Treat underscore as word seperator

We remove the underscore character temporarily from the wordchars
to make Scintilla split words on underscore.
After splitting the current line into words, we add the underscore again
to the document's wordchars setting if it was in before.

Fixes #496.


Modified Paths:
--------------
    spellcheck/src/speller.c

Modified: spellcheck/src/speller.c
21 lines changed, 20 insertions(+), 1 deletions(-)
===================================================================
@@ -205,6 +205,8 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
 	gint suggestions_found = 0;
 	gint wordchars_len;
 	gchar *wordchars;
+	gchar *underscore_in_wordchars = NULL;
+	gboolean wordchars_modified = FALSE;
 
 	g_return_val_if_fail(sc_speller_dict != NULL, 0);
 	g_return_val_if_fail(doc != NULL, 0);
@@ -218,9 +220,21 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
 	{
 		/* temporarily add "'" to the wordchars */
 		wordchars[wordchars_len] = '\'';
+		wordchars_modified = TRUE;
+	}
+	underscore_in_wordchars = strchr(wordchars, '_');
+	if (underscore_in_wordchars != NULL)
+	{
+		/* Temporarily remove underscore from the wordchars to treat
+		 * it as a word seperator. Replace it by a "'" which we added already above. */
+		*underscore_in_wordchars = '\'';
+		wordchars_modified = TRUE;
+	}
+	if (wordchars_modified)
+	{
+		/* apply previously changed WORDCHARS setting */
 		scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);
 	}
-
 	pos_start = sci_get_position_from_line(doc->editor->sci, line_number);
 	pos_end = sci_get_position_from_line(doc->editor->sci, line_number + 1);
 
@@ -242,6 +256,11 @@ gint sc_speller_process_line(GeanyDocument *doc, gint line_number)
 		g_free(word);
 	}
 
+	if (underscore_in_wordchars != NULL)
+	{
+		/* re-add underscore if we removed it above */
+		*underscore_in_wordchars = '_';
+	}
 	/* reset wordchars for the current document */
 	wordchars[wordchars_len] = '\0';
 	scintilla_send_message(doc->editor->sci, SCI_SETWORDCHARS, 0, (sptr_t)wordchars);



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Plugins-Commits mailing list