Last active
August 29, 2015 14:04
-
-
Save hcs64/993e77d4539f84ca33ca to your computer and use it in GitHub Desktop.
Spell checking fix for pygtkspellcheck as embedded in CherryTree 0.33.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# $Id$ | |
# Maintainer: Balló György <ballogyor+arch at gmail dot com> | |
# Contributor: Bartłomiej Piotrowski | |
# Contributor: Brad Fanella <[email protected]> | |
# Contributor: Allan McRae <[email protected]> | |
# Contributor: Tomas A. Schertel <[email protected]> | |
# Contributor: Adam Gashlin <[email protected]> | |
pkgname=cherrytree | |
pkgver=0.33.4 | |
pkgrel=2 | |
pkgdesc='Hierarchical note taking application featuring rich text and syntax highlighting' | |
arch=('any') | |
groups=('modified') | |
url='http://www.giuspen.com/cherrytree/' | |
license=('GPL3') | |
depends=('pygtksourceview2' 'python2-dbus' 'desktop-file-utils') | |
optdepends=('python2-pyenchant: for spell checking support' | |
'p7zip: for password protection support') | |
install=cherrytree.install | |
source=( | |
http://www.giuspen.com/software/$pkgname-$pkgver.tar.xz | |
spellcheck_apostrophe.patch | |
) | |
sha256sums=( | |
'b116657ba7c4252f671a83f9cc2e8bbf69b6345741fd1c569299a8aa293eb177' | |
'3f36d3335911823f2e601c69ef591442a2ae5cbc52ad111c87741ddd41f1c227' | |
) | |
prepare() { | |
cd $pkgname-$pkgver | |
patch -p1 < ../spellcheck_apostrophe.patch | |
} | |
build() { | |
cd $pkgname-$pkgver | |
python2 setup.py build | |
} | |
package() { | |
cd $pkgname-$pkgver | |
python2 setup.py install --root="$pkgdir/" --optimize=1 | |
# Fix file permissions | |
find "$pkgdir/usr/share" -type f | xargs chmod 644 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 7c0c3c912f80 modules/pgsc_spellcheck.py | |
--- a/modules/pgsc_spellcheck.py Mon May 26 23:18:46 2014 +0200 | |
+++ b/modules/pgsc_spellcheck.py Tue May 27 12:03:10 2014 -0400 | |
@@ -42,6 +42,40 @@ | |
# public objects | |
__all__ = ['SpellChecker', 'NoDictionariesFound', 'NoGtkBindingFound'] | |
+# apostrophe workaround from gtkspell3 | |
+def gtk_spell_forward_word_end(i): | |
+ | |
+ # heuristic: | |
+ # if we're on an singlequote/apostrophe and | |
+ # if the next letter is alphanumeric, | |
+ # this is an apostrophe (either single quote, or U+2019 = 8217. | |
+ | |
+ if not i.forward_word_end(): | |
+ return False | |
+ | |
+ if i.get_char() != '\'' and \ | |
+ i.get_char() != 8217: | |
+ return True | |
+ | |
+ it = i.copy() | |
+ if it.forward_char() and \ | |
+ it.get_char().isalpha(): | |
+ return i.forward_word_end() | |
+ | |
+ return True | |
+ | |
+def gtk_spell_backward_word_start(i): | |
+ if not i.backward_word_start(): | |
+ return False | |
+ | |
+ it = i.copy() | |
+ if it.get_char().isalpha() and \ | |
+ it.backward_char() and \ | |
+ (it.get_char() == '\'' or \ | |
+ it.get_char() == 8217): | |
+ return i.backward_word_start() | |
+ | |
+ return True | |
class NoDictionariesFound(Exception): | |
""" | |
@@ -132,10 +166,10 @@ | |
def word(self): | |
start = self.iter | |
if not start.starts_word(): | |
- start.backward_word_start() | |
+ gtk_spell_backward_word_start(start) | |
end = self.iter | |
if end.inside_word(): | |
- end.forward_word_end() | |
+ gtk_spell_forward_word_end(end) | |
return start, end | |
def move(self, location): | |
@@ -361,21 +395,21 @@ | |
return | |
if start.equal(end): | |
return | |
- if end.inside_word(): end.forward_word_end() | |
+ if end.inside_word(): gtk_spell_forward_word_end(end) | |
if not start.starts_word() and (start.inside_word() or start.ends_word()): | |
- start.backward_word_start() | |
+ gtk_spell_backward_word_start(start) | |
self._buffer.remove_tag(self._misspelled, start, end) | |
cursor = self._buffer.get_iter_at_mark(self._buffer.get_insert()) | |
precursor = cursor.copy() | |
precursor.backward_char() | |
highlight = (cursor.has_tag(self._misspelled) or precursor.has_tag(self._misspelled)) | |
if not start.get_offset(): | |
- start.forward_word_end() | |
- start.backward_word_start() | |
+ gtk_spell_forward_word_end(start) | |
+ gtk_spell_backward_word_start(start) | |
word_start = start.copy() | |
while word_start.compare(end) < 0: | |
word_end = word_start.copy() | |
- word_end.forward_word_end() | |
+ gtk_spell_forward_word_end(word_end) | |
in_word = ((word_start.compare(cursor) < 0) and | |
(cursor.compare(word_end) <= 0)) | |
if in_word and not force_all: | |
@@ -386,8 +420,8 @@ | |
else: | |
self._check_word(word_start, word_end) | |
self._deferred_check = False | |
- word_end.forward_word_end() | |
- word_end.backward_word_start() | |
+ gtk_spell_forward_word_end(word_end) | |
+ gtk_spell_backward_word_start(word_end) | |
if word_start.equal(word_end): | |
break | |
word_start = word_end.copy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment