kikocis/company-english-helper public
Changesets · Branches · Tags · Compare
| Changeset | 30a5ce78ec64c03aa87e8f5b3dfe7fb73fc5307b743576474d6709f5fafe2a11 |
|---|---|
| Author | Andy Stewart <lazycat.manatee@gmail.com> · 2018-12-01 23:36 +08:00 |
| Committer | Andy Stewart <lazycat.manatee@gmail.com> · 2018-12-01 23:36 +08:00 |
| Parents | 0c0cc64b5ec1 |
1 file changed
modified company-english-helper.el +39 −23
| @@ -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.1 | |
| 10 | -;; Last-Updated: 2018-08-30 13:26:02 | |
| 9 | +;; Version: 1.2 | |
| 10 | +;; Last-Updated: 2018-12-01 23:35:13 | |
| 11 | 11 | ;; By: Andy Stewart |
| 12 | 12 | ;; URL: http://www.emacswiki.org/emacs/download/company-english-helper.el |
| 13 | 13 | ;; Keywords: |
| @@ -70,6 +70,9 @@ | ||
| 70 | 70 | |
| 71 | 71 | ;;; Change log: |
| 72 | 72 | ;; |
| 73 | +;; 2018/12/01 | |
| 74 | +;; * Adjust the case of the completion word according to the string entered by the user. | |
| 75 | +;; | |
| 73 | 76 | ;; 2018/08/29 |
| 74 | 77 | ;; * Add option `company-english-helper-fuzz-search-p' and turn off it default. |
| 75 | 78 | ;; |
| @@ -147,20 +150,17 @@ | ||
| 147 | 150 | (interactive (company-begin-backend 'company-english-helper-search)) |
| 148 | 151 | (prefix (company-grab-symbol)) |
| 149 | 152 | (candidates |
| 150 | - (progn | |
| 151 | - (setq prefix-match-candidates | |
| 153 | + (let* ((prefix-match-candidates | |
| 152 | 154 | (remove-if-not |
| 153 | 155 | (lambda (c) (string-prefix-p (downcase arg) c)) |
| 154 | 156 | english-helper-completions)) |
| 155 | - | |
| 156 | - (setq suffix-match-candidates | |
| 157 | + (suffix-match-candidates | |
| 157 | 158 | (if company-english-helper-fuzz-search-p |
| 158 | 159 | (remove-if-not |
| 159 | 160 | (lambda (c) (string-suffix-p (downcase arg) c)) |
| 160 | 161 | english-helper-completions) |
| 161 | 162 | nil)) |
| 162 | - | |
| 163 | - (setq fuzz-match-candidates | |
| 163 | + (fuzz-match-candidates | |
| 164 | 164 | (if company-english-helper-fuzz-search-p |
| 165 | 165 | (remove-if-not |
| 166 | 166 | (lambda (c) |
| @@ -173,23 +173,39 @@ | ||
| 173 | 173 | )))) |
| 174 | 174 | english-helper-completions) |
| 175 | 175 | nil)) |
| 176 | - | |
| 177 | - ;; Make prefix-match-candidates as first candidates, then suffix-match-candidates and fuzz-match-candidates. | |
| 178 | - (delete-dups (if fuzz-match-candidates | |
| 179 | - (append | |
| 180 | - (subseq prefix-match-candidates 0 (min company-english-helper-match-group-size (length prefix-match-candidates))) | |
| 181 | - (subseq suffix-match-candidates 0 (min company-english-helper-match-group-size (length suffix-match-candidates))) | |
| 182 | - (subseq fuzz-match-candidates 0 (min company-english-helper-match-group-size (length fuzz-match-candidates))) | |
| 183 | - ) | |
| 184 | - (append | |
| 185 | - prefix-match-candidates | |
| 186 | - suffix-match-candidates | |
| 187 | - fuzz-match-candidates | |
| 188 | - ))) | |
| 176 | + (match-candidates | |
| 177 | + ;; Make prefix-match-candidates as first candidates, then suffix-match-candidates and fuzz-match-candidates. | |
| 178 | + (delete-dups (if fuzz-match-candidates | |
| 179 | + (append | |
| 180 | + (subseq prefix-match-candidates 0 (min company-english-helper-match-group-size (length prefix-match-candidates))) | |
| 181 | + (subseq suffix-match-candidates 0 (min company-english-helper-match-group-size (length suffix-match-candidates))) | |
| 182 | + (subseq fuzz-match-candidates 0 (min company-english-helper-match-group-size (length fuzz-match-candidates))) | |
| 183 | + ) | |
| 184 | + (append | |
| 185 | + prefix-match-candidates | |
| 186 | + suffix-match-candidates | |
| 187 | + fuzz-match-candidates | |
| 188 | + ))))) | |
| 189 | + (company-english-helper-convert-candidates arg match-candidates) | |
| 189 | 190 | )) |
| 190 | 191 | (annotation (english-helper-annotation arg)) |
| 191 | - (sorted t) | |
| 192 | - )) | |
| 192 | + (sorted t))) | |
| 193 | + | |
| 194 | +(defun company-english-helper-convert-candidates (input candidates) | |
| 195 | + (cond ((company-english-helper-upcase-string-p input) | |
| 196 | + (mapcar 'upcase candidates)) | |
| 197 | + ((company-english-helper-capitalize-string-p input) | |
| 198 | + (mapcar 'capitalize candidates)) | |
| 199 | + (t candidates))) | |
| 200 | + | |
| 201 | +(defun company-english-helper-upcase-string-p (str) | |
| 202 | + (let ((case-fold-search nil)) | |
| 203 | + (and (> (length str) 1) | |
| 204 | + (string-match-p "\\`[A-Z]*\\'" str)))) | |
| 205 | + | |
| 206 | +(defun company-english-helper-capitalize-string-p (str) | |
| 207 | + (let ((case-fold-search nil)) | |
| 208 | + (string-match-p "\\`[A-Z][a-z]*\\'" str))) | |
| 193 | 209 | |
| 194 | 210 | (defun toggle-company-english-helper () |
| 195 | 211 | "Toggle company english helper." |