emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master cf98238 04/29: Preview the common part of completion candi


From: Dmitry Gutov
Subject: [elpa] master cf98238 04/29: Preview the common part of completion candidates
Date: Tue, 28 Mar 2017 20:50:33 -0400 (EDT)

branch: master
commit cf982388e9d34655653f7bfbd2e1053e26b86ab2
Author: Kiso Katsuyuki <address@hidden>
Commit: Kiso Katsuyuki <address@hidden>

    Preview the common part of completion candidates
    
    The new frontends to preview the common part of candidates was added.
          company-preview-common-frontend
    
    I changed a little the function company-preview-show-at-point to
    be used in this frontend. The default frontend
    company-preview-if-just-one-frontend originally uses the function,
    so both frontends reference it.
    
    Configuration of customized variable company-frontends and
    the fuction company-frontends-set to set the frontends are also
    changed since the new frontend is added.
    
    In the default configuration the new frontend is not activated.
---
 company.el | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/company.el b/company.el
index 7fde671..ac96146 100644
--- a/company.el
+++ b/company.el
@@ -188,14 +188,19 @@ attention to case differences."
              (and (memq 
'company-pseudo-tooltip-unless-just-one-frontend-with-delay value)
                   (memq 'company-pseudo-tooltip-unless-just-one-frontend 
value)))
          (user-error "Pseudo tooltip frontend cannot be used more than once"))
-    (and (memq 'company-preview-if-just-one-frontend value)
-         (memq 'company-preview-frontend value)
+    (and (or (and (memq 'company-preview-if-just-one-frontend value)
+                  (memq 'company-preview-frontend value))
+             (and (memq 'company-preview-if-just-one-frontend value)
+                  (memq 'company-preview-common-frontend value))
+             (and (memq 'company-preview-frontend value)
+                  (memq 'company-preview-common-frontend value))
+             )
          (user-error "Preview frontend cannot be used twice"))
     (and (memq 'company-echo value)
          (memq 'company-echo-metadata-frontend value)
          (user-error "Echo area cannot be used twice"))
     ;; Preview must come last.
-    (dolist (f '(company-preview-if-just-one-frontend 
company-preview-frontend))
+    (dolist (f '(company-preview-if-just-one-frontend company-preview-frontend 
company-preview-common-frontend))
       (when (cdr (memq f value))
         (setq value (append (delq f value) (list f)))))
     (set variable value)))
@@ -237,6 +242,8 @@ The visualized data is stored in `company-prefix', 
`company-candidates',
                          (const :tag "preview" company-preview-frontend)
                          (const :tag "preview, unique only"
                                 company-preview-if-just-one-frontend)
+                         (const :tag "preview, unique and common part"
+                                company-preview-common-frontend)
                          (function :tag "custom function" nil))))
 
 (defcustom company-tooltip-limit 10
@@ -2912,7 +2919,7 @@ Delay is determined by `company-tooltip-idle-delay'."
 (defun company-preview-show-at-point (pos)
   (company-preview-hide)
 
-  (let ((completion (nth company-selection company-candidates)))
+  (let ((completion (if (cdr company-candidates) company-common (nth 
company-selection company-candidates))))
     (setq completion (copy-sequence (company--pre-render completion)))
     (font-lock-append-text-property 0 (length completion)
                                     'face 'company-preview
@@ -2984,6 +2991,19 @@ Delay is determined by `company-tooltip-idle-delay'."
   (when (overlayp company-pseudo-tooltip-overlay)
     (not (overlay-get company-pseudo-tooltip-overlay 'invisible))))
 
+
+(defun company--show-common-inline-p ()
+  (and company-common
+       (or (eq (company-call-backend 'ignore-case) 'keep-prefix)
+           (string-prefix-p company-prefix company-common))))
+
+(defun company-preview-common-frontend (command)
+  "`company-preview-frontend', but only shown for single candidates."
+  (when (or (not (eq command 'post-command))
+            (company--show-common-inline-p))
+    (company-preview-frontend command)))
+
+
 ;;; echo 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defvar-local company-echo-last-msg nil)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]