Elffuss BraidHub

kikocis/company-english-helper public

Adjust the case of the completion word according to the string entered by the user.
Changeset30a5ce78ec64c03aa87e8f5b3dfe7fb73fc5307b743576474d6709f5fafe2a11
AuthorAndy Stewart <lazycat.manatee@gmail.com> · 2018-12-01 23:36 +08:00
CommitterAndy Stewart <lazycat.manatee@gmail.com> · 2018-12-01 23:36 +08:00
Parents0c0cc64b5ec1

Browse the files at this changeset

1 file changed

modified company-english-helper.el +39 −23
@@ -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.1
10-;; Last-Updated: 2018-08-30 13:26:02
9+;; Version: 1.2
10+;; Last-Updated: 2018-12-01 23:35:13
1111 ;; By: Andy Stewart
1212 ;; URL: http://www.emacswiki.org/emacs/download/company-english-helper.el
1313 ;; Keywords:
@@ -70,6 +70,9 @@
7070
7171 ;;; Change log:
7272 ;;
73+;; 2018/12/01
74+;; * Adjust the case of the completion word according to the string entered by the user.
75+;;
7376 ;; 2018/08/29
7477 ;; * Add option `company-english-helper-fuzz-search-p' and turn off it default.
7578 ;;
@@ -147,20 +150,17 @@
147150 (interactive (company-begin-backend 'company-english-helper-search))
148151 (prefix (company-grab-symbol))
149152 (candidates
150- (progn
151- (setq prefix-match-candidates
153+ (let* ((prefix-match-candidates
152154 (remove-if-not
153155 (lambda (c) (string-prefix-p (downcase arg) c))
154156 english-helper-completions))
155-
156- (setq suffix-match-candidates
157+ (suffix-match-candidates
157158 (if company-english-helper-fuzz-search-p
158159 (remove-if-not
159160 (lambda (c) (string-suffix-p (downcase arg) c))
160161 english-helper-completions)
161162 nil))
162-
163- (setq fuzz-match-candidates
163+ (fuzz-match-candidates
164164 (if company-english-helper-fuzz-search-p
165165 (remove-if-not
166166 (lambda (c)
@@ -173,23 +173,39 @@
173173 ))))
174174 english-helper-completions)
175175 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)
189190 ))
190191 (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)))
193209
194210 (defun toggle-company-english-helper ()
195211 "Toggle company english helper."