Re: [PATCH] git-gui: Automatically spell check commit messages as the user types

Previous thread: Re: [PATCH] Documentation/SubmittingPatches: Instruct how to use [PATCH] Subject header by Jari Aalto on Monday, February 4, 2008 - 1:12 am. (1 message)

Next thread: New to git: sorry for obvious question. by Paul Gardiner on Monday, February 4, 2008 - 2:56 am. (8 messages)
From: Shawn O. Pearce
Date: Monday, February 4, 2008 - 1:41 am

[This is also in my `pu` branch on repo.or.cz/git-gui.]

As you can see the commit message was rather long.  I used this
feature the entire time while writing it, and I have to say, it
saved me from my horrible spelling and typing skills.  It also
didn't feel like there was any significant lag, although every
once in a while it will mark a word that you are in the middle
of typing as misspelled, and catch up and correct that once you
finish the word.  I guess that's what you get for slowing down
and taking a few extra milliseconds to move the fingers.  :)

I need to test this on other platforms and with other languages,
but its working quite nicely on my Mac OS X system.  I did have to
install Aspell through DarwinPorts, sadly Mac OS 10.4 does not come
with it pre-installed.

Personally I prefer this style of spellchecking over the "lets show
a modal dialog and ask the user to check one word at a time through
the document".  Mainly because this style gives you full context,
while the modal dialog forms almost never do.

I'm not sure how to configure Aspell for other languages, it just
magically came up with English on my system.  Since git-gui has i18n
support almost everywhere else I want to get that settled before
this topic merges into my master branch.  I've CC'd Christian and
Johannes as they have been a big help in the past with the git-gui
i18n effort and I would value any input they might have.


--8>--
[PATCH] git-gui: Automatically spell check commit messages as the user types

Many user friendly tools like word processors, email editors and web
browsers allow users to spell check the message they are writing
as they type it, making it easy to identify a common misspelling
of a word and correct it on the fly.

We now open a bi-directional pipe to Aspell and feed the message
text the user is editing off to the program about once every 300
milliseconds.  This is frequent enough that the user sees the results
almost immediately, but is not so frequent as to cause ...
From: Wincent Colaiuta
Date: Monday, February 4, 2008 - 1:53 am

Rather than sending off the text to be spellchecked at intervals,  
couldn't you refrain from sending it when the cursor hasn't yet moved  
past a word boundary? This is what most "check spelling as you type  
implementations do".

eg. If you type "spellnig" and leave the cursor immediately after the  
"g", the word won't be highlighted until you hit space or otherwise  
cause the cursor to move beyond the word boundary.

Cheers,
Wincent



-

From: Shawn O. Pearce
Date: Monday, February 4, 2008 - 2:03 am

Indeed, that's brillant.  Something like this on top would work:

diff --git a/lib/spellcheck.tcl b/lib/spellcheck.tcl
index c032725..088812d 100644
--- a/lib/spellcheck.tcl
+++ b/lib/spellcheck.tcl
@@ -71,6 +71,14 @@ proc spellcheck_commit_buffer {} {
 		SPELL_i SPELL_sent SPELL_last \
 		SPELL_fd SPELL_line SPELL_suggest
 
+	if {![regexp {^\W$} [$ui_comm get {insert -1c} insert]]} {
+		$ui_comm tag remove misspelled \
+			{insert -1c wordstart} \
+			{insert -1c wordend}
+		set SPELL_i [after 300 spellcheck_commit_buffer]
+		return
+	}
+
 	set buf [$ui_comm get 1.0 end]
 	if {$buf ne $SPELL_sent && $buf eq $SPELL_last} {
 		foreach line [split $buf "\n"] {

-- 
Shawn.
-

From: Jakub Narebski
Date: Monday, February 4, 2008 - 3:14 am

IMHO both modes have their use. The "flyspell" mode can show you
errors as you type, so you wouldn't repeat mistakes (running spelling
only on finished words is a good idea), the "modal dialog" has its use
for final chackup, as it is much easier in this mode to use "ignore"
or "ignore all" for the word which is not in dictionary and you know
it is correct, select one of proposed corrections or write your and
use "replace" or "replace all", and add word to local dictionary, and
change language (if done right of course, i.e. with highlighting and
going to the word currently being corrected, and not hiding/covering
the text being corrected so you can see the context).

BTW. you can check how Emacs does that in its flyspell-mode, and how
it does checking lazily; I guess the code should be readable even

aspell {-d|--master}=<dictionary>

-- 
Jakub Narebski
Poland
ShadeHawk on #git
-

From: Adam Flott
Date: Monday, February 4, 2008 - 10:06 pm

Very impressive. I used it a bunch today and didn't find any problems.
Thanks again!


Adam
-

Previous thread: Re: [PATCH] Documentation/SubmittingPatches: Instruct how to use [PATCH] Subject header by Jari Aalto on Monday, February 4, 2008 - 1:12 am. (1 message)

Next thread: New to git: sorry for obvious question. by Paul Gardiner on Monday, February 4, 2008 - 2:56 am. (8 messages)