kikocis/company-english-helper public
Changesets · Branches · Tags · Compare
| Changeset | b9b9ce6a297512117b78bedbeb3b5129ca5abf9197f05634b0f2743cd427a0c2 |
|---|---|
| Author | Andy Stewart <lazycat.manatee@gmail.com> · 2018-08-30 13:26 +08:00 |
| Committer | Andy Stewart <lazycat.manatee@gmail.com> · 2018-08-30 13:26 +08:00 |
| Parents | aa289f8aed7a |
1 file changed
modified company-english-helper.el +32 −15
| @@ -6,8 +6,8 @@ | ||
| 6 | 6 | ;; Maintainer: Andy Stewart <lazycat.manatee@gmail.com> |
| 7 | 7 | ;; Copyright (C) 2018, Andy Stewart, all rights reserved. |
| 8 | 8 | ;; 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 | |
| 11 | 11 | ;; By: Andy Stewart |
| 12 | 12 | ;; URL: http://www.emacswiki.org/emacs/download/company-english-helper.el |
| 13 | 13 | ;; Keywords: |
| @@ -55,6 +55,10 @@ | ||
| 55 | 55 | ;; |
| 56 | 56 | ;; And bind your key with function `toggle-company-english-helper'. |
| 57 | 57 | ;; |
| 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 | +;; | |
| 58 | 62 | |
| 59 | 63 | ;;; Customize: |
| 60 | 64 | ;; |
| @@ -66,6 +70,9 @@ | ||
| 66 | 70 | |
| 67 | 71 | ;;; Change log: |
| 68 | 72 | ;; |
| 73 | +;; 2018/08/29 | |
| 74 | +;; * Add option `company-english-helper-fuzz-search-p' and turn off it default. | |
| 75 | +;; | |
| 69 | 76 | ;; 2018/08/27 |
| 70 | 77 | ;; * Add fuzz search algorithm. |
| 71 | 78 | ;; * Make prefix-match-candidates as first candidates, then suffix-match-candidates and fuzz-match-candidates. |
| @@ -115,6 +122,12 @@ | ||
| 115 | 122 | (defvar company-english-helper-match-group-size 10 |
| 116 | 123 | "The max size of match group.") |
| 117 | 124 | |
| 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 | + | |
| 118 | 131 | (defun english-helper-annotation (s) |
| 119 | 132 | (let* ((translation (get-text-property 0 :initials s)) |
| 120 | 133 | (translation-format-string (replace-regexp-in-string "\\cc" "" translation)) |
| @@ -141,21 +154,25 @@ | ||
| 141 | 154 | english-helper-completions)) |
| 142 | 155 | |
| 143 | 156 | (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)) | |
| 147 | 162 | |
| 148 | 163 | (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)) | |
| 159 | 176 | |
| 160 | 177 | ;; Make prefix-match-candidates as first candidates, then suffix-match-candidates and fuzz-match-candidates. |
| 161 | 178 | (delete-dups (append |