allow swapping dict at runtime

This commit is contained in:
Felix Van der Jeugt 2016-04-25 10:48:47 +02:00
parent fdb630555d
commit 2d71c541c6
2 changed files with 14 additions and 10 deletions

View File

@ -1004,11 +1004,14 @@ class WordHinter:
def __init__(self):
# will be initialized on first use.
self.words = set()
self.dictionary = None
def ensure_initialized(self):
"""Generate the used words if yet uninialized."""
if not self.words:
dictionary = config.get("hints", "dictionary")
dictionary = config.get("hints", "dictionary")
if not self.words or self.dictionary != dictionary:
self.words.clear()
self.dictionary = dictionary
try:
with open(dictionary, encoding="UTF-8") as wordfile:
alphabet = set(string.ascii_lowercase)
@ -1104,3 +1107,4 @@ class WordHinter:
used_hints.add(hint)
hints.append(hint)
return hints

View File

@ -62,21 +62,21 @@ def test_hints(test_name, quteproc):
def test_word_hints_issue1393(quteproc, tmpdir):
dict_file = tmpdir / 'dict'
dict_file.write(textwrap.dedent("""
alpha
alph
beta
gamma
delta
epsilon
gamm
delt
epsi
"""))
targets = [
('words', 'words.txt'),
('smart', 'smart.txt'),
('hinting', 'hinting.txt'),
('alpha', 'l33t.txt'),
('alph', 'l33t.txt'),
('beta', 'l33t.txt'),
('gamma', 'l33t.txt'),
('delta', 'l33t.txt'),
('epsilon', 'l33t.txt'),
('gamm', 'l33t.txt'),
('delt', 'l33t.txt'),
('epsi', 'l33t.txt'),
]
quteproc.set_setting('hints', 'mode', 'word')