Elffuss BraidHub

kikocis/company-english-helper public

Add option `company-english-helper-fuzz-search-p' and turn off it default.
Changesetb9b9ce6a297512117b78bedbeb3b5129ca5abf9197f05634b0f2743cd427a0c2
AuthorAndy Stewart <lazycat.manatee@gmail.com> · 2018-08-30 13:26 +08:00
CommitterAndy Stewart <lazycat.manatee@gmail.com> · 2018-08-30 13:26 +08:00
Parentsaa289f8aed7a

Browse the files at this changeset

1 file changed

modified company-english-helper.el +32 −15
@@ -6,8 +6,8 @@
66 ;; Maintainer: Andy Stewart <lazycat.manatee@gmail.com>
77 ;; Copyright (C) 2018, Andy Stewart, all rights reserved.
88 ;; Created: 2018-07-06 23:22:22
9-;; Version: 1.0
10-;; Last-Updated: 2018-08-28 22:17:36
9+;; Version: 1.1
10+;; Last-Updated: 2018-08-30 13:26:02
1111 ;; By: Andy Stewart
1212 ;; URL: http://www.emacswiki.org/emacs/download/company-english-helper.el
1313 ;; Keywords:
@@ -55,6 +55,10 @@
5555 ;;
5656 ;; And bind your key with function `toggle-company-english-helper'.
5757 ;;
58+;; If your computer's performance is good enough, you can enable fuzz search by:
59+;;
60+;; (setq company-english-helper-fuzz-search-p t)
61+;;
5862
5963 ;;; Customize:
6064 ;;
@@ -66,6 +70,9 @@
6670
6771 ;;; Change log:
6872 ;;
73+;; 2018/08/29
74+;; * Add option `company-english-helper-fuzz-search-p' and turn off it default.
75+;;
6976 ;; 2018/08/27
7077 ;; * Add fuzz search algorithm.
7178 ;; * Make prefix-match-candidates as first candidates, then suffix-match-candidates and fuzz-match-candidates.
@@ -115,6 +122,12 @@
115122 (defvar company-english-helper-match-group-size 10
116123 "The max size of match group.")
117124
125+(defvar company-english-helper-fuzz-search-p nil
126+ "Turn on this option to enable fuzz search.
127+Default is disable because fuzz search performance.
128+
129+If your computer's performance is good enough, you can enable this option.")
130+
118131 (defun english-helper-annotation (s)
119132 (let* ((translation (get-text-property 0 :initials s))
120133 (translation-format-string (replace-regexp-in-string "\\cc" "" translation))
@@ -141,21 +154,25 @@
141154 english-helper-completions))
142155
143156 (setq suffix-match-candidates
144- (remove-if-not
145- (lambda (c) (string-suffix-p (downcase arg) c))
146- english-helper-completions))
157+ (if company-english-helper-fuzz-search-p
158+ (remove-if-not
159+ (lambda (c) (string-suffix-p (downcase arg) c))
160+ english-helper-completions)
161+ nil))
147162
148163 (setq fuzz-match-candidates
149- (remove-if-not
150- (lambda (c)
151- (and (string-match-p "-" (downcase arg))
152- (let* ((split-list (split-string (downcase arg) "-"))
153- (left-string (car split-list))
154- (right-string (cadr split-list)))
155- (and (string-prefix-p left-string c)
156- (string-match-p right-string (string-remove-prefix left-string c))
157- ))))
158- english-helper-completions))
164+ (if company-english-helper-fuzz-search-p
165+ (remove-if-not
166+ (lambda (c)
167+ (and (string-match-p "-" (downcase arg))
168+ (let* ((split-list (split-string (downcase arg) "-"))
169+ (left-string (car split-list))
170+ (right-string (cadr split-list)))
171+ (and (string-prefix-p left-string c)
172+ (string-match-p right-string (string-remove-prefix left-string c))
173+ ))))
174+ english-helper-completions)
175+ nil))
159176
160177 ;; Make prefix-match-candidates as first candidates, then suffix-match-candidates and fuzz-match-candidates.
161178 (delete-dups (append