[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/company 98d8894271 2/3: Reuse the 'match' code from com
From: |
ELPA Syncer |
Subject: |
[elpa] externals/company 98d8894271 2/3: Reuse the 'match' code from company-capf |
Date: |
Sun, 15 Oct 2023 21:57:39 -0400 (EDT) |
branch: externals/company
commit 98d8894271b6a7aed85d279f70098ba6cbae10c7
Author: Kien Nguyen <kien.n.quang@gmail.com>
Commit: Dmitry Gutov <dmitry@gutov.dev>
Reuse the 'match' code from company-capf
Resolves #1215
---
company-capf.el | 25 ++++---------------------
company-dabbrev-code.el | 2 ++
company.el | 20 ++++++++++++++++++++
3 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/company-capf.el b/company-capf.el
index 5a2f3db148..c6f578f98e 100644
--- a/company-capf.el
+++ b/company-capf.el
@@ -135,27 +135,10 @@ so we can't just use the preceding variable instead.")
(`match
;; Ask the for the `:company-match' function. If that doesn't help,
;; fallback to sniffing for face changes to get a suitable value.
- (let ((f (plist-get (nthcdr 4 company-capf--current-completion-data)
- :company-match)))
- (if f (funcall f arg)
- (let* ((match-start nil) (pos -1)
- (prop-value nil) (faces nil)
- (has-face-p nil) chunks
- (limit (length arg)))
- (while (< pos limit)
- (setq pos
- (if (< pos 0) 0 (next-property-change pos arg limit)))
- (setq prop-value (or
- (get-text-property pos 'face arg)
- (get-text-property pos 'font-lock-face arg))
- faces (if (listp prop-value) prop-value (list prop-value))
- has-face-p (memq 'completions-common-part faces))
- (cond ((and (not match-start) has-face-p)
- (setq match-start pos))
- ((and match-start (not has-face-p))
- (push (cons match-start pos) chunks)
- (setq match-start nil))))
- (nreverse chunks)))))
+ (let ((f (or (plist-get (nthcdr 4 company-capf--current-completion-data)
+ :company-match)
+ #'company--match-from-capf-face)))
+ (funcall f arg)))
(`duplicates t)
(`no-cache t) ;Not much can be done here, as long as we handle
;non-prefix matches.
diff --git a/company-dabbrev-code.el b/company-dabbrev-code.el
index fd8a1abbc1..a496c8ed37 100644
--- a/company-dabbrev-code.el
+++ b/company-dabbrev-code.el
@@ -127,6 +127,8 @@ comments or strings."
(kind 'text)
(no-cache t)
(ignore-case company-dabbrev-code-ignore-case)
+ (match (when company-dabbrev-code-completion-styles
+ (company--match-from-capf-face arg)))
(duplicates t)))
(defun company-dabbrev-code--filter (prefix table)
diff --git a/company.el b/company.el
index 4209051113..c62f9a4df0 100644
--- a/company.el
+++ b/company.el
@@ -1142,6 +1142,26 @@ matches IDLE-BEGIN-AFTER-RE, return it wrapped in a
cons."
(concat prefix (substring s len))))
strings)))
+(defun company--match-from-capf-face (str)
+ "Compute `match' result from a CAPF's completion fontification."
+ (let* ((match-start nil) (pos -1)
+ (prop-value nil) (faces nil)
+ (has-face-p nil) chunks
+ (limit (length str)))
+ (while (< pos limit)
+ (setq pos
+ (if (< pos 0) 0 (next-property-change pos str limit)))
+ (setq prop-value (or (get-text-property pos 'face str)
+ (get-text-property pos 'font-lock-face str))
+ faces (if (listp prop-value) prop-value (list prop-value))
+ has-face-p (memq 'completions-common-part faces))
+ (cond ((and (not match-start) has-face-p)
+ (setq match-start pos))
+ ((and match-start (not has-face-p))
+ (push (cons match-start pos) chunks)
+ (setq match-start nil))))
+ (nreverse chunks)))
+
(defvar company--cache (make-hash-table :test #'equal :size 10))
(cl-defun company-cache-fetch (key