branch: externals/company
commit e5637192f23666983d46ddd535bc853b77c12006
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>

    Support completion in minibuffer
    
    Experimental for overlay popup; just works with the child frame one.
---
 NEWS.md    |  2 ++
 company.el | 25 +++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/NEWS.md b/NEWS.md
index cd93895569..877948649d 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
 
 # Next
 
+* New option `company-global-minibuffer` for completion during 
`eval-expression`
+  (`M-:`).
 * `C-M-i` is bound to `company-complete-common` when completion is active.
 * New built-in frontend using "real graphical" widget for the popup
   ([#1525](https://github.com/company-mode/company-mode/pull/1525)).
diff --git a/company.el b/company.el
index 19afa2fb2f..4574f20f4b 100644
--- a/company.el
+++ b/company.el
@@ -1054,10 +1054,19 @@ means that `company-mode' is always turned on except in 
`message-mode' buffers."
                       (const :tag "Except" not)
                       (repeat :inline t (symbol :tag "mode")))))
 
+(defcustom company-global-minibuffer t
+  "Non-nil to enable `company-mode' in the minibuffer.
+The value can be t (meaning only enable if the minibuffer has a local
+`completion-at-point-functions' value) or a custom predicate function."
+  :type 'boolean)
+
 ;;;###autoload
 (define-globalized-minor-mode global-company-mode company-mode company-mode-on)
 
 (defun company-mode-on ()
+  (when (and company-global-minibuffer
+             (minibufferp))
+    (add-hook 'minibuffer-setup-hook #'company--minibuffer-on 100))
   (when (and (not (or noninteractive (eq (aref (buffer-name) 0) ?\s)))
              (cond ((eq company-global-modes t)
                     t)
@@ -1066,6 +1075,14 @@ means that `company-mode' is always turned on except in 
`message-mode' buffers."
                    (t (memq major-mode company-global-modes))))
     (company-mode 1)))
 
+(defun company--minibuffer-on ()
+  (when (and (or resize-mini-windows
+                 (not (try-completion "company-pseudo-tooltip" 
company-frontends)))
+             (if (eq company-global-minibuffer t)
+                 (local-variable-p 'completion-at-point-functions)
+               (funcall company-global-minibuffer)))
+    (company-mode 1)))
+
 (defsubst company-assert-enabled ()
   (unless company-mode
     (company-uninstall-map)
@@ -4326,12 +4343,20 @@ Returns a negative number if the tooltip should be 
displayed above point."
         (overlay-put ov 'company-height height))))
 
 (defun company-pseudo-tooltip-show-at-point (pos column-offset)
+  (when (and (= (window-size) 1)
+             (minibufferp))
+    (add-hook 'window-size-change-functions #'company-pseudo-tooltip-refresh 
nil t))
   (let* ((col-row (company--col-row pos))
          (col (- (car col-row) column-offset)))
     (when (< col 0) (setq col 0))
     (company--with-face-remappings
      (company-pseudo-tooltip-show (1+ (cdr col-row)) col company-selection))))
 
+(defun company-pseudo-tooltip-refresh (_window)
+  (when company-pseudo-tooltip-overlay
+    (overlay-put company-pseudo-tooltip-overlay 'company-guard nil))
+  (company-pseudo-tooltip-frontend 'post-command))
+
 (defun company-pseudo-tooltip-edit (selection)
   (let* ((height (overlay-get company-pseudo-tooltip-overlay 'company-height))
          (lines-and-offset  (company--create-lines selection (abs height)))

Reply via email to