diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index e88ec6378..ba00cf75d 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -20,6 +20,7 @@ """A HintManager to draw hints over links.""" import os +import string import math import functools import collections @@ -154,8 +155,17 @@ class HintManager(QObject): def _get_word_hints(self, words=[]): if not words: - with open(os.path.join(standarddir.config(), "hints")) as hintfile: - words.extend(hint.rstrip() for hint in hintfile) + with open("/usr/share/dict/words") as wordfile: + alphabet = set(string.ascii_lowercase) + hints = set() + lines = (line.rstrip().lower() for line in wordfile) + for word in lines: + if not set(word) <= alphabet: continue + if not len(word) <= 4: continue + for i in range(len(word)): + hints.discard(word[:i+1]) + hints.add(word) + words.extend(hints) return words def _get_text(self): @@ -207,7 +217,12 @@ class HintManager(QObject): A list of hint strings, in the same order as the elements. """ if config.get('hints', 'mode') == 'words': - return self._get_word_hints()[:len(elems)] + try: + return self._get_word_hints()[:len(elems)] + except IOError: + message.error(self._win_id, "Word hints require a dictionary" + + " at /usr/share/dict/words.", immediately=True) + # falls back on letter hints if config.get('hints', 'mode') == 'number': chars = '0123456789' else: diff --git a/scripts/dictionary_to_word_hints.py b/scripts/dictionary_to_word_hints.py deleted file mode 100644 index 761baa4d5..000000000 --- a/scripts/dictionary_to_word_hints.py +++ /dev/null @@ -1,39 +0,0 @@ - -import sys -import string - -def filter_hints(words): - - alphabet = set("asdflkjqwerpoiu") - hints = set() - - for word in words: - - # hints should be lowercase - word = word.lower() - - # hints should be alphabetic - if not set(word) <= alphabet: - continue - - # hints shouldn't be longer than 5 characters - if len(word) > 5: - continue - - # hints should not be prefixes of other hints. we prefer the - # longer ones. - for i in range(len(word)): - hints.discard(word[:i+1]) - - hints.add(word) - - yield from hints - -def main(): - inlines = (line.rstrip() for line in sys.stdin) - outlines = ("{}\n".format(hint) for hint in filter_hints(inlines)) - sys.stdout.writelines(outlines) - -if __name__ == "__main__": - main() -