mirror of
				https://github.com/wting/autojump
				synced 2025-06-13 12:54:07 +00:00 
			
		
		
		
	implement smartcase detection
This commit is contained in:
		
							parent
							
								
									bb04405cd6
								
							
						
					
					
						commit
						d9b205c935
					
				| @ -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 | ||||
|  | ||||
| @ -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 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user