1 ;;; company.el --- extensible inline text completion mechanism
3 ;; Copyright (C) 2009 Nikolaj Schumacher
5 ;; Author: Nikolaj Schumacher <bugs * nschum de>
7 ;; Keywords: abbrev, convenience, matchis
8 ;; URL: http://nschum.de/src/emacs/company/
9 ;; Compatibility: GNU Emacs 22.x, GNU Emacs 23.x
11 ;; This file is NOT part of GNU Emacs.
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License
15 ;; as published by the Free Software Foundation; either version 2
16 ;; of the License, or (at your option) any later version.
18 ;; This program is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
28 ;; Company is a modular completion mechanism. Modules for retrieving completion
29 ;; candidates are called back-ends, modules for displaying them are front-ends.
31 ;; Company comes with many back-ends, e.g. `company-elisp'. These are
32 ;; distributed in individual files and can be used individually.
34 ;; Place company.el and the back-ends you want to use in a directory and add the
35 ;; following to your .emacs:
36 ;; (add-to-list 'load-path "/path/to/company")
37 ;; (autoload 'company-mode "company" nil t)
39 ;; Enable company-mode with M-x company-mode. For further information look at
40 ;; the documentation for `company-mode' (C-h f company-mode RET)
42 ;; To write your own back-end, look at the documentation for `company-backends'.
43 ;; Here is a simple example completing "foo":
45 ;; (defun company-my-backend (command &optional arg &rest ignored)
47 ;; ('prefix (when (looking-back "foo\\>")
49 ;; ('candidates (list "foobar" "foobaz" "foobarbaz"))
50 ;; ('meta (format "This value is named %s" arg))))
52 ;; Sometimes it is a good idea to mix two back-ends together, for example to
53 ;; enrich gtags with dabbrev text (to emulate local variables):
55 ;; (defun gtags-gtags-dabbrev-backend (command &optional arg &rest ignored)
57 ;; (prefix (company-gtags 'prefix))
58 ;; (candidates (append (company-gtags 'candidates arg)
59 ;; (company-dabbrev 'candidates arg)))))
62 ;; When point is at the very end of the buffer, the pseudo-tooltip appears very
63 ;; wrong, unless company is allowed to temporarily insert a fake newline.
64 ;; This behavior is enabled by `company-end-of-buffer-workaround'.
69 ;; Added `company-require-match' option.
72 ;; Improved Emacs Lisp back-end behavior for local variables.
73 ;; Added `company-elisp-detect-function-context' option.
74 ;; The mouse can now be used for selection.
77 ;; Added `company-show-location'.
78 ;; Added etags back-end.
79 ;; Added work-around for end-of-buffer bug.
80 ;; Added `company-filter-candidates'.
81 ;; More local Lisp variables are now included in the candidates.
84 ;; Fixed elisp documentation buffer always showing the same doc.
85 ;; Added `company-echo-strip-common-frontend'.
86 ;; Added `company-show-numbers' option and M-0 ... M-9 default bindings.
87 ;; Don't hide the echo message if it isn't shown.
94 (eval-when-compile (require 'cl))
96 (add-to-list 'debug-ignored-errors "^.* frontend cannot be used twice$")
97 (add-to-list 'debug-ignored-errors "^Echo area cannot be used twice$")
98 (add-to-list 'debug-ignored-errors "^No \\(document\\|loc\\)ation available$")
99 (add-to-list 'debug-ignored-errors "^Company not ")
100 (add-to-list 'debug-ignored-errors "^No candidate number ")
102 (defgroup company nil
103 "Extensible inline text completion mechanism"
108 (defface company-tooltip
109 '((t :background "yellow"
110 :foreground "black"))
111 "*Face used for the tool tip."
114 (defface company-tooltip-selection
115 '((default :inherit company-tooltip)
116 (((class color) (min-colors 88)) (:background "orange1"))
117 (t (:background "green")))
118 "*Face used for the selection in the tool tip."
121 (defface company-tooltip-mouse
122 '((default :inherit highlight))
123 "*Face used for the tool tip item under the mouse."
126 (defface company-tooltip-common
127 '((t :inherit company-tooltip
129 "*Face used for the common completion in the tool tip."
132 (defface company-tooltip-common-selection
133 '((t :inherit company-tooltip-selection
135 "*Face used for the selected common completion in the tool tip."
138 (defcustom company-tooltip-limit 10
139 "*The maximum number of candidates in the tool tip"
143 (defface company-preview
144 '((t :background "blue4"
145 :foreground "wheat"))
146 "*Face used for the completion preview."
149 (defface company-preview-common
150 '((t :inherit company-preview
152 "*Face used for the common part of the completion preview."
155 (defface company-preview-search
156 '((t :inherit company-preview
157 :background "blue1"))
158 "*Face used for the search string in the completion preview."
161 (defface company-echo nil
162 "*Face used for completions in the echo area."
165 (defface company-echo-common
166 '((((background dark)) (:foreground "firebrick1"))
167 (((background light)) (:background "firebrick4")))
168 "*Face used for the common part of completions in the echo area."
171 (defun company-frontends-set (variable value)
173 (let ((remainder value))
174 (setcdr remainder (delq (car remainder) (cdr remainder))))
175 (and (memq 'company-pseudo-tooltip-unless-just-one-frontend value)
176 (memq 'company-pseudo-tooltip-frontend value)
177 (error "Pseudo tooltip frontend cannot be used twice"))
178 (and (memq 'company-preview-if-just-one-frontend value)
179 (memq 'company-preview-frontend value)
180 (error "Preview frontend cannot be used twice"))
181 (and (memq 'company-echo value)
182 (memq 'company-echo-metadata-frontend value)
183 (error "Echo area cannot be used twice"))
184 ;; preview must come last
185 (dolist (f '(company-preview-if-just-one-frontend company-preview-frontend))
187 (setq value (append (delq f value) (list f)))))
188 (set variable value))
190 (defcustom company-frontends '(company-pseudo-tooltip-unless-just-one-frontend
191 company-preview-frontend
192 company-echo-metadata-frontend)
193 "*The list of active front-ends (visualizations).
194 Each front-end is a function that takes one argument. It is called with
195 one of the following arguments:
197 'show: When the visualization should start.
199 'hide: When the visualization should end.
201 'update: When the data has been updated.
203 'pre-command: Before every command that is executed while the
204 visualization is active.
206 'post-command: After every command that is executed while the
207 visualization is active.
209 The visualized data is stored in `company-prefix', `company-candidates',
210 `company-common', `company-selection', `company-point' and
211 `company-search-string'."
212 :set 'company-frontends-set
214 :type '(repeat (choice (const :tag "echo" company-echo-frontend)
215 (const :tag "echo, strip common"
216 company-echo-strip-common-frontend)
217 (const :tag "show echo meta-data in echo"
218 company-echo-metadata-frontend)
219 (const :tag "pseudo tooltip"
220 company-pseudo-tooltip-frontend)
221 (const :tag "pseudo tooltip, multiple only"
222 company-pseudo-tooltip-unless-just-one-frontend)
223 (const :tag "preview" company-preview-frontend)
224 (const :tag "preview, unique only"
225 company-preview-if-just-one-frontend)
226 (function :tag "custom function" nil))))
228 (defcustom company-backends '(company-elisp company-nxml company-css
229 company-semantic company-gtags company-etags
230 company-oddmuse company-files company-dabbrev)
231 "*The list of active back-ends (completion engines).
232 Each back-end is a function that takes a variable number of arguments.
233 The first argument is the command requested from the back-end. It is one
236 'prefix: The back-end should return the text to be completed. It must be
237 text immediately before `point'. Returning nil passes control to the next
240 'candidates: The second argument is the prefix to be completed. The
241 return value should be a list of candidates that start with the prefix.
245 'sorted: The back-end may return t here to indicate that the candidates
246 are sorted and will not need to be sorted again.
248 'no-cache: Usually company doesn't ask for candidates again as completion
249 progresses, unless the back-end returns t for this command. The second
250 argument is the latest prefix.
252 'meta: The second argument is a completion candidate. The back-end should
253 return a (short) documentation string for it.
255 'doc-buffer: The second argument is a completion candidate. The back-end should
256 create a buffer (preferably with `company-doc-buffer'), fill it with
257 documentation and return it.
259 'location: The second argument is a completion candidate. The back-end can
260 return the cons of buffer and buffer location, or of file and line
261 number where the completion candidate was defined.
263 'require-match: If this value is t, the user is not allowed to enter anything
264 not offering as a candidate. Use with care! The default value nil gives the
265 user that choice with `company-require-match'. Return value 'never overrides
266 that option the other way around.
268 The back-end should return nil for all commands it does not support or
269 does not know about."
271 :type '(repeat (function :tag "function" nil)))
273 (defvar start-count 0)
275 (defcustom company-completion-started-hook nil
276 "*Hook run when company starts completing.
277 The hook is called with one argument that is non-nil if the completion was
282 (defcustom company-completion-cancelled-hook nil
283 "*Hook run when company cancels completing.
284 The hook is called with one argument that is non-nil if the completion was
289 (defcustom company-completion-finished-hook nil
290 "*Hook run when company successfully completes.
291 The hook is called with the selected candidate as an argument."
295 (defcustom company-minimum-prefix-length 3
296 "*The minimum prefix length for automatic completion."
298 :type '(integer :tag "prefix length"))
300 (defcustom company-require-match 'company-explicit-action-p
301 "*If enabled, disallow non-matching input.
302 This can be a function do determine if a match is required.
304 This can be overridden by the back-end, if it returns t or 'never to
307 :type '(choice (const :tag "Off" nil)
308 (function :tag "Predicate function")
309 (const :tag "On, if user interaction took place"
310 'company-explicit-action-p)
311 (const :tag "On" t)))
313 (defcustom company-idle-delay .7
314 "*The idle delay in seconds until automatic completions starts.
315 A value of nil means never complete automatically, t means complete
316 immediately when a prefix of `company-minimum-prefix-length' is reached."
318 :type '(choice (const :tag "never (nil)" nil)
319 (const :tag "immediate (t)" t)
320 (number :tag "seconds")))
322 (defcustom company-show-numbers nil
323 "*If enabled, show quick-access numbers for the first ten candidates."
325 :type '(choice (const :tag "off" nil)
326 (const :tag "on" t)))
328 (defvar company-end-of-buffer-workaround t
329 "*Work around a visualization bug when completing at the end of the buffer.
330 The work-around consists of adding a newline.")
332 ;;; mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
334 (defvar company-mode-map (make-sparse-keymap)
335 "Keymap used by `company-mode'.")
337 (defvar company-active-map
338 (let ((keymap (make-sparse-keymap)))
339 (define-key keymap (kbd "M-n") 'company-select-next)
340 (define-key keymap (kbd "M-p") 'company-select-previous)
341 (define-key keymap (kbd "<down>") 'company-select-next)
342 (define-key keymap (kbd "<up>") 'company-select-previous)
343 (define-key keymap [down-mouse-1] 'ignore)
344 (define-key keymap [down-mouse-3] 'ignore)
345 (define-key keymap [mouse-1] 'company-complete-mouse)
346 (define-key keymap [mouse-3] 'company-select-mouse)
347 (define-key keymap [up-mouse-1] 'ignore)
348 (define-key keymap [up-mouse-3] 'ignore)
349 (define-key keymap "\C-m" 'company-complete-selection)
350 (define-key keymap "\t" 'company-complete-common)
351 (define-key keymap (kbd "<f1>") 'company-show-doc-buffer)
352 (define-key keymap "\C-w" 'company-show-location)
353 (define-key keymap "\C-s" 'company-search-candidates)
354 (define-key keymap "\C-\M-s" 'company-filter-candidates)
356 (define-key keymap (vector (+ (aref (kbd "M-0") 0) i))
357 `(lambda () (interactive) (company-complete-number ,i))))
360 "Keymap that is enabled during an active completion.")
363 (define-minor-mode company-mode
364 "\"complete anything\"; in in-buffer completion framework.
365 Completion starts automatically, depending on the values
366 `company-idle-delay' and `company-minimum-prefix-length'.
368 Completion can be controlled with the commands:
369 `company-complete-common', `company-complete-selection', `company-complete',
370 `company-select-next', `company-select-previous'. If these commands are
371 called before `company-idle-delay', completion will also start.
373 Completions can be searched with `company-search-candidates' or
374 `company-filter-candidates'. These can be used while completion is
377 The completion data is retrieved using `company-backends' and displayed using
380 regular keymap (`company-mode-map'):
383 keymap during active completions (`company-active-map'):
385 \\{company-active-map}"
386 nil " comp" company-mode-map
389 (add-hook 'pre-command-hook 'company-pre-command nil t)
390 (add-hook 'post-command-hook 'company-post-command nil t)
391 (dolist (backend company-backends)
392 (unless (fboundp backend)
393 (ignore-errors (require backend nil t)))
394 (unless (fboundp backend)
395 (message "Company back-end '%s' could not be initialized"
397 (remove-hook 'pre-command-hook 'company-pre-command t)
398 (remove-hook 'post-command-hook 'company-post-command t)
400 (kill-local-variable 'company-point)))
402 (defsubst company-assert-enabled ()
404 (company-uninstall-map)
405 (error "Company not enabled")))
407 ;;; keymaps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 (defvar company-overriding-keymap-bound nil)
410 (make-variable-buffer-local 'company-overriding-keymap-bound)
412 (defvar company-old-keymap nil)
413 (make-variable-buffer-local 'company-old-keymap)
415 (defvar company-my-keymap nil)
416 (make-variable-buffer-local 'company-my-keymap)
418 (defsubst company-enable-overriding-keymap (keymap)
419 (setq company-my-keymap keymap)
420 (when company-overriding-keymap-bound
421 (company-uninstall-map)))
423 (defun company-install-map ()
424 (unless (or company-overriding-keymap-bound
425 (null company-my-keymap))
426 (setq company-old-keymap overriding-terminal-local-map
427 overriding-terminal-local-map company-my-keymap
428 company-overriding-keymap-bound t)))
430 (defun company-uninstall-map ()
431 (when (eq overriding-terminal-local-map company-my-keymap)
432 (setq overriding-terminal-local-map company-old-keymap
433 company-overriding-keymap-bound nil)))
436 ;; Emacs calculates the active keymaps before reading the event. That means we
437 ;; cannot change the keymap from a timer. So we send a bogus command.
438 (defun company-ignore ()
441 (global-set-key '[31415926] 'company-ignore)
443 (defun company-input-noop ()
444 (push 31415926 unread-command-events))
446 ;;; backends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
448 (defun company-grab (regexp &optional expression)
449 (when (looking-back regexp)
450 (or (match-string-no-properties (or expression 0)) "")))
452 (defun company-in-string-or-comment (&optional point)
453 (let ((pos (syntax-ppss)))
454 (or (nth 3 pos) (nth 4 pos) (nth 7 pos))))
456 ;;; completion mechanism ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
458 (defvar company-backend nil)
459 (make-variable-buffer-local 'company-backend)
461 (defvar company-prefix nil)
462 (make-variable-buffer-local 'company-prefix)
464 (defvar company-candidates nil)
465 (make-variable-buffer-local 'company-candidates)
467 (defvar company-candidates-length nil)
468 (make-variable-buffer-local 'company-candidates-length)
470 (defvar company-candidates-cache nil)
471 (make-variable-buffer-local 'company-candidates-cache)
473 (defvar company-candidates-predicate nil)
474 (make-variable-buffer-local 'company-candidates-predicate)
476 (defvar company-common nil)
477 (make-variable-buffer-local 'company-common)
479 (defvar company-selection 0)
480 (make-variable-buffer-local 'company-selection)
482 (defvar company-selection-changed nil)
483 (make-variable-buffer-local 'company-selection-changed)
485 (defvar company--explicit-action nil
486 "Non-nil, if explicit completion took place.")
487 (make-variable-buffer-local 'company--explicit-action)
489 (defvar company-point nil)
490 (make-variable-buffer-local 'company-point)
492 (defvar company-timer nil)
494 (defvar company-added-newline nil)
495 (make-variable-buffer-local 'company-added-newline)
497 (defsubst company-strip-prefix (str)
498 (substring str (length company-prefix)))
500 (defun company-explicit-action-p ()
501 "Return whether explicit completion action was taken by the user."
502 (or company--explicit-action
503 company-selection-changed))
505 (defsubst company-reformat (candidate)
506 ;; company-ispell needs this, because the results are always lower-case
507 ;; It's mory efficient to fix it only when they are displayed.
508 (concat company-prefix (substring candidate (length company-prefix))))
510 (defsubst company-should-complete (prefix)
511 (and (eq company-idle-delay t)
512 (>= (length prefix) company-minimum-prefix-length)))
514 (defsubst company-call-frontends (command)
515 (dolist (frontend company-frontends)
517 (funcall frontend command)
518 (error (error "Company: Front-end %s error \"%s\" on command %s"
519 frontend (error-message-string err) command)))))
521 (defsubst company-set-selection (selection &optional force-update)
522 (setq selection (max 0 (min (1- company-candidates-length) selection)))
523 (when (or force-update (not (equal selection company-selection)))
524 (setq company-selection selection
525 company-selection-changed t)
526 (company-call-frontends 'update)))
528 (defun company-apply-predicate (candidates predicate)
530 (dolist (c candidates)
531 (when (funcall predicate c)
535 (defun company-update-candidates (candidates)
536 (setq company-candidates-length (length candidates))
537 (if (> company-selection 0)
538 ;; Try to restore the selection
539 (let ((selected (nth company-selection company-candidates)))
540 (setq company-selection 0
541 company-candidates candidates)
543 (while (and candidates (string< (pop candidates) selected))
544 (incf company-selection))
546 ;; Make sure selection isn't out of bounds.
547 (setq company-selection (min (1- company-candidates-length)
548 company-selection)))))
549 (setq company-selection 0
550 company-candidates candidates))
552 (push (cons company-prefix company-candidates) company-candidates-cache)
554 (let ((completion-ignore-case (funcall company-backend 'ignore-case)))
555 (setq company-common (try-completion company-prefix company-candidates)))
556 (when (eq company-common t)
557 (setq company-candidates nil)))
559 (defun company-calculate-candidates (prefix)
560 (or (cdr (assoc prefix company-candidates-cache))
561 (when company-candidates-cache
562 (let ((len (length prefix))
563 (completion-ignore-case (funcall company-backend 'ignore-case))
566 (when (setq prev (cdr (assoc (substring prefix 0 (- len i))
567 company-candidates-cache)))
568 (return (all-completions prefix prev))))))
569 (let ((candidates (funcall company-backend 'candidates prefix)))
570 (when company-candidates-predicate
572 (company-apply-predicate candidates
573 company-candidates-predicate)))
574 (unless (funcall company-backend 'sorted)
575 (setq candidates (sort candidates 'string<)))
576 (when (or (cdr candidates)
577 (not (equal (car candidates) prefix)))
578 ;; Don't start when already completed and unique.
581 (defun company-idle-begin (buf win tick pos)
583 (eq buf (current-buffer))
584 (eq win (selected-window))
585 (eq tick (buffer-chars-modified-tick))
587 (not company-candidates)
588 (not (equal (point) company-point))
589 (let ((company-idle-delay t))
591 (when company-candidates
593 (company-post-command)))))
595 (defun company-manual-begin ()
597 (company-assert-enabled)
599 (not company-candidates)
600 (let ((company-idle-delay t)
601 (company-minimum-prefix-length 0))
602 (setq company--explicit-action t)
604 ;; Return non-nil if active.
607 (defsubst company-incremental-p (old-prefix new-prefix)
608 (and (> (length new-prefix) (length old-prefix))
609 (equal old-prefix (substring new-prefix 0 (length old-prefix)))))
611 (defun company-require-match-p ()
612 (let ((backend-value (funcall company-backend 'require-match)))
613 (or (eq backend-value t)
614 (and (if (functionp company-require-match)
615 (funcall company-require-match)
616 (eq company-require-match t))
617 (not (eq backend-value 'never))))))
619 (defun company-continue ()
620 (when company-candidates
621 (when (funcall company-backend 'no-cache company-prefix)
622 ;; Don't complete existing candidates, fetch new ones.
623 (setq company-candidates-cache nil))
624 (let ((new-prefix (funcall company-backend 'prefix)))
625 (unless (and (= (- (point) (length new-prefix))
626 (- company-point (length company-prefix)))
627 (or (equal company-prefix new-prefix)
628 (let ((c (company-calculate-candidates new-prefix)))
630 (setq company-prefix new-prefix)
631 (company-update-candidates c)
633 (if (not (and (company-incremental-p company-prefix new-prefix)
634 (company-require-match-p)))
635 (setq company-candidates nil)
636 (backward-delete-char (length new-prefix))
637 (insert company-prefix)
639 (message "Matching input is required")
640 company-candidates)))))
642 (defun company-begin ()
643 (if (or buffer-read-only overriding-terminal-local-map overriding-local-map)
644 ;; Don't complete in these cases.
645 (setq company-candidates nil)
647 (unless company-candidates
649 (dolist (backend company-backends)
650 (when (and (fboundp backend)
651 (setq prefix (funcall backend 'prefix)))
652 (setq company-backend backend)
653 (when (company-should-complete prefix)
654 (let ((c (company-calculate-candidates prefix)))
656 (setq company-prefix prefix)
657 (company-update-candidates c)
658 (run-hook-with-args 'company-completion-started-hook
659 (company-explicit-action-p))
660 (company-call-frontends 'show))))
662 (if company-candidates
664 (when (and company-end-of-buffer-workaround (eobp))
665 (save-excursion (insert "\n"))
666 (setq company-added-newline (buffer-chars-modified-tick)))
667 (setq company-point (point))
668 (company-enable-overriding-keymap company-active-map)
669 (company-call-frontends 'update))
672 (defun company-cancel (&optional result)
673 (and company-added-newline
674 (> (point-max) (point-min))
675 (let ((tick (buffer-chars-modified-tick)))
676 (delete-region (1- (point-max)) (point-max))
677 (equal tick company-added-newline))
678 ;; Only set unmodified when tick remained the same since insert.
679 (set-buffer-modified-p nil))
682 (run-hook-with-args 'company-completion-finished-hook result)
683 (run-hook-with-args 'company-completion-cancelled-hook result)))
684 (setq company-added-newline nil
687 company-candidates nil
688 company-candidates-length nil
689 company-candidates-cache nil
690 company-candidates-predicate nil
693 company-selection-changed nil
694 company--explicit-action nil
697 (cancel-timer company-timer))
698 (company-search-mode 0)
699 (company-call-frontends 'hide)
700 (company-enable-overriding-keymap nil))
702 (defun company-abort ()
704 ;; Don't start again, unless started manually.
705 (setq company-point (point)))
707 (defun company-finish (result)
708 (insert (company-strip-prefix result))
709 (company-cancel result)
710 ;; Don't start again, unless started manually.
711 (setq company-point (point)))
713 (defsubst company-keep (command)
714 (and (symbolp command) (get command 'company-keep)))
716 (defun company-pre-command ()
717 (unless (company-keep this-command)
719 (when company-candidates
720 (company-call-frontends 'pre-command))
721 (error (message "Company: An error occurred in pre-command")
722 (message "%s" (error-message-string err))
725 (cancel-timer company-timer))
726 (company-uninstall-map))
728 (defun company-post-command ()
729 (unless (company-keep this-command)
732 (unless (equal (point) company-point)
734 (when company-candidates
735 (company-call-frontends 'post-command))
736 (when (numberp company-idle-delay)
738 (run-with-timer company-idle-delay nil 'company-idle-begin
739 (current-buffer) (selected-window)
740 (buffer-chars-modified-tick) (point)))))
741 (error (message "Company: An error occurred in post-command")
742 (message "%s" (error-message-string err))
744 (company-install-map))
746 ;;; search ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
748 (defvar company-search-string nil)
749 (make-variable-buffer-local 'company-search-string)
751 (defvar company-search-lighter " Search: \"\"")
752 (make-variable-buffer-local 'company-search-lighter)
754 (defvar company-search-old-map nil)
755 (make-variable-buffer-local 'company-search-old-map)
757 (defvar company-search-old-selection 0)
758 (make-variable-buffer-local 'company-search-old-selection)
760 (defun company-search (text lines)
761 (let ((quoted (regexp-quote text))
764 (when (string-match quoted line (length company-prefix))
768 (defun company-search-printing-char ()
770 (company-search-assert-enabled)
771 (setq company-search-string
772 (concat (or company-search-string "") (string last-command-event))
773 company-search-lighter (concat " Search: \"" company-search-string
775 (let ((pos (company-search company-search-string
776 (nthcdr company-selection company-candidates))))
779 (company-set-selection (+ company-selection pos) t))))
781 (defun company-search-repeat-forward ()
782 "Repeat the incremental search in completion candidates forward."
784 (company-search-assert-enabled)
785 (let ((pos (company-search company-search-string
786 (cdr (nthcdr company-selection
787 company-candidates)))))
790 (company-set-selection (+ company-selection pos 1) t))))
792 (defun company-search-repeat-backward ()
793 "Repeat the incremental search in completion candidates backwards."
795 (company-search-assert-enabled)
796 (let ((pos (company-search company-search-string
797 (nthcdr (- company-candidates-length
799 (reverse company-candidates)))))
802 (company-set-selection (- company-selection pos 1) t))))
804 (defun company-create-match-predicate ()
805 (setq company-candidates-predicate
807 ,(if company-candidates-predicate
808 `(and (string-match ,company-search-string candidate)
809 (funcall ,company-candidates-predicate
811 `(string-match ,company-search-string candidate))))
812 (company-update-candidates
813 (company-apply-predicate company-candidates company-candidates-predicate))
815 (setq company-candidates-cache (cons company-prefix company-candidates)))
817 (defun company-filter-printing-char ()
819 (company-search-assert-enabled)
820 (company-search-printing-char)
821 (company-create-match-predicate)
822 (company-call-frontends 'update))
824 (defun company-search-kill-others ()
825 "Limit the completion candidates to the ones matching the search string."
827 (company-search-assert-enabled)
828 (company-create-match-predicate)
829 (company-search-mode 0)
830 (company-call-frontends 'update))
832 (defun company-search-abort ()
833 "Abort searching the completion candidates."
835 (company-search-assert-enabled)
836 (company-set-selection company-search-old-selection t)
837 (company-search-mode 0))
839 (defun company-search-other-char ()
841 (company-search-assert-enabled)
842 (company-search-mode 0)
843 (when last-input-event
844 (clear-this-command-keys t)
845 (setq unread-command-events (list last-input-event))))
847 (defvar company-search-map
849 (keymap (make-keymap)))
850 (if (fboundp 'max-char)
851 (set-char-table-range (nth 1 keymap) (cons #x100 (max-char))
852 'company-search-printing-char)
854 ;; obselete in Emacs 23
855 (let ((l (generic-character-list))
856 (table (nth 1 keymap)))
858 (set-char-table-default table (car l) 'company-search-printing-char)
860 (define-key keymap [t] 'company-search-other-char)
862 (define-key keymap (make-string 1 i) 'company-search-other-char)
865 (define-key keymap (vector i) 'company-search-printing-char)
867 (let ((meta-map (make-sparse-keymap)))
868 (define-key keymap (char-to-string meta-prefix-char) meta-map)
869 (define-key keymap [escape] meta-map))
870 (define-key keymap (vector meta-prefix-char t) 'company-search-other-char)
871 (define-key keymap "\e\e\e" 'company-search-other-char)
872 (define-key keymap [escape escape escape] 'company-search-other-char)
874 (define-key keymap "\C-g" 'company-search-abort)
875 (define-key keymap "\C-s" 'company-search-repeat-forward)
876 (define-key keymap "\C-r" 'company-search-repeat-backward)
877 (define-key keymap "\C-o" 'company-search-kill-others)
879 "Keymap used for incrementally searching the completion candidates.")
881 (define-minor-mode company-search-mode
882 "Search mode for completion candidates.
883 Don't start this directly, use `company-search-candidates' or
884 `company-filter-candidates'."
885 nil company-search-lighter nil
886 (if company-search-mode
887 (if (company-manual-begin)
889 (setq company-search-old-selection company-selection)
890 (company-call-frontends 'update))
891 (setq company-search-mode nil))
892 (kill-local-variable 'company-search-string)
893 (kill-local-variable 'company-search-lighter)
894 (kill-local-variable 'company-search-old-selection)
895 (company-enable-overriding-keymap company-active-map)))
897 (defsubst company-search-assert-enabled ()
898 (company-assert-enabled)
899 (unless company-search-mode
900 (company-uninstall-map)
901 (error "Company not in search mode")))
903 (defun company-search-candidates ()
904 "Start searching the completion candidates incrementally.
906 \\<company-search-map>Search can be controlled with the commands:
907 - `company-search-repeat-forward' (\\[company-search-repeat-forward])
908 - `company-search-repeat-backward' (\\[company-search-repeat-backward])
909 - `company-search-abort' (\\[company-search-abort])
911 Regular characters are appended to the search string.
913 The command `company-search-kill-others' (\\[company-search-kill-others]) uses
914 the search string to limit the completion candidates."
916 (company-search-mode 1)
917 (company-enable-overriding-keymap company-search-map))
919 (defvar company-filter-map
920 (let ((keymap (make-keymap)))
921 (define-key keymap [remap company-search-printing-char]
922 'company-filter-printing-char)
923 (set-keymap-parent keymap company-search-map)
925 "Keymap used for incrementally searching the completion candidates.")
927 (defun company-filter-candidates ()
928 "Start filtering the completion candidates incrementally.
929 This works the same way as `company-search-candidates' immediately
930 followed by `company-search-kill-others' after each input."
932 (company-search-mode 1)
933 (company-enable-overriding-keymap company-filter-map))
935 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
937 (defun company-select-next ()
938 "Select the next candidate in the list."
940 (when (company-manual-begin)
941 (company-set-selection (1+ company-selection))))
943 (defun company-select-previous ()
944 "Select the previous candidate in the list."
946 (when (company-manual-begin)
947 (company-set-selection (1- company-selection))))
949 (defun company-select-mouse (event)
950 "Select the candidate picked by the mouse."
952 (when (nth 4 (event-start event))
953 (company-set-selection (- (cdr (posn-col-row (event-start event)))
954 (cdr (posn-col-row (posn-at-point)))
958 (defun company-complete-mouse (event)
959 "Complete the candidate picked by the mouse."
961 (when (company-select-mouse event)
962 (company-complete-selection)))
964 (defun company-complete-selection ()
965 "Complete the selected candidate."
967 (when (company-manual-begin)
968 (company-finish (nth company-selection company-candidates))))
970 (defun company-complete-common ()
971 "Complete the common part of all candidates."
973 (when (company-manual-begin)
974 (if (equal company-common (car company-candidates))
975 ;; for success message
976 (company-complete-selection)
977 (insert (company-strip-prefix company-common)))))
979 (defun company-complete ()
980 "Complete the common part of all candidates or the current selection.
981 The first time this is called, the common part is completed, the second time, or
982 when the selection has been changed, the selected candidate is completed."
984 (when (company-manual-begin)
985 (if (or company-selection-changed
986 (eq last-command 'company-complete-common))
987 (call-interactively 'company-complete-selection)
988 (call-interactively 'company-complete-common)
989 (setq this-command 'company-complete-common))))
991 (defun company-complete-number (n)
992 "Complete the Nth candidate."
993 (when (company-manual-begin)
994 (and (< n 1) (> n company-candidates-length)
995 (error "No candidate number %d" n))
997 (company-finish (nth n company-candidates))))
999 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1001 (defconst company-space-strings-limit 100)
1003 (defconst company-space-strings
1005 (dotimes (i company-space-strings-limit)
1006 (push (make-string (- company-space-strings-limit 1 i) ?\ ) lst))
1007 (apply 'vector lst)))
1009 (defsubst company-space-string (len)
1010 (if (< len company-space-strings-limit)
1011 (aref company-space-strings len)
1012 (make-string len ?\ )))
1014 (defsubst company-safe-substring (str from &optional to)
1015 (let ((len (length str)))
1018 (if (and to (> to len))
1019 (concat (substring str from)
1020 (company-space-string (- to len)))
1021 (substring str from to)))))
1023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1025 (defvar company-last-metadata nil)
1026 (make-variable-buffer-local 'company-last-metadata)
1028 (defun company-fetch-metadata ()
1029 (let ((selected (nth company-selection company-candidates)))
1030 (unless (equal selected (car company-last-metadata))
1031 (setq company-last-metadata
1032 (cons selected (funcall company-backend 'meta selected))))
1033 (cdr company-last-metadata)))
1035 (defun company-doc-buffer (&optional string)
1036 (with-current-buffer (get-buffer-create "*Company meta-data*")
1040 (defmacro company-electric (&rest body)
1041 (declare (indent 0) (debug t))
1042 `(when (company-manual-begin)
1043 (save-window-excursion
1044 (let ((height (window-height))
1045 (row (cdr (posn-col-row (posn-at-point)))))
1047 (and (< (window-height) height)
1048 (< (- (window-height) row 2) company-tooltip-limit)
1049 (recenter (- (window-height) row 2)))
1050 (while (eq 'scroll-other-window
1051 (key-binding (vector (list (read-event)))))
1052 (call-interactively 'scroll-other-window))
1053 (when last-input-event
1054 (clear-this-command-keys t)
1055 (setq unread-command-events (list last-input-event)))))))
1057 (defun company-show-doc-buffer ()
1058 "Temporarily show a buffer with the complete documentation for the selection."
1061 (let ((selected (nth company-selection company-candidates)))
1062 (display-buffer (or (funcall company-backend 'doc-buffer selected)
1063 (error "No documentation available")) t))))
1064 (put 'company-show-doc-buffer 'company-keep t)
1066 (defun company-show-location ()
1067 "Temporarily display a buffer showing the selected candidate in context."
1070 (let* ((selected (nth company-selection company-candidates))
1071 (location (funcall company-backend 'location selected))
1072 (pos (or (cdr location) (error "No location available")))
1073 (buffer (or (and (bufferp (car location)) (car location))
1074 (find-file-noselect (car location) t))))
1075 (with-selected-window (display-buffer buffer t)
1076 (if (bufferp (car location))
1079 (set-window-start nil (point))))))
1080 (put 'company-show-location 'company-keep t)
1082 ;;; pseudo-tooltip ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1084 (defvar company-pseudo-tooltip-overlay nil)
1085 (make-variable-buffer-local 'company-pseudo-tooltip-overlay)
1087 (defvar company-tooltip-offset 0)
1088 (make-variable-buffer-local 'company-tooltip-offset)
1090 (defun company-pseudo-tooltip-update-offset (selection num-lines limit)
1093 (setq company-tooltip-offset
1094 (max (min selection company-tooltip-offset)
1095 (- selection -1 limit)))
1097 (when (<= company-tooltip-offset 1)
1099 (setq company-tooltip-offset 0))
1101 (when (>= company-tooltip-offset (- num-lines limit 1))
1103 (when (= selection (1- num-lines))
1104 (decf company-tooltip-offset)
1105 (when (<= company-tooltip-offset 1)
1106 (setq company-tooltip-offset 0)
1113 (defsubst company-round-tab (arg)
1114 (* (/ (+ arg tab-width) tab-width) tab-width))
1116 (defun company-untabify (str)
1117 (let* ((pieces (split-string str "\t"))
1120 (setcar copy (company-safe-substring
1121 (car copy) 0 (company-round-tab (string-width (car copy)))))
1123 (apply 'concat pieces)))
1125 (defun company-fill-propertize (line width selected)
1126 (setq line (company-safe-substring line 0 width))
1127 (add-text-properties 0 width '(face company-tooltip
1128 mouse-face company-tooltip-mouse)
1130 (add-text-properties 0 (length company-common)
1131 '(face company-tooltip-common
1132 mouse-face company-tooltip-mouse)
1135 (if (and company-search-string
1136 (string-match (regexp-quote company-search-string) line
1137 (length company-prefix)))
1139 (add-text-properties (match-beginning 0) (match-end 0)
1140 '(face company-tooltip-selection)
1142 (when (< (match-beginning 0) (length company-common))
1143 (add-text-properties (match-beginning 0) (length company-common)
1144 '(face company-tooltip-common-selection)
1146 (add-text-properties 0 width '(face company-tooltip-selection
1147 mouse-face company-tooltip-selection)
1149 (add-text-properties 0 (length company-common)
1150 '(face company-tooltip-common-selection
1151 mouse-face company-tooltip-selection)
1157 (defun company-buffer-lines (beg end)
1159 (let ((row (cdr (posn-col-row (posn-at-point))))
1161 (while (and (equal (move-to-window-line (incf row)) row)
1163 (push (buffer-substring beg (min end (1- (point)))) lines)
1165 (unless (eq beg end)
1166 (push (buffer-substring beg end) lines))
1169 (defsubst company-modify-line (old new offset)
1170 (concat (company-safe-substring old 0 offset)
1172 (company-safe-substring old (+ offset (length new)))))
1174 (defun company-replacement-string (old lines column nl)
1176 ;; Inject into old lines.
1178 (push (company-modify-line (pop old) (pop lines) column) new))
1179 ;; Append whole new lines.
1181 (push (concat (company-space-string column) (pop lines)) new))
1182 (concat (when nl "\n")
1183 (mapconcat 'identity (nreverse new) "\n")
1186 (defun company-create-lines (column selection limit)
1188 (let ((len company-candidates-length)
1197 ;; Scroll to offset.
1198 (setq limit (company-pseudo-tooltip-update-offset selection len limit))
1200 (when (> company-tooltip-offset 0)
1201 (setq previous (format "...(%d)" company-tooltip-offset)))
1203 (setq remainder (- len limit company-tooltip-offset)
1204 remainder (when (> remainder 0)
1205 (setq remainder (format "...(%d)" remainder))))
1207 (decf selection company-tooltip-offset)
1208 (setq width (min (length previous) (length remainder))
1209 lines (nthcdr company-tooltip-offset company-candidates)
1214 (setq width (max (length (pop lines-copy)) width)))
1215 (setq width (min width (- (window-width) column)))
1217 (setq lines-copy lines)
1219 ;; number can make tooltip too long
1220 (and company-show-numbers
1221 (< (setq numbered company-tooltip-offset) 10)
1225 (push (propertize (company-safe-substring previous 0 width)
1226 'face 'company-tooltip)
1230 (push (company-fill-propertize
1231 (if (>= numbered 10)
1232 (company-reformat (pop lines))
1235 (company-safe-substring (company-reformat (pop lines))
1238 width (equal i selection))
1242 (push (propertize (company-safe-substring remainder 0 width)
1243 'face 'company-tooltip)
1246 (setq lines (nreverse new))))
1250 (defsubst company-pseudo-tooltip-height ()
1251 "Calculate the appropriate tooltip height."
1252 (max 3 (min company-tooltip-limit
1253 (- (window-height) 2
1254 (count-lines (window-start) (point-at-bol))))))
1256 (defun company-pseudo-tooltip-show (row column selection)
1257 (company-pseudo-tooltip-hide)
1262 (let* ((height (company-pseudo-tooltip-height))
1263 (lines (company-create-lines column selection height))
1264 (nl (< (move-to-window-line row) row))
1266 (end (save-excursion
1267 (move-to-window-line (+ row height))
1270 (mapcar 'company-untabify (company-buffer-lines beg end)))
1273 (setq company-pseudo-tooltip-overlay (make-overlay beg end))
1275 (overlay-put company-pseudo-tooltip-overlay 'company-old old-string)
1276 (overlay-put company-pseudo-tooltip-overlay 'company-column column)
1277 (overlay-put company-pseudo-tooltip-overlay 'company-nl nl)
1278 (overlay-put company-pseudo-tooltip-overlay 'company-before
1279 (company-replacement-string old-string lines column nl))
1280 (overlay-put company-pseudo-tooltip-overlay 'company-height height)
1282 (overlay-put company-pseudo-tooltip-overlay 'window (selected-window)))))
1284 (defun company-pseudo-tooltip-show-at-point (pos)
1285 (let ((col-row (posn-col-row (posn-at-point pos))))
1286 (company-pseudo-tooltip-show (1+ (cdr col-row)) (car col-row) company-selection)))
1288 (defun company-pseudo-tooltip-edit (lines selection)
1289 (let* ((old-string (overlay-get company-pseudo-tooltip-overlay 'company-old))
1290 (column (overlay-get company-pseudo-tooltip-overlay 'company-column))
1291 (nl (overlay-get company-pseudo-tooltip-overlay 'company-nl))
1292 (height (overlay-get company-pseudo-tooltip-overlay 'company-height))
1293 (lines (company-create-lines column selection height)))
1294 (overlay-put company-pseudo-tooltip-overlay 'company-before
1295 (company-replacement-string old-string lines column nl))))
1297 (defun company-pseudo-tooltip-hide ()
1298 (when company-pseudo-tooltip-overlay
1299 (delete-overlay company-pseudo-tooltip-overlay)
1300 (setq company-pseudo-tooltip-overlay nil)))
1302 (defun company-pseudo-tooltip-hide-temporarily ()
1303 (when (overlayp company-pseudo-tooltip-overlay)
1304 (overlay-put company-pseudo-tooltip-overlay 'invisible nil)
1305 (overlay-put company-pseudo-tooltip-overlay 'before-string nil)))
1307 (defun company-pseudo-tooltip-unhide ()
1308 (when company-pseudo-tooltip-overlay
1309 (overlay-put company-pseudo-tooltip-overlay 'invisible t)
1310 (overlay-put company-pseudo-tooltip-overlay 'before-string
1311 (overlay-get company-pseudo-tooltip-overlay 'company-before))
1312 (overlay-put company-pseudo-tooltip-overlay 'window (selected-window))))
1314 (defun company-pseudo-tooltip-frontend (command)
1315 "A `company-mode' front-end similar to a tool-tip but based on overlays."
1317 ('pre-command (company-pseudo-tooltip-hide-temporarily))
1319 (unless (and (overlayp company-pseudo-tooltip-overlay)
1320 (equal (overlay-get company-pseudo-tooltip-overlay
1322 (company-pseudo-tooltip-height)))
1324 (company-pseudo-tooltip-show-at-point (- (point)
1325 (length company-prefix))))
1326 (company-pseudo-tooltip-unhide))
1327 ('hide (company-pseudo-tooltip-hide)
1328 (setq company-tooltip-offset 0))
1329 ('update (when (overlayp company-pseudo-tooltip-overlay)
1330 (company-pseudo-tooltip-edit company-candidates
1331 company-selection)))))
1333 (defun company-pseudo-tooltip-unless-just-one-frontend (command)
1334 "`company-pseudo-tooltip-frontend', but not shown for single candidates."
1335 (unless (and (eq command 'post-command)
1336 (not (cdr company-candidates)))
1337 (company-pseudo-tooltip-frontend command)))
1339 ;;; overlay ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1341 (defvar company-preview-overlay nil)
1342 (make-variable-buffer-local 'company-preview-overlay)
1344 (defun company-preview-show-at-point (pos)
1345 (company-preview-hide)
1347 (setq company-preview-overlay (make-overlay pos pos))
1349 (let ((completion(nth company-selection company-candidates)))
1350 (setq completion (propertize completion 'face 'company-preview))
1351 (add-text-properties 0 (length company-common)
1352 '(face company-preview-common) completion)
1354 ;; Add search string
1355 (and company-search-string
1356 (string-match (regexp-quote company-search-string) completion)
1357 (add-text-properties (match-beginning 0)
1359 '(face company-preview-search)
1362 (setq completion (company-strip-prefix completion))
1364 (and (equal pos (point))
1365 (not (equal completion ""))
1366 (add-text-properties 0 1 '(cursor t) completion))
1368 (overlay-put company-preview-overlay 'after-string completion)
1369 (overlay-put company-preview-overlay 'window (selected-window))))
1371 (defun company-preview-hide ()
1372 (when company-preview-overlay
1373 (delete-overlay company-preview-overlay)
1374 (setq company-preview-overlay nil)))
1376 (defun company-preview-frontend (command)
1377 "A `company-mode' front-end showing the selection as if it had been inserted."
1379 ('pre-command (company-preview-hide))
1380 ('post-command (company-preview-show-at-point (point)))
1381 ('hide (company-preview-hide))))
1383 (defun company-preview-if-just-one-frontend (command)
1384 "`company-preview-frontend', but only shown for single candidates."
1385 (unless (and (eq command 'post-command)
1386 (cdr company-candidates))
1387 (company-preview-frontend command)))
1389 ;;; echo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1391 (defvar company-echo-last-msg nil)
1392 (make-variable-buffer-local 'company-echo-last-msg)
1394 (defvar company-echo-timer nil)
1396 (defvar company-echo-delay .1)
1398 (defun company-echo-show (&optional getter)
1400 (setq company-echo-last-msg (funcall getter)))
1401 (let ((message-log-max nil))
1402 (if company-echo-last-msg
1403 (message "%s" company-echo-last-msg)
1406 (defsubst company-echo-show-soon (&optional getter)
1407 (when company-echo-timer
1408 (cancel-timer company-echo-timer))
1409 (setq company-echo-timer (run-with-timer company-echo-delay nil
1410 'company-echo-show getter)))
1412 (defun company-echo-format ()
1414 (let ((limit (window-width (minibuffer-window)))
1416 ;; Roll to selection.
1417 (candidates (nthcdr company-selection company-candidates))
1418 (i (if company-show-numbers company-selection 99999))
1422 (setq comp (company-reformat (pop candidates))
1423 len (+ len 1 (length comp)))
1427 (setq comp (propertize (format "%d: %s" i comp)
1428 'face 'company-echo))
1431 (add-text-properties 3 (+ 3 (length company-common))
1432 '(face company-echo-common) comp))
1433 (setq comp (propertize comp 'face 'company-echo))
1434 (add-text-properties 0 (length company-common)
1435 '(face company-echo-common) comp))
1437 (setq candidates nil)
1440 (mapconcat 'identity (nreverse msg) " ")))
1442 (defun company-echo-strip-common-format ()
1444 (let ((limit (window-width (minibuffer-window)))
1445 (len (+ (length company-prefix) 2))
1446 ;; Roll to selection.
1447 (candidates (nthcdr company-selection company-candidates))
1448 (i (if company-show-numbers company-selection 99999))
1452 (setq comp (company-strip-prefix (pop candidates))
1453 len (+ len 2 (length comp)))
1456 (setq comp (format "%s (%d)" comp i))
1460 (setq candidates nil)
1461 (push (propertize comp 'face 'company-echo) msg)))
1463 (concat (propertize company-prefix 'face 'company-echo-common) "{"
1464 (mapconcat 'identity (nreverse msg) ", ")
1467 (defun company-echo-hide ()
1468 (when company-echo-timer
1469 (cancel-timer company-echo-timer))
1470 (unless (equal company-echo-last-msg "")
1471 (setq company-echo-last-msg "")
1472 (company-echo-show)))
1474 (defun company-echo-frontend (command)
1475 "A `company-mode' front-end showing the candidates in the echo area."
1477 ('pre-command (company-echo-show-soon))
1478 ('post-command (company-echo-show-soon 'company-echo-format))
1479 ('hide (company-echo-hide))))
1481 (defun company-echo-strip-common-frontend (command)
1482 "A `company-mode' front-end showing the candidates in the echo area."
1484 ('pre-command (company-echo-show-soon))
1485 ('post-command (company-echo-show-soon 'company-echo-strip-common-format))
1486 ('hide (company-echo-hide))))
1488 (defun company-echo-metadata-frontend (command)
1489 "A `company-mode' front-end showing the documentation in the echo area."
1491 ('pre-command (company-echo-show-soon))
1492 ('post-command (company-echo-show-soon 'company-fetch-metadata))
1493 ('hide (company-echo-hide))))
1496 ;;; company.el ends here