Skip to content

Commit

Permalink
spellcheck: update to the modern dict-common layout
Browse files Browse the repository at this point in the history
/usr/share/dict/words is a symlink these days.
Prefer cracklib-small, which fixes spellcheck on Arch.

Closes #663
Reported-by: @refaelsh
Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information
davvid committed Feb 19, 2017
1 parent 272875b commit a5670ca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cola/widgets/spellcheck.py
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, unicode_literals
import collections
import os
import re
import sys

Expand Down Expand Up @@ -65,6 +66,7 @@ def correct(word, words):


class NorvigSpellCheck(object):

def __init__(self):
self.words = collections.defaultdict(lambda: 1)
self.extra_words = set()
Expand All @@ -89,8 +91,22 @@ def check(self, word):
return word.replace('.', '') in self.words

def read(self):
for (path, title) in (('/usr/share/dict/words', True),
('/usr/share/dict/propernames', False)):
"""Read dictionary words"""
paths = []

words = '/usr/share/dict/words'
cracklib = '/usr/share/dict/cracklib-small'
propernames = '/usr/share/dict/propernames'

if os.path.exists(cracklib):
paths.append((cracklib, True))
else:
paths.append((words, True))

if os.path.exists(propernames):
paths.append((propernames, False))

for (path, title) in paths:
try:
with open(path, 'r') as f:
for word in f:
Expand All @@ -99,6 +115,7 @@ def read(self):
yield word.rstrip().title()
except IOError:
pass

raise StopIteration


Expand Down
8 changes: 8 additions & 0 deletions share/doc/git-cola/relnotes.rst
Expand Up @@ -82,6 +82,14 @@ Usability, bells and whistles

Fixes
=====
* `git cola`'s spellchecker now supports the new `dict-common` filesystem
layout, and prefers the `/usr/share/dict/cracklib-small` file over the
`/usr/share/dict/words` provided on older distributions.
This makes the spellchecker compatible with Arch, which does not provide
a `words` symlink like Debian.

https://github.com/git-cola/git-cola/issues/663

* Properly handle the case where an existing file is untracked using
the File Browser.

Expand Down

0 comments on commit a5670ca

Please sign in to comment.