From d9b205c935035b7d0116c677c76a40878900cd35 Mon Sep 17 00:00:00 2001 From: William Ting Date: Tue, 17 Dec 2013 10:35:43 -0600 Subject: [PATCH] implement smartcase detection --- bin/autojump | 9 ++++++++- bin/utils.py | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/autojump b/bin/autojump index 3e6929c..8daca9d 100755 --- a/bin/autojump +++ b/bin/autojump @@ -40,6 +40,7 @@ from data import save from utils import decode from utils import encode_local from utils import first +from utils import has_uppercase from utils import is_osx from utils import print_entry @@ -200,10 +201,11 @@ def find_matches(config, needles, count=1): if not needles: return first(data).path + ignore_case = detect_smartcase(needles) sanitize = lambda x: decode(x).rstrip(os.sep) needles = imap(sanitize, needles) - exact_matches = match_exact_regex(needles, data) + exact_matches = match_exact_regex(needles, data, ignore_case) return first(exact_matches).path @@ -255,6 +257,11 @@ def print_stats(config): print("\ndata:\t %s" % config['data_path']) +def detect_smartcase(strings): + """Detect if any uppercase letters are present in any of the strings.""" + return not any(imap(has_uppercase, strings)) + + def main(): parse_args(parse_env(set_defaults())) return 0 diff --git a/bin/utils.py b/bin/utils.py index 5ed3fe5..dc616a7 100644 --- a/bin/utils.py +++ b/bin/utils.py @@ -10,6 +10,7 @@ import os import platform import shutil import sys +import unicodedata def create_dir(path): @@ -50,6 +51,10 @@ def first(xs): return None +def has_uppercase(string): + return any(unicodedata.category(c) == 'Lu' for c in unicode(string)) + + def is_python2(): return sys.version_info[0] == 2