]> code.delx.au - gnu-emacs-elpa/blob - company.el
Don't change lighter to back-end name, if it isn't a symbol.
[gnu-emacs-elpa] / company.el
1 ;;; company.el --- extensible inline text completion mechanism
2 ;;
3 ;; Copyright (C) 2009 Nikolaj Schumacher
4 ;;
5 ;; Author: Nikolaj Schumacher <bugs * nschum de>
6 ;; Version: 0.4.2
7 ;; Keywords: abbrev, convenience, matchis
8 ;; URL: http://nschum.de/src/emacs/company/
9 ;; Compatibility: GNU Emacs 22.x, GNU Emacs 23.x
10 ;;
11 ;; This file is NOT part of GNU Emacs.
12 ;;
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.
17 ;;
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.
22 ;;
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/>.
25 ;;
26 ;;; Commentary:
27 ;;
28 ;; Company is a modular completion mechanism. Modules for retrieving completion
29 ;; candidates are called back-ends, modules for displaying them are front-ends.
30 ;;
31 ;; Company comes with many back-ends, e.g. `company-elisp'. These are
32 ;; distributed in individual files and can be used individually.
33 ;;
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)
38 ;;
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)
41 ;;
42 ;; If you want to start a specific back-end, call it interactively or use
43 ;; `company-begin-backend'. For example:
44 ;; M-x company-abbrev will prompt for and insert an abbrev.
45 ;;
46 ;; To write your own back-end, look at the documentation for `company-backends'.
47 ;; Here is a simple example completing "foo":
48 ;;
49 ;; (defun company-my-backend (command &optional arg &rest ignored)
50 ;; (case command
51 ;; ('prefix (when (looking-back "foo\\>")
52 ;; (match-string 0)))
53 ;; ('candidates (list "foobar" "foobaz" "foobarbaz"))
54 ;; ('meta (format "This value is named %s" arg))))
55 ;;
56 ;; Sometimes it is a good idea to mix two back-ends together, for example to
57 ;; enrich gtags with dabbrev-code results (to emulate local variables):
58 ;; To do this, add a list with the merged back-ends as an element in
59 ;; company-backends.
60 ;;
61 ;; Known Issues:
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'.
65 ;;
66 ;;; Change Log:
67 ;;
68 ;; 2009-04-25 (0.4.2)
69 ;; In C modes . and -> now count towards `company-minimum-prefix-length'.
70 ;; Reverted default front-end back to `company-preview-if-just-one-frontend'.
71 ;; The pseudo tooltip will no longer be clipped at the right window edge.
72 ;; Added `company-tooltip-minimum'.
73 ;; Windows compatibility fixes.
74 ;;
75 ;; 2009-04-19 (0.4.1)
76 ;; Added `global-company-mode'.
77 ;; Performance enhancements.
78 ;; Added `company-eclim' back-end.
79 ;; Added safer workaround for Emacs `posn-col-row' bug.
80 ;;
81 ;; 2009-04-18 (0.4)
82 ;; Automatic completion is now aborted if the prefix gets too short.
83 ;; Added option `company-dabbrev-time-limit'.
84 ;; `company-backends' now supports merging back-ends.
85 ;; Added back-end `company-dabbrev-code' for generic code.
86 ;; Fixed `company-begin-with'.
87 ;;
88 ;; 2009-04-15 (0.3.1)
89 ;; Added 'stop prefix to prevent dabbrev from completing inside of symbols.
90 ;; Fixed issues with tabbar-mode and line-spacing.
91 ;; Performance enhancements.
92 ;;
93 ;; 2009-04-12 (0.3)
94 ;; Added `company-begin-commands' option.
95 ;; Added abbrev, tempo and Xcode back-ends.
96 ;; Back-ends are now interactive. You can start them with M-x backend-name.
97 ;; Added `company-begin-with' for starting company from elisp-code.
98 ;; Added hooks.
99 ;; Added `company-require-match' and `company-auto-complete' options.
100 ;;
101 ;; 2009-04-05 (0.2.1)
102 ;; Improved Emacs Lisp back-end behavior for local variables.
103 ;; Added `company-elisp-detect-function-context' option.
104 ;; The mouse can now be used for selection.
105 ;;
106 ;; 2009-03-22 (0.2)
107 ;; Added `company-show-location'.
108 ;; Added etags back-end.
109 ;; Added work-around for end-of-buffer bug.
110 ;; Added `company-filter-candidates'.
111 ;; More local Lisp variables are now included in the candidates.
112 ;;
113 ;; 2009-03-21 (0.1.5)
114 ;; Fixed elisp documentation buffer always showing the same doc.
115 ;; Added `company-echo-strip-common-frontend'.
116 ;; Added `company-show-numbers' option and M-0 ... M-9 default bindings.
117 ;; Don't hide the echo message if it isn't shown.
118 ;;
119 ;; 2009-03-20 (0.1)
120 ;; Initial release.
121 ;;
122 ;;; Code:
123
124 (eval-when-compile (require 'cl))
125
126 (add-to-list 'debug-ignored-errors "^.* frontend cannot be used twice$")
127 (add-to-list 'debug-ignored-errors "^Echo area cannot be used twice$")
128 (add-to-list 'debug-ignored-errors "^No \\(document\\|loc\\)ation available$")
129 (add-to-list 'debug-ignored-errors "^Company not ")
130 (add-to-list 'debug-ignored-errors "^No candidate number ")
131 (add-to-list 'debug-ignored-errors "^Cannot complete at point$")
132
133 (defgroup company nil
134 "Extensible inline text completion mechanism"
135 :group 'abbrev
136 :group 'convenience
137 :group 'maching)
138
139 (defface company-tooltip
140 '((t :background "yellow"
141 :foreground "black"))
142 "*Face used for the tool tip."
143 :group 'company)
144
145 (defface company-tooltip-selection
146 '((default :inherit company-tooltip)
147 (((class color) (min-colors 88)) (:background "orange1"))
148 (t (:background "green")))
149 "*Face used for the selection in the tool tip."
150 :group 'company)
151
152 (defface company-tooltip-mouse
153 '((default :inherit highlight))
154 "*Face used for the tool tip item under the mouse."
155 :group 'company)
156
157 (defface company-tooltip-common
158 '((t :inherit company-tooltip
159 :foreground "red"))
160 "*Face used for the common completion in the tool tip."
161 :group 'company)
162
163 (defface company-tooltip-common-selection
164 '((t :inherit company-tooltip-selection
165 :foreground "red"))
166 "*Face used for the selected common completion in the tool tip."
167 :group 'company)
168
169 (defface company-preview
170 '((t :background "blue4"
171 :foreground "wheat"))
172 "*Face used for the completion preview."
173 :group 'company)
174
175 (defface company-preview-common
176 '((t :inherit company-preview
177 :foreground "red"))
178 "*Face used for the common part of the completion preview."
179 :group 'company)
180
181 (defface company-preview-search
182 '((t :inherit company-preview
183 :background "blue1"))
184 "*Face used for the search string in the completion preview."
185 :group 'company)
186
187 (defface company-echo nil
188 "*Face used for completions in the echo area."
189 :group 'company)
190
191 (defface company-echo-common
192 '((((background dark)) (:foreground "firebrick1"))
193 (((background light)) (:background "firebrick4")))
194 "*Face used for the common part of completions in the echo area."
195 :group 'company)
196
197 (defun company-frontends-set (variable value)
198 ;; uniquify
199 (let ((remainder value))
200 (setcdr remainder (delq (car remainder) (cdr remainder))))
201 (and (memq 'company-pseudo-tooltip-unless-just-one-frontend value)
202 (memq 'company-pseudo-tooltip-frontend value)
203 (error "Pseudo tooltip frontend cannot be used twice"))
204 (and (memq 'company-preview-if-just-one-frontend value)
205 (memq 'company-preview-frontend value)
206 (error "Preview frontend cannot be used twice"))
207 (and (memq 'company-echo value)
208 (memq 'company-echo-metadata-frontend value)
209 (error "Echo area cannot be used twice"))
210 ;; preview must come last
211 (dolist (f '(company-preview-if-just-one-frontend company-preview-frontend))
212 (when (memq f value)
213 (setq value (append (delq f value) (list f)))))
214 (set variable value))
215
216 (defcustom company-frontends '(company-pseudo-tooltip-unless-just-one-frontend
217 company-preview-if-just-one-frontend
218 company-echo-metadata-frontend)
219 "*The list of active front-ends (visualizations).
220 Each front-end is a function that takes one argument. It is called with
221 one of the following arguments:
222
223 'show: When the visualization should start.
224
225 'hide: When the visualization should end.
226
227 'update: When the data has been updated.
228
229 'pre-command: Before every command that is executed while the
230 visualization is active.
231
232 'post-command: After every command that is executed while the
233 visualization is active.
234
235 The visualized data is stored in `company-prefix', `company-candidates',
236 `company-common', `company-selection', `company-point' and
237 `company-search-string'."
238 :set 'company-frontends-set
239 :group 'company
240 :type '(repeat (choice (const :tag "echo" company-echo-frontend)
241 (const :tag "echo, strip common"
242 company-echo-strip-common-frontend)
243 (const :tag "show echo meta-data in echo"
244 company-echo-metadata-frontend)
245 (const :tag "pseudo tooltip"
246 company-pseudo-tooltip-frontend)
247 (const :tag "pseudo tooltip, multiple only"
248 company-pseudo-tooltip-unless-just-one-frontend)
249 (const :tag "preview" company-preview-frontend)
250 (const :tag "preview, unique only"
251 company-preview-if-just-one-frontend)
252 (function :tag "custom function" nil))))
253
254 (defcustom company-tooltip-limit 10
255 "*The maximum number of candidates in the tool tip"
256 :group 'company
257 :type 'integer)
258
259 (defcustom company-tooltip-minimum 6
260 "*The minimum height of the tool tip.
261 If this many lines are not available, prefer to display the tooltip above."
262 :group 'company
263 :type 'integer)
264
265 (defvar company-safe-backends
266 '((company-abbrev . "Abbrev")
267 (company-css . "CSS")
268 (company-dabbrev . "dabbrev for plain text")
269 (company-dabbrev-code . "dabbrev for code")
270 (company-eclim . "eclim (an Eclipse interace)")
271 (company-elisp . "Emacs Lisp")
272 (company-etags . "etags")
273 (company-files . "Files")
274 (company-gtags . "GNU Global")
275 (company-ispell . "ispell")
276 (company-keywords . "Programming language keywords")
277 (company-nxml . "nxml")
278 (company-oddmuse . "Oddmuse")
279 (company-semantic . "CEDET Semantic")
280 (company-tempo . "Tempo templates")
281 (company-xcode . "Xcode")))
282 (put 'company-safe-backends 'risky-local-variable t)
283
284 (defun company-safe-backends-p (backends)
285 (and (consp backends)
286 (not (dolist (backend backends)
287 (unless (if (consp backend)
288 (company-safe-backends-p backend)
289 (assq backend company-safe-backends))
290 (return t))))))
291
292 (defcustom company-backends '(company-elisp company-nxml company-css
293 company-eclim company-semantic company-xcode
294 (company-gtags company-etags company-dabbrev-code
295 company-keywords)
296 company-oddmuse company-files company-dabbrev)
297 "*The list of active back-ends (completion engines).
298 Each list elements can itself be a list of back-ends. In that case their
299 completions are merged. Otherwise only the first matching back-end returns
300 results.
301
302 Each back-end is a function that takes a variable number of arguments.
303 The first argument is the command requested from the back-end. It is one
304 of the following:
305
306 'prefix: The back-end should return the text to be completed. It must be
307 text immediately before `point'. Returning nil passes control to the next
308 back-end. The function should return 'stop if it should complete but cannot
309 \(e.g. if it is in the middle of a string\). If the returned value is only
310 part of the prefix (e.g. the part after \"->\" in C), the back-end may return a
311 cons of prefix and prefix length, which is then used in the
312 `company-minimum-prefix-length' test.
313
314 'candidates: The second argument is the prefix to be completed. The
315 return value should be a list of candidates that start with the prefix.
316
317 Optional commands:
318
319 'sorted: The back-end may return t here to indicate that the candidates
320 are sorted and will not need to be sorted again.
321
322 'duplicates: If non-nil, company will take care of removing duplicates
323 from the list.
324
325 'no-cache: Usually company doesn't ask for candidates again as completion
326 progresses, unless the back-end returns t for this command. The second
327 argument is the latest prefix.
328
329 'meta: The second argument is a completion candidate. The back-end should
330 return a (short) documentation string for it.
331
332 'doc-buffer: The second argument is a completion candidate. The back-end should
333 create a buffer (preferably with `company-doc-buffer'), fill it with
334 documentation and return it.
335
336 'location: The second argument is a completion candidate. The back-end can
337 return the cons of buffer and buffer location, or of file and line
338 number where the completion candidate was defined.
339
340 'require-match: If this value is t, the user is not allowed to enter anything
341 not offering as a candidate. Use with care! The default value nil gives the
342 user that choice with `company-require-match'. Return value 'never overrides
343 that option the other way around.
344
345 The back-end should return nil for all commands it does not support or
346 does not know about. It should also be callable interactively and use
347 `company-begin-backend' to start itself in that case."
348 :group 'company
349 :type `(repeat
350 (choice
351 :tag "Back-end"
352 ,@(mapcar (lambda (b) `(const :tag ,(cdr b) ,(car b)))
353 company-safe-backends)
354 (symbol :tag "User defined")
355 (repeat :tag "Merged Back-ends"
356 (choice :tag "Back-end"
357 ,@(mapcar (lambda (b)
358 `(const :tag ,(cdr b) ,(car b)))
359 company-safe-backends)
360 (symbol :tag "User defined"))))))
361
362 (put 'company-backends 'safe-local-variable 'company-safe-backends-p)
363
364 (defcustom company-completion-started-hook nil
365 "*Hook run when company starts completing.
366 The hook is called with one argument that is non-nil if the completion was
367 started manually."
368 :group 'company
369 :type 'hook)
370
371 (defcustom company-completion-cancelled-hook nil
372 "*Hook run when company cancels completing.
373 The hook is called with one argument that is non-nil if the completion was
374 aborted manually."
375 :group 'company
376 :type 'hook)
377
378 (defcustom company-completion-finished-hook nil
379 "*Hook run when company successfully completes.
380 The hook is called with the selected candidate as an argument."
381 :group 'company
382 :type 'hook)
383
384 (defcustom company-minimum-prefix-length 3
385 "*The minimum prefix length for automatic completion."
386 :group 'company
387 :type '(integer :tag "prefix length"))
388
389 (defcustom company-require-match 'company-explicit-action-p
390 "*If enabled, disallow non-matching input.
391 This can be a function do determine if a match is required.
392
393 This can be overridden by the back-end, if it returns t or 'never to
394 'require-match. `company-auto-complete' also takes precedence over this."
395 :group 'company
396 :type '(choice (const :tag "Off" nil)
397 (function :tag "Predicate function")
398 (const :tag "On, if user interaction took place"
399 'company-explicit-action-p)
400 (const :tag "On" t)))
401
402 (defcustom company-auto-complete 'company-explicit-action-p
403 "Determines when to auto-complete.
404 If this is enabled, all characters from `company-auto-complete-chars' complete
405 the selected completion. This can also be a function."
406 :group 'company
407 :type '(choice (const :tag "Off" nil)
408 (function :tag "Predicate function")
409 (const :tag "On, if user interaction took place"
410 'company-explicit-action-p)
411 (const :tag "On" t)))
412
413 (defcustom company-auto-complete-chars '(?\ ?\( ?\) ?. ?\" ?$ ?\' ?< ?| ?!)
414 "Determines which characters trigger an automatic completion.
415 See `company-auto-complete'. If this is a string, each string character causes
416 completion. If it is a list of syntax description characters (see
417 `modify-syntax-entry'), all characters with that syntax auto-complete.
418
419 This can also be a function, which is called with the new input and should
420 return non-nil if company should auto-complete.
421
422 A character that is part of a valid candidate never starts auto-completion."
423 :group 'company
424 :type '(choice (string :tag "Characters")
425 (set :tag "Syntax"
426 (const :tag "Whitespace" ?\ )
427 (const :tag "Symbol" ?_)
428 (const :tag "Opening parentheses" ?\()
429 (const :tag "Closing parentheses" ?\))
430 (const :tag "Word constituent" ?w)
431 (const :tag "Punctuation." ?.)
432 (const :tag "String quote." ?\")
433 (const :tag "Paired delimiter." ?$)
434 (const :tag "Expression quote or prefix operator." ?\')
435 (const :tag "Comment starter." ?<)
436 (const :tag "Comment ender." ?>)
437 (const :tag "Character-quote." ?/)
438 (const :tag "Generic string fence." ?|)
439 (const :tag "Generic comment fence." ?!))
440 (function :tag "Predicate function")))
441
442 (defcustom company-idle-delay .7
443 "*The idle delay in seconds until automatic completions starts.
444 A value of nil means never complete automatically, t means complete
445 immediately when a prefix of `company-minimum-prefix-length' is reached."
446 :group 'company
447 :type '(choice (const :tag "never (nil)" nil)
448 (const :tag "immediate (t)" t)
449 (number :tag "seconds")))
450
451 (defcustom company-begin-commands t
452 "*A list of commands following which company will start completing.
453 If this is t, it will complete after any command. See `company-idle-delay'.
454
455 Alternatively any command with a non-nil 'company-begin property is treated as
456 if it was on this list."
457 :group 'company
458 :type '(choice (const :tag "Any command" t)
459 (const :tag "Self insert command" '(self-insert-command))
460 (repeat :tag "Commands" function)))
461
462 (defcustom company-show-numbers nil
463 "*If enabled, show quick-access numbers for the first ten candidates."
464 :group 'company
465 :type '(choice (const :tag "off" nil)
466 (const :tag "on" t)))
467
468 (defvar company-end-of-buffer-workaround t
469 "*Work around a visualization bug when completing at the end of the buffer.
470 The work-around consists of adding a newline.")
471
472 ;;; mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
473
474 (defvar company-mode-map (make-sparse-keymap)
475 "Keymap used by `company-mode'.")
476
477 (defvar company-active-map
478 (let ((keymap (make-sparse-keymap)))
479 (define-key keymap "\e\e\e" 'company-abort)
480 (define-key keymap "\C-g" 'company-abort)
481 (define-key keymap (kbd "M-n") 'company-select-next)
482 (define-key keymap (kbd "M-p") 'company-select-previous)
483 (define-key keymap (kbd "<down>") 'company-select-next)
484 (define-key keymap (kbd "<up>") 'company-select-previous)
485 (define-key keymap [down-mouse-1] 'ignore)
486 (define-key keymap [down-mouse-3] 'ignore)
487 (define-key keymap [mouse-1] 'company-complete-mouse)
488 (define-key keymap [mouse-3] 'company-select-mouse)
489 (define-key keymap [up-mouse-1] 'ignore)
490 (define-key keymap [up-mouse-3] 'ignore)
491 (define-key keymap "\C-m" 'company-complete-selection)
492 (define-key keymap "\t" 'company-complete-common)
493 (define-key keymap (kbd "<f1>") 'company-show-doc-buffer)
494 (define-key keymap "\C-w" 'company-show-location)
495 (define-key keymap "\C-s" 'company-search-candidates)
496 (define-key keymap "\C-\M-s" 'company-filter-candidates)
497 (dotimes (i 10)
498 (define-key keymap (vector (+ (aref (kbd "M-0") 0) i))
499 `(lambda () (interactive) (company-complete-number ,i))))
500
501 keymap)
502 "Keymap that is enabled during an active completion.")
503
504 (defvar company--disabled-backends nil)
505
506 (defun company-init-backend (backend)
507 (and (symbolp backend)
508 (not (fboundp backend))
509 (ignore-errors (require backend nil t)))
510
511 (if (or (symbolp backend)
512 (functionp backend))
513 (if (ignore-errors (funcall backend 'init) t)
514 (put backend 'company-init t)
515 (put backend 'company-init 'failed)
516 (unless (memq backend company--disabled-backends)
517 (message "Company back-end '%s' could not be initialized"
518 backend)
519 (push backend company--disabled-backends))
520 nil)
521 (mapc 'company-init-backend backend)))
522
523 (defvar company-default-lighter " company")
524
525 (defvar company-lighter company-default-lighter)
526 (make-variable-buffer-local 'company-lighter)
527
528 ;;;###autoload
529 (define-minor-mode company-mode
530 "\"complete anything\"; in in-buffer completion framework.
531 Completion starts automatically, depending on the values
532 `company-idle-delay' and `company-minimum-prefix-length'.
533
534 Completion can be controlled with the commands:
535 `company-complete-common', `company-complete-selection', `company-complete',
536 `company-select-next', `company-select-previous'. If these commands are
537 called before `company-idle-delay', completion will also start.
538
539 Completions can be searched with `company-search-candidates' or
540 `company-filter-candidates'. These can be used while completion is
541 inactive, as well.
542
543 The completion data is retrieved using `company-backends' and displayed using
544 `company-frontends'. If you want to start a specific back-end, call it
545 interactively or use `company-begin-backend'.
546
547 regular keymap (`company-mode-map'):
548
549 \\{company-mode-map}
550 keymap during active completions (`company-active-map'):
551
552 \\{company-active-map}"
553 nil company-lighter company-mode-map
554 (if company-mode
555 (progn
556 (add-hook 'pre-command-hook 'company-pre-command nil t)
557 (add-hook 'post-command-hook 'company-post-command nil t)
558 (mapc 'company-init-backend company-backends))
559 (remove-hook 'pre-command-hook 'company-pre-command t)
560 (remove-hook 'post-command-hook 'company-post-command t)
561 (company-cancel)
562 (kill-local-variable 'company-point)))
563
564 (define-globalized-minor-mode global-company-mode company-mode
565 (lambda () (company-mode 1)))
566
567 (defsubst company-assert-enabled ()
568 (unless company-mode
569 (company-uninstall-map)
570 (error "Company not enabled")))
571
572 ;;; keymaps ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
573
574 (defvar company-overriding-keymap-bound nil)
575 (make-variable-buffer-local 'company-overriding-keymap-bound)
576
577 (defvar company-old-keymap nil)
578 (make-variable-buffer-local 'company-old-keymap)
579
580 (defvar company-my-keymap nil)
581 (make-variable-buffer-local 'company-my-keymap)
582
583 (defsubst company-enable-overriding-keymap (keymap)
584 (setq company-my-keymap keymap)
585 (when company-overriding-keymap-bound
586 (company-uninstall-map)))
587
588 (defun company-install-map ()
589 (unless (or company-overriding-keymap-bound
590 (null company-my-keymap))
591 (setq company-old-keymap overriding-terminal-local-map
592 overriding-terminal-local-map company-my-keymap
593 company-overriding-keymap-bound t)))
594
595 (defun company-uninstall-map ()
596 (when (eq overriding-terminal-local-map company-my-keymap)
597 (setq overriding-terminal-local-map company-old-keymap
598 company-overriding-keymap-bound nil)))
599
600 ;; Hack:
601 ;; Emacs calculates the active keymaps before reading the event. That means we
602 ;; cannot change the keymap from a timer. So we send a bogus command.
603 (defun company-ignore ()
604 (interactive)
605 (setq this-command last-command))
606
607 (global-set-key '[31415926] 'company-ignore)
608
609 (defun company-input-noop ()
610 (push 31415926 unread-command-events))
611
612 ;; Hack:
613 ;; posn-col-row is incorrect in older Emacsen when line-spacing is set
614 (defun company--col-row (&optional pos)
615 (let ((posn (posn-at-point pos)))
616 (cons (car (posn-col-row posn)) (cdr (posn-actual-col-row posn)))))
617
618 (defsubst company--column (&optional pos)
619 (car (posn-col-row (posn-at-point pos))))
620
621 (defsubst company--row (&optional pos)
622 (cdr (posn-actual-col-row (posn-at-point pos))))
623
624 ;;; backends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
625
626 (defun company-grab (regexp &optional expression limit)
627 (when (looking-back regexp limit)
628 (or (match-string-no-properties (or expression 0)) "")))
629
630 (defun company-grab-line (regexp &optional expression)
631 (company-grab regexp expression (point-at-bol)))
632
633 (defun company-grab-symbol ()
634 (if (looking-at "\\_>")
635 (buffer-substring (point) (save-excursion (skip-syntax-backward "w_")
636 (point)))
637 (unless (and (char-after) (memq (char-syntax (char-after)) '(?w ?_)))
638 "")))
639
640 (defun company-grab-word ()
641 (if (looking-at "\\>")
642 (buffer-substring (point) (save-excursion (skip-syntax-backward "w")
643 (point)))
644 (unless (and (char-after) (eq (char-syntax (char-after)) ?w))
645 "")))
646
647 (defun company-in-string-or-comment ()
648 (let ((ppss (syntax-ppss)))
649 (or (car (setq ppss (nthcdr 3 ppss)))
650 (car (setq ppss (cdr ppss)))
651 (nth 3 ppss))))
652
653 (if (fboundp 'locate-dominating-file)
654 (defalias 'company-locate-dominating-file 'locate-dominating-file)
655 (defun company-locate-dominating-file (file name)
656 (catch 'root
657 (let ((dir (file-name-directory file))
658 (prev-dir nil))
659 (while (not (equal dir prev-dir))
660 (when (file-exists-p (expand-file-name name dir))
661 (throw 'root dir))
662 (setq prev-dir dir
663 dir (file-name-directory (directory-file-name dir))))))))
664
665 (defun company-call-backend (&rest args)
666 (if (functionp company-backend)
667 (apply company-backend args)
668 (apply 'company--multi-backend-adapter company-backend args)))
669
670 (defun company--multi-backend-adapter (backends command &rest args)
671 (case command
672 ('candidates
673 (apply 'append (mapcar (lambda (backend) (apply backend command args))
674 backends)))
675 ('sorted nil)
676 ('duplicates t)
677 (otherwise
678 (let (value)
679 (dolist (backend backends)
680 (when (setq value (apply backend command args))
681 (return value)))))))
682
683 ;;; completion mechanism ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
684
685 (defvar company-backend nil)
686 (make-variable-buffer-local 'company-backend)
687
688 (defvar company-prefix nil)
689 (make-variable-buffer-local 'company-prefix)
690
691 (defvar company-candidates nil)
692 (make-variable-buffer-local 'company-candidates)
693
694 (defvar company-candidates-length nil)
695 (make-variable-buffer-local 'company-candidates-length)
696
697 (defvar company-candidates-cache nil)
698 (make-variable-buffer-local 'company-candidates-cache)
699
700 (defvar company-candidates-predicate nil)
701 (make-variable-buffer-local 'company-candidates-predicate)
702
703 (defvar company-common nil)
704 (make-variable-buffer-local 'company-common)
705
706 (defvar company-selection 0)
707 (make-variable-buffer-local 'company-selection)
708
709 (defvar company-selection-changed nil)
710 (make-variable-buffer-local 'company-selection-changed)
711
712 (defvar company--explicit-action nil
713 "Non-nil, if explicit completion took place.")
714 (make-variable-buffer-local 'company--explicit-action)
715
716 (defvar company--point-max nil)
717 (make-variable-buffer-local 'company--point-max)
718
719 (defvar company-point nil)
720 (make-variable-buffer-local 'company-point)
721
722 (defvar company-timer nil)
723
724 (defvar company-added-newline nil)
725 (make-variable-buffer-local 'company-added-newline)
726
727 (defsubst company-strip-prefix (str)
728 (substring str (length company-prefix)))
729
730 (defun company-explicit-action-p ()
731 "Return whether explicit completion action was taken by the user."
732 (or company--explicit-action
733 company-selection-changed))
734
735 (defsubst company-reformat (candidate)
736 ;; company-ispell needs this, because the results are always lower-case
737 ;; It's mory efficient to fix it only when they are displayed.
738 (concat company-prefix (substring candidate (length company-prefix))))
739
740 (defun company--should-complete ()
741 (and (not (or buffer-read-only overriding-terminal-local-map
742 overriding-local-map))
743 (eq company-idle-delay t)
744 (or (eq t company-begin-commands)
745 (memq this-command company-begin-commands)
746 (and (symbolp this-command) (get this-command 'company-begin)))
747 (not (and transient-mark-mode mark-active))))
748
749 (defsubst company-call-frontends (command)
750 (dolist (frontend company-frontends)
751 (condition-case err
752 (funcall frontend command)
753 (error (error "Company: Front-end %s error \"%s\" on command %s"
754 frontend (error-message-string err) command)))))
755
756 (defsubst company-set-selection (selection &optional force-update)
757 (setq selection (max 0 (min (1- company-candidates-length) selection)))
758 (when (or force-update (not (equal selection company-selection)))
759 (setq company-selection selection
760 company-selection-changed t)
761 (company-call-frontends 'update)))
762
763 (defun company-apply-predicate (candidates predicate)
764 (let (new)
765 (dolist (c candidates)
766 (when (funcall predicate c)
767 (push c new)))
768 (nreverse new)))
769
770 (defun company-update-candidates (candidates)
771 (setq company-candidates-length (length candidates))
772 (if (> company-selection 0)
773 ;; Try to restore the selection
774 (let ((selected (nth company-selection company-candidates)))
775 (setq company-selection 0
776 company-candidates candidates)
777 (when selected
778 (while (and candidates (string< (pop candidates) selected))
779 (incf company-selection))
780 (unless candidates
781 ;; Make sure selection isn't out of bounds.
782 (setq company-selection (min (1- company-candidates-length)
783 company-selection)))))
784 (setq company-selection 0
785 company-candidates candidates))
786 ;; Save in cache:
787 (push (cons company-prefix company-candidates) company-candidates-cache)
788 ;; Calculate common.
789 (let ((completion-ignore-case (company-call-backend 'ignore-case)))
790 (setq company-common (try-completion company-prefix company-candidates)))
791 (when (eq company-common t)
792 (setq company-candidates nil)))
793
794 (defun company-calculate-candidates (prefix)
795 (let ((candidates (cdr (assoc prefix company-candidates-cache))))
796 (or candidates
797 (when company-candidates-cache
798 (let ((len (length prefix))
799 (completion-ignore-case (company-call-backend 'ignore-case))
800 prev)
801 (dotimes (i (1+ len))
802 (when (setq prev (cdr (assoc (substring prefix 0 (- len i))
803 company-candidates-cache)))
804 (setq candidates (all-completions prefix prev))
805 (return t)))))
806 ;; no cache match, call back-end
807 (progn
808 (setq candidates (company-call-backend 'candidates prefix))
809 (when company-candidates-predicate
810 (setq candidates
811 (company-apply-predicate candidates
812 company-candidates-predicate)))
813 (unless (company-call-backend 'sorted)
814 (setq candidates (sort candidates 'string<)))
815 (when (company-call-backend 'duplicates)
816 ;; strip duplicates
817 (let ((c2 candidates))
818 (while c2
819 (setcdr c2 (progn (while (equal (pop c2) (car c2)))
820 c2)))))))
821 (if (or (cdr candidates)
822 (not (equal (car candidates) prefix)))
823 ;; Don't start when already completed and unique.
824 candidates
825 ;; Not the right place? maybe when setting?
826 (and company-candidates t))))
827
828 (defun company-idle-begin (buf win tick pos)
829 (and company-mode
830 (eq buf (current-buffer))
831 (eq win (selected-window))
832 (eq tick (buffer-chars-modified-tick))
833 (eq pos (point))
834 (not company-candidates)
835 (not (equal (point) company-point))
836 (let ((company-idle-delay t)
837 (company-begin-commands t))
838 (company-begin)
839 (when company-candidates
840 (company-input-noop)
841 (company-post-command)))))
842
843 (defun company-auto-begin ()
844 (company-assert-enabled)
845 (and company-mode
846 (not company-candidates)
847 (let ((company-idle-delay t)
848 (company-minimum-prefix-length 0)
849 (company-begin-commands t))
850 (company-begin)))
851 ;; Return non-nil if active.
852 company-candidates)
853
854 (defun company-manual-begin ()
855 (interactive)
856 (setq company--explicit-action t)
857 (company-auto-begin))
858
859 (defun company-require-match-p ()
860 (let ((backend-value (company-call-backend 'require-match)))
861 (or (eq backend-value t)
862 (and (if (functionp company-require-match)
863 (funcall company-require-match)
864 (eq company-require-match t))
865 (not (eq backend-value 'never))))))
866
867 (defun company-punctuation-p (input)
868 "Return non-nil, if input starts with punctuation or parentheses."
869 (memq (char-syntax (string-to-char input)) '(?. ?\( ?\))))
870
871 (defun company-auto-complete-p (input)
872 "Return non-nil, if input starts with punctuation or parentheses."
873 (and (if (functionp company-auto-complete)
874 (funcall company-auto-complete)
875 company-auto-complete)
876 (if (functionp company-auto-complete-chars)
877 (funcall company-auto-complete-chars input)
878 (if (consp company-auto-complete-chars)
879 (memq (char-syntax (string-to-char input))
880 company-auto-complete-chars)
881 (string-match (substring input 0 1) company-auto-complete-chars)))))
882
883 (defun company--incremental-p ()
884 (and (> (point) company-point)
885 (> (point-max) company--point-max)
886 (not (eq this-command 'backward-delete-char-untabify))
887 (equal (buffer-substring (- company-point (length company-prefix))
888 company-point)
889 company-prefix)))
890
891 (defsubst company--string-incremental-p (old-prefix new-prefix)
892 (and (> (length new-prefix) (length old-prefix))
893 (equal old-prefix (substring new-prefix 0 (length old-prefix)))))
894
895 (defun company--continue-failed (new-prefix)
896 (when (company--incremental-p)
897 (let ((input (buffer-substring-no-properties (point) company-point)))
898 (cond
899 ((company-auto-complete-p input)
900 ;; auto-complete
901 (save-excursion
902 (goto-char company-point)
903 (company-complete-selection)
904 nil))
905 ((and (company--string-incremental-p company-prefix new-prefix)
906 (company-require-match-p))
907 ;; wrong incremental input, but required match
908 (backward-delete-char (length input))
909 (ding)
910 (message "Matching input is required")
911 company-candidates)
912 ((equal company-prefix (car company-candidates))
913 ;; last input was actually success
914 (company-cancel company-prefix)
915 nil)))))
916
917 (defun company--good-prefix-p (prefix)
918 (and (or (company-explicit-action-p)
919 (>= (or (cdr-safe prefix) (length prefix))
920 company-minimum-prefix-length))
921 (stringp (or (car-safe prefix) prefix))))
922
923 (defun company--continue ()
924 (when (company-call-backend 'no-cache company-prefix)
925 ;; Don't complete existing candidates, fetch new ones.
926 (setq company-candidates-cache nil))
927 (let* ((new-prefix (company-call-backend 'prefix))
928 (c (when (and (company--good-prefix-p new-prefix)
929 (setq new-prefix (or (car-safe new-prefix) new-prefix))
930 (= (- (point) (length new-prefix))
931 (- company-point (length company-prefix))))
932 (setq new-prefix (or (car-safe new-prefix) new-prefix))
933 (company-calculate-candidates new-prefix))))
934 (or (cond
935 ((eq c t)
936 ;; t means complete/unique.
937 (company-cancel new-prefix)
938 nil)
939 ((consp c)
940 ;; incremental match
941 (setq company-prefix new-prefix)
942 (company-update-candidates c)
943 c)
944 (t (company--continue-failed new-prefix)))
945 (company-cancel))))
946
947 (defun company--begin-new ()
948 (let (prefix c)
949 (dolist (backend (if company-backend
950 ;; prefer manual override
951 (list company-backend)
952 company-backends))
953 (setq prefix
954 (if (or (symbolp backend)
955 (functionp backend))
956 (when (or (not (symbolp backend))
957 (eq t (get backend 'company-init))
958 (unless (get backend 'company-init)
959 (company-init-backend backend)))
960 (funcall backend 'prefix))
961 (company--multi-backend-adapter backend 'prefix)))
962 (when prefix
963 (when (company--good-prefix-p prefix)
964 (setq prefix (or (car-safe prefix) prefix)
965 company-backend backend
966 c (company-calculate-candidates prefix))
967 ;; t means complete/unique. We don't start, so no hooks.
968 (when (consp c)
969 (setq company-prefix prefix)
970 (when (symbolp backend)
971 (setq company-lighter (concat " " (symbol-name backend))))
972 (company-update-candidates c)
973 (run-hook-with-args 'company-completion-started-hook
974 (company-explicit-action-p))
975 (company-call-frontends 'show)))
976 (return c)))))
977
978 (defun company-begin ()
979 (setq company-candidates
980 (or (and company-candidates (company--continue))
981 (and (company--should-complete) (company--begin-new))))
982 (when company-candidates
983 (when (and company-end-of-buffer-workaround (eobp))
984 (save-excursion (insert "\n"))
985 (setq company-added-newline (buffer-chars-modified-tick)))
986 (setq company-point (point)
987 company--point-max (point-max))
988 (company-enable-overriding-keymap company-active-map)
989 (company-call-frontends 'update)))
990
991 (defun company-cancel (&optional result)
992 (and company-added-newline
993 (> (point-max) (point-min))
994 (let ((tick (buffer-chars-modified-tick)))
995 (delete-region (1- (point-max)) (point-max))
996 (equal tick company-added-newline))
997 ;; Only set unmodified when tick remained the same since insert.
998 (set-buffer-modified-p nil))
999 (when company-prefix
1000 (if (stringp result)
1001 (run-hook-with-args 'company-completion-finished-hook result)
1002 (run-hook-with-args 'company-completion-cancelled-hook result)))
1003 (setq company-added-newline nil
1004 company-backend nil
1005 company-prefix nil
1006 company-candidates nil
1007 company-candidates-length nil
1008 company-candidates-cache nil
1009 company-candidates-predicate nil
1010 company-common nil
1011 company-selection 0
1012 company-selection-changed nil
1013 company--explicit-action nil
1014 company-lighter company-default-lighter
1015 company--point-max nil
1016 company-point nil)
1017 (when company-timer
1018 (cancel-timer company-timer))
1019 (company-search-mode 0)
1020 (company-call-frontends 'hide)
1021 (company-enable-overriding-keymap nil))
1022
1023 (defun company-abort ()
1024 (interactive)
1025 (company-cancel t)
1026 ;; Don't start again, unless started manually.
1027 (setq company-point (point)))
1028
1029 (defun company-finish (result)
1030 (insert (company-strip-prefix result))
1031 (company-cancel result)
1032 ;; Don't start again, unless started manually.
1033 (setq company-point (point)))
1034
1035 (defsubst company-keep (command)
1036 (and (symbolp command) (get command 'company-keep)))
1037
1038 (defun company-pre-command ()
1039 (unless (company-keep this-command)
1040 (condition-case err
1041 (when company-candidates
1042 (company-call-frontends 'pre-command))
1043 (error (message "Company: An error occurred in pre-command")
1044 (message "%s" (error-message-string err))
1045 (company-cancel))))
1046 (when company-timer
1047 (cancel-timer company-timer)
1048 (setq company-timer nil))
1049 (company-uninstall-map))
1050
1051 (defun company-post-command ()
1052 (unless (company-keep this-command)
1053 (condition-case err
1054 (progn
1055 (unless (equal (point) company-point)
1056 (company-begin))
1057 (if company-candidates
1058 (company-call-frontends 'post-command)
1059 (and (numberp company-idle-delay)
1060 (or (eq t company-begin-commands)
1061 (memq this-command company-begin-commands))
1062 (setq company-timer
1063 (run-with-timer company-idle-delay nil
1064 'company-idle-begin
1065 (current-buffer) (selected-window)
1066 (buffer-chars-modified-tick) (point))))))
1067 (error (message "Company: An error occurred in post-command")
1068 (message "%s" (error-message-string err))
1069 (company-cancel))))
1070 (company-install-map))
1071
1072 ;;; search ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1073
1074 (defvar company-search-string nil)
1075 (make-variable-buffer-local 'company-search-string)
1076
1077 (defvar company-search-lighter " Search: \"\"")
1078 (make-variable-buffer-local 'company-search-lighter)
1079
1080 (defvar company-search-old-map nil)
1081 (make-variable-buffer-local 'company-search-old-map)
1082
1083 (defvar company-search-old-selection 0)
1084 (make-variable-buffer-local 'company-search-old-selection)
1085
1086 (defun company-search (text lines)
1087 (let ((quoted (regexp-quote text))
1088 (i 0))
1089 (dolist (line lines)
1090 (when (string-match quoted line (length company-prefix))
1091 (return i))
1092 (incf i))))
1093
1094 (defun company-search-printing-char ()
1095 (interactive)
1096 (company-search-assert-enabled)
1097 (setq company-search-string
1098 (concat (or company-search-string "") (string last-command-event))
1099 company-search-lighter (concat " Search: \"" company-search-string
1100 "\""))
1101 (let ((pos (company-search company-search-string
1102 (nthcdr company-selection company-candidates))))
1103 (if (null pos)
1104 (ding)
1105 (company-set-selection (+ company-selection pos) t))))
1106
1107 (defun company-search-repeat-forward ()
1108 "Repeat the incremental search in completion candidates forward."
1109 (interactive)
1110 (company-search-assert-enabled)
1111 (let ((pos (company-search company-search-string
1112 (cdr (nthcdr company-selection
1113 company-candidates)))))
1114 (if (null pos)
1115 (ding)
1116 (company-set-selection (+ company-selection pos 1) t))))
1117
1118 (defun company-search-repeat-backward ()
1119 "Repeat the incremental search in completion candidates backwards."
1120 (interactive)
1121 (company-search-assert-enabled)
1122 (let ((pos (company-search company-search-string
1123 (nthcdr (- company-candidates-length
1124 company-selection)
1125 (reverse company-candidates)))))
1126 (if (null pos)
1127 (ding)
1128 (company-set-selection (- company-selection pos 1) t))))
1129
1130 (defun company-create-match-predicate ()
1131 (setq company-candidates-predicate
1132 `(lambda (candidate)
1133 ,(if company-candidates-predicate
1134 `(and (string-match ,company-search-string candidate)
1135 (funcall ,company-candidates-predicate
1136 candidate))
1137 `(string-match ,company-search-string candidate))))
1138 (company-update-candidates
1139 (company-apply-predicate company-candidates company-candidates-predicate))
1140 ;; Invalidate cache.
1141 (setq company-candidates-cache (cons company-prefix company-candidates)))
1142
1143 (defun company-filter-printing-char ()
1144 (interactive)
1145 (company-search-assert-enabled)
1146 (company-search-printing-char)
1147 (company-create-match-predicate)
1148 (company-call-frontends 'update))
1149
1150 (defun company-search-kill-others ()
1151 "Limit the completion candidates to the ones matching the search string."
1152 (interactive)
1153 (company-search-assert-enabled)
1154 (company-create-match-predicate)
1155 (company-search-mode 0)
1156 (company-call-frontends 'update))
1157
1158 (defun company-search-abort ()
1159 "Abort searching the completion candidates."
1160 (interactive)
1161 (company-search-assert-enabled)
1162 (company-set-selection company-search-old-selection t)
1163 (company-search-mode 0))
1164
1165 (defun company-search-other-char ()
1166 (interactive)
1167 (company-search-assert-enabled)
1168 (company-search-mode 0)
1169 (when last-input-event
1170 (clear-this-command-keys t)
1171 (setq unread-command-events (list last-input-event))))
1172
1173 (defvar company-search-map
1174 (let ((i 0)
1175 (keymap (make-keymap)))
1176 (if (fboundp 'max-char)
1177 (set-char-table-range (nth 1 keymap) (cons #x100 (max-char))
1178 'company-search-printing-char)
1179 (with-no-warnings
1180 ;; obselete in Emacs 23
1181 (let ((l (generic-character-list))
1182 (table (nth 1 keymap)))
1183 (while l
1184 (set-char-table-default table (car l) 'company-search-printing-char)
1185 (setq l (cdr l))))))
1186 (define-key keymap [t] 'company-search-other-char)
1187 (while (< i ?\s)
1188 (define-key keymap (make-string 1 i) 'company-search-other-char)
1189 (incf i))
1190 (while (< i 256)
1191 (define-key keymap (vector i) 'company-search-printing-char)
1192 (incf i))
1193 (let ((meta-map (make-sparse-keymap)))
1194 (define-key keymap (char-to-string meta-prefix-char) meta-map)
1195 (define-key keymap [escape] meta-map))
1196 (define-key keymap (vector meta-prefix-char t) 'company-search-other-char)
1197 (define-key keymap "\e\e\e" 'company-search-other-char)
1198 (define-key keymap [escape escape escape] 'company-search-other-char)
1199
1200 (define-key keymap "\C-g" 'company-search-abort)
1201 (define-key keymap "\C-s" 'company-search-repeat-forward)
1202 (define-key keymap "\C-r" 'company-search-repeat-backward)
1203 (define-key keymap "\C-o" 'company-search-kill-others)
1204 keymap)
1205 "Keymap used for incrementally searching the completion candidates.")
1206
1207 (define-minor-mode company-search-mode
1208 "Search mode for completion candidates.
1209 Don't start this directly, use `company-search-candidates' or
1210 `company-filter-candidates'."
1211 nil company-search-lighter nil
1212 (if company-search-mode
1213 (if (company-manual-begin)
1214 (progn
1215 (setq company-search-old-selection company-selection)
1216 (company-call-frontends 'update))
1217 (setq company-search-mode nil))
1218 (kill-local-variable 'company-search-string)
1219 (kill-local-variable 'company-search-lighter)
1220 (kill-local-variable 'company-search-old-selection)
1221 (company-enable-overriding-keymap company-active-map)))
1222
1223 (defsubst company-search-assert-enabled ()
1224 (company-assert-enabled)
1225 (unless company-search-mode
1226 (company-uninstall-map)
1227 (error "Company not in search mode")))
1228
1229 (defun company-search-candidates ()
1230 "Start searching the completion candidates incrementally.
1231
1232 \\<company-search-map>Search can be controlled with the commands:
1233 - `company-search-repeat-forward' (\\[company-search-repeat-forward])
1234 - `company-search-repeat-backward' (\\[company-search-repeat-backward])
1235 - `company-search-abort' (\\[company-search-abort])
1236
1237 Regular characters are appended to the search string.
1238
1239 The command `company-search-kill-others' (\\[company-search-kill-others]) uses
1240 the search string to limit the completion candidates."
1241 (interactive)
1242 (company-search-mode 1)
1243 (company-enable-overriding-keymap company-search-map))
1244
1245 (defvar company-filter-map
1246 (let ((keymap (make-keymap)))
1247 (define-key keymap [remap company-search-printing-char]
1248 'company-filter-printing-char)
1249 (set-keymap-parent keymap company-search-map)
1250 keymap)
1251 "Keymap used for incrementally searching the completion candidates.")
1252
1253 (defun company-filter-candidates ()
1254 "Start filtering the completion candidates incrementally.
1255 This works the same way as `company-search-candidates' immediately
1256 followed by `company-search-kill-others' after each input."
1257 (interactive)
1258 (company-search-mode 1)
1259 (company-enable-overriding-keymap company-filter-map))
1260
1261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1262
1263 (defun company-select-next ()
1264 "Select the next candidate in the list."
1265 (interactive)
1266 (when (company-manual-begin)
1267 (company-set-selection (1+ company-selection))))
1268
1269 (defun company-select-previous ()
1270 "Select the previous candidate in the list."
1271 (interactive)
1272 (when (company-manual-begin)
1273 (company-set-selection (1- company-selection))))
1274
1275 (defun company-select-mouse (event)
1276 "Select the candidate picked by the mouse."
1277 (interactive "e")
1278 (when (nth 4 (event-start event))
1279 (company-set-selection (- (cdr (posn-actual-col-row (event-start event)))
1280 (company--row)
1281 1))
1282 t))
1283
1284 (defun company-complete-mouse (event)
1285 "Complete the candidate picked by the mouse."
1286 (interactive "e")
1287 (when (company-select-mouse event)
1288 (company-complete-selection)))
1289
1290 (defun company-complete-selection ()
1291 "Complete the selected candidate."
1292 (interactive)
1293 (when (company-manual-begin)
1294 (company-finish (nth company-selection company-candidates))))
1295
1296 (defun company-complete-common ()
1297 "Complete the common part of all candidates."
1298 (interactive)
1299 (when (company-manual-begin)
1300 (if (and (not (cdr company-candidates))
1301 (equal company-common (car company-candidates)))
1302 (company-complete-selection)
1303 (insert (company-strip-prefix company-common)))))
1304
1305 (defun company-complete ()
1306 "Complete the common part of all candidates or the current selection.
1307 The first time this is called, the common part is completed, the second time, or
1308 when the selection has been changed, the selected candidate is completed."
1309 (interactive)
1310 (when (company-manual-begin)
1311 (if (or company-selection-changed
1312 (eq last-command 'company-complete-common))
1313 (call-interactively 'company-complete-selection)
1314 (call-interactively 'company-complete-common)
1315 (setq this-command 'company-complete-common))))
1316
1317 (defun company-complete-number (n)
1318 "Complete the Nth candidate.
1319 To show the number next to the candidates in some back-ends, enable
1320 `company-show-numbers'."
1321 (when (company-manual-begin)
1322 (and (< n 1) (> n company-candidates-length)
1323 (error "No candidate number %d" n))
1324 (decf n)
1325 (company-finish (nth n company-candidates))))
1326
1327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1328
1329 (defconst company-space-strings-limit 100)
1330
1331 (defconst company-space-strings
1332 (let (lst)
1333 (dotimes (i company-space-strings-limit)
1334 (push (make-string (- company-space-strings-limit 1 i) ?\ ) lst))
1335 (apply 'vector lst)))
1336
1337 (defsubst company-space-string (len)
1338 (if (< len company-space-strings-limit)
1339 (aref company-space-strings len)
1340 (make-string len ?\ )))
1341
1342 (defsubst company-safe-substring (str from &optional to)
1343 (let ((len (length str)))
1344 (if (> from len)
1345 ""
1346 (if (and to (> to len))
1347 (concat (substring str from)
1348 (company-space-string (- to len)))
1349 (substring str from to)))))
1350
1351 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1352
1353 (defvar company-last-metadata nil)
1354 (make-variable-buffer-local 'company-last-metadata)
1355
1356 (defun company-fetch-metadata ()
1357 (let ((selected (nth company-selection company-candidates)))
1358 (unless (equal selected (car company-last-metadata))
1359 (setq company-last-metadata
1360 (cons selected (company-call-backend 'meta selected))))
1361 (cdr company-last-metadata)))
1362
1363 (defun company-doc-buffer (&optional string)
1364 (with-current-buffer (get-buffer-create "*Company meta-data*")
1365 (erase-buffer)
1366 (current-buffer)))
1367
1368 (defmacro company--electric-do (&rest body)
1369 (declare (indent 0) (debug t))
1370 `(when (company-manual-begin)
1371 (save-window-excursion
1372 (let ((height (window-height))
1373 (row (company--row)))
1374 ,@body
1375 (and (< (window-height) height)
1376 (< (- (window-height) row 2) company-tooltip-limit)
1377 (recenter (- (window-height) row 2)))
1378 (while (eq 'scroll-other-window
1379 (key-binding (vector (list (read-event)))))
1380 (call-interactively 'scroll-other-window))
1381 (when last-input-event
1382 (clear-this-command-keys t)
1383 (setq unread-command-events (list last-input-event)))))))
1384
1385 (defun company-show-doc-buffer ()
1386 "Temporarily show a buffer with the complete documentation for the selection."
1387 (interactive)
1388 (company--electric-do
1389 (let ((selected (nth company-selection company-candidates)))
1390 (display-buffer (or (company-call-backend 'doc-buffer selected)
1391 (error "No documentation available")) t))))
1392 (put 'company-show-doc-buffer 'company-keep t)
1393
1394 (defun company-show-location ()
1395 "Temporarily display a buffer showing the selected candidate in context."
1396 (interactive)
1397 (company--electric-do
1398 (let* ((selected (nth company-selection company-candidates))
1399 (location (company-call-backend 'location selected))
1400 (pos (or (cdr location) (error "No location available")))
1401 (buffer (or (and (bufferp (car location)) (car location))
1402 (find-file-noselect (car location) t))))
1403 (with-selected-window (display-buffer buffer t)
1404 (if (bufferp (car location))
1405 (goto-char pos)
1406 (goto-line pos))
1407 (set-window-start nil (point))))))
1408 (put 'company-show-location 'company-keep t)
1409
1410 ;;; package functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1411
1412 (defvar company-callback nil)
1413 (make-variable-buffer-local 'company-callback)
1414
1415 (defvar company-begin-with-marker nil)
1416 (make-variable-buffer-local 'company-begin-with-marker)
1417
1418 (defun company-remove-callback (&optional ignored)
1419 (remove-hook 'company-completion-finished-hook company-callback t)
1420 (remove-hook 'company-completion-cancelled-hook 'company-remove-callback t)
1421 (remove-hook 'company-completion-finished-hook 'company-remove-callback t)
1422 (when company-begin-with-marker
1423 (set-marker company-begin-with-marker nil)))
1424
1425 (defun company-begin-backend (backend &optional callback)
1426 "Start a completion at point using BACKEND."
1427 (interactive (let ((val (completing-read "Company back-end: "
1428 obarray
1429 'functionp nil "company-")))
1430 (when val
1431 (list (intern val)))))
1432 (when (setq company-callback callback)
1433 (add-hook 'company-completion-finished-hook company-callback nil t))
1434 (add-hook 'company-completion-cancelled-hook 'company-remove-callback nil t)
1435 (add-hook 'company-completion-finished-hook 'company-remove-callback nil t)
1436 (setq company-backend backend)
1437 ;; Return non-nil if active.
1438 (or (company-manual-begin)
1439 (error "Cannot complete at point")))
1440
1441 (defun company-begin-with (candidates
1442 &optional prefix-length require-match callback)
1443 "Start a completion at point.
1444 CANDIDATES is the list of candidates to use and PREFIX-LENGTH is the length of
1445 the prefix that already is in the buffer before point. It defaults to 0.
1446
1447 CALLBACK is a function called with the selected result if the user successfully
1448 completes the input.
1449
1450 Example:
1451 \(company-begin-with '\(\"foo\" \"foobar\" \"foobarbaz\"\)\)"
1452 (setq company-begin-with-marker (copy-marker (point) t))
1453 (company-begin-backend
1454 `(lambda (command &optional arg &rest ignored)
1455 (cond
1456 ((eq command 'prefix)
1457 (when (equal (point) (marker-position company-begin-with-marker))
1458 (buffer-substring ,(- (point) (or prefix-length 0)) (point))))
1459 ((eq command 'candidates)
1460 (all-completions arg ',candidates))
1461 ((eq command 'require-match)
1462 ,require-match)))
1463 callback))
1464
1465 ;;; pseudo-tooltip ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1466
1467 (defvar company-pseudo-tooltip-overlay nil)
1468 (make-variable-buffer-local 'company-pseudo-tooltip-overlay)
1469
1470 (defvar company-tooltip-offset 0)
1471 (make-variable-buffer-local 'company-tooltip-offset)
1472
1473 (defun company-pseudo-tooltip-update-offset (selection num-lines limit)
1474
1475 (decf limit 2)
1476 (setq company-tooltip-offset
1477 (max (min selection company-tooltip-offset)
1478 (- selection -1 limit)))
1479
1480 (when (<= company-tooltip-offset 1)
1481 (incf limit)
1482 (setq company-tooltip-offset 0))
1483
1484 (when (>= company-tooltip-offset (- num-lines limit 1))
1485 (incf limit)
1486 (when (= selection (1- num-lines))
1487 (decf company-tooltip-offset)
1488 (when (<= company-tooltip-offset 1)
1489 (setq company-tooltip-offset 0)
1490 (incf limit))))
1491
1492 limit)
1493
1494 ;;; propertize
1495
1496 (defsubst company-round-tab (arg)
1497 (* (/ (+ arg tab-width) tab-width) tab-width))
1498
1499 (defun company-untabify (str)
1500 (let* ((pieces (split-string str "\t"))
1501 (copy pieces))
1502 (while (cdr copy)
1503 (setcar copy (company-safe-substring
1504 (car copy) 0 (company-round-tab (string-width (car copy)))))
1505 (pop copy))
1506 (apply 'concat pieces)))
1507
1508 (defun company-fill-propertize (line width selected)
1509 (setq line (company-safe-substring line 0 width))
1510 (add-text-properties 0 width '(face company-tooltip
1511 mouse-face company-tooltip-mouse)
1512 line)
1513 (add-text-properties 0 (length company-common)
1514 '(face company-tooltip-common
1515 mouse-face company-tooltip-mouse)
1516 line)
1517 (when selected
1518 (if (and company-search-string
1519 (string-match (regexp-quote company-search-string) line
1520 (length company-prefix)))
1521 (progn
1522 (add-text-properties (match-beginning 0) (match-end 0)
1523 '(face company-tooltip-selection)
1524 line)
1525 (when (< (match-beginning 0) (length company-common))
1526 (add-text-properties (match-beginning 0) (length company-common)
1527 '(face company-tooltip-common-selection)
1528 line)))
1529 (add-text-properties 0 width '(face company-tooltip-selection
1530 mouse-face company-tooltip-selection)
1531 line)
1532 (add-text-properties 0 (length company-common)
1533 '(face company-tooltip-common-selection
1534 mouse-face company-tooltip-selection)
1535 line)))
1536 line)
1537
1538 ;;; replace
1539
1540 (defun company-buffer-lines (beg end)
1541 (goto-char beg)
1542 (let ((row (company--row))
1543 lines)
1544 (while (and (equal (move-to-window-line (incf row)) row)
1545 (<= (point) end))
1546 (push (buffer-substring beg (min end (1- (point)))) lines)
1547 (setq beg (point)))
1548 (unless (eq beg end)
1549 (push (buffer-substring beg end) lines))
1550 (nreverse lines)))
1551
1552 (defsubst company-modify-line (old new offset)
1553 (concat (company-safe-substring old 0 offset)
1554 new
1555 (company-safe-substring old (+ offset (length new)))))
1556
1557 (defsubst company--length-limit (lst limit)
1558 (if (nthcdr limit lst)
1559 limit
1560 (length lst)))
1561
1562 (defun company--replacement-string (lines old column nl &optional align-top)
1563
1564 (let ((width (length (car lines))))
1565 (when (> width (- (window-width) column))
1566 (setq column (max 0 (- (window-width) width)))))
1567
1568 (let (new)
1569 (when align-top
1570 ;; untouched lines first
1571 (dotimes (i (- (length old) (length lines)))
1572 (push (pop old) new)))
1573 ;; length into old lines.
1574 (while old
1575 (push (company-modify-line (pop old) (pop lines) column) new))
1576 ;; Append whole new lines.
1577 (while lines
1578 (push (concat (company-space-string column) (pop lines)) new))
1579 (concat (when nl "\n")
1580 (mapconcat 'identity (nreverse new) "\n")
1581 "\n")))
1582
1583 (defun company--create-lines (selection limit)
1584
1585 (let ((len company-candidates-length)
1586 (numbered 99999)
1587 lines
1588 width
1589 lines-copy
1590 previous
1591 remainder
1592 new)
1593
1594 ;; Scroll to offset.
1595 (setq limit (company-pseudo-tooltip-update-offset selection len limit))
1596
1597 (when (> company-tooltip-offset 0)
1598 (setq previous (format "...(%d)" company-tooltip-offset)))
1599
1600 (setq remainder (- len limit company-tooltip-offset)
1601 remainder (when (> remainder 0)
1602 (setq remainder (format "...(%d)" remainder))))
1603
1604 (decf selection company-tooltip-offset)
1605 (setq width (max (length previous) (length remainder))
1606 lines (nthcdr company-tooltip-offset company-candidates)
1607 len (min limit len)
1608 lines-copy lines)
1609
1610 (dotimes (i len)
1611 (setq width (max (length (pop lines-copy)) width)))
1612 (setq width (min width (window-width)))
1613
1614 (setq lines-copy lines)
1615
1616 ;; number can make tooltip too long
1617 (when company-show-numbers
1618 (setq numbered company-tooltip-offset))
1619
1620 (when previous
1621 (push (propertize (company-safe-substring previous 0 width)
1622 'face 'company-tooltip)
1623 new))
1624
1625 (dotimes (i len)
1626 (push (company-fill-propertize
1627 (if (>= numbered 10)
1628 (company-reformat (pop lines))
1629 (incf numbered)
1630 (format "%s %d"
1631 (company-safe-substring (company-reformat (pop lines))
1632 0 (- width 2))
1633 (mod numbered 10)))
1634 width (equal i selection))
1635 new))
1636
1637 (when remainder
1638 (push (propertize (company-safe-substring remainder 0 width)
1639 'face 'company-tooltip)
1640 new))
1641
1642 (setq lines (nreverse new))))
1643
1644 ;; show
1645
1646 (defsubst company--window-inner-height ()
1647 (let ((edges (window-inside-edges (selected-window))))
1648 (- (nth 3 edges) (nth 1 edges))))
1649
1650 (defsubst company--pseudo-tooltip-height ()
1651 "Calculate the appropriate tooltip height.
1652 Returns a negative number if the tooltip should be displayed above point."
1653 (let* ((lines (count-lines (window-start) (point-at-bol)))
1654 (below (- (company--window-inner-height) 1 lines)))
1655 (if (and (< below (min company-tooltip-minimum company-candidates-length))
1656 (> lines below))
1657 (- (max 3 (min company-tooltip-limit lines)))
1658 (max 3 (min company-tooltip-limit below)))))
1659
1660 (defun company-pseudo-tooltip-show (row column selection)
1661 (company-pseudo-tooltip-hide)
1662 (save-excursion
1663
1664 (move-to-column 0)
1665
1666 (let* ((height (company--pseudo-tooltip-height))
1667 above)
1668
1669 (when (< height 0)
1670 (setq row (+ row height -1)
1671 above t))
1672
1673 (let* ((nl (< (move-to-window-line row) row))
1674 (beg (point))
1675 (end (save-excursion
1676 (move-to-window-line (+ row (abs height)))
1677 (point)))
1678 (ov (make-overlay beg end))
1679 (args (list (mapcar 'company-untabify
1680 (company-buffer-lines beg end))
1681 column nl above)))
1682
1683 (setq company-pseudo-tooltip-overlay ov)
1684 (overlay-put ov 'company-replacement-args args)
1685 (overlay-put ov 'company-before
1686 (apply 'company--replacement-string
1687 (company--create-lines selection (abs height))
1688 args))
1689
1690 (overlay-put ov 'company-column column)
1691 (overlay-put ov 'company-height (abs height))
1692 (overlay-put ov 'window (selected-window))))))
1693
1694 (defun company-pseudo-tooltip-show-at-point (pos)
1695 (let ((col-row (company--col-row pos)))
1696 (when col-row
1697 (company-pseudo-tooltip-show (1+ (cdr col-row)) (car col-row)
1698 company-selection))))
1699
1700 (defun company-pseudo-tooltip-edit (lines selection)
1701 (let ((column (overlay-get company-pseudo-tooltip-overlay 'company-column))
1702 (height (overlay-get company-pseudo-tooltip-overlay 'company-height)))
1703 (overlay-put company-pseudo-tooltip-overlay 'company-before
1704 (apply 'company--replacement-string
1705 (company--create-lines selection height)
1706 (overlay-get company-pseudo-tooltip-overlay
1707 'company-replacement-args)))))
1708
1709 (defun company-pseudo-tooltip-hide ()
1710 (when company-pseudo-tooltip-overlay
1711 (delete-overlay company-pseudo-tooltip-overlay)
1712 (setq company-pseudo-tooltip-overlay nil)))
1713
1714 (defun company-pseudo-tooltip-hide-temporarily ()
1715 (when (overlayp company-pseudo-tooltip-overlay)
1716 (overlay-put company-pseudo-tooltip-overlay 'invisible nil)
1717 (overlay-put company-pseudo-tooltip-overlay 'before-string nil)))
1718
1719 (defun company-pseudo-tooltip-unhide ()
1720 (when company-pseudo-tooltip-overlay
1721 (overlay-put company-pseudo-tooltip-overlay 'invisible t)
1722 (overlay-put company-pseudo-tooltip-overlay 'before-string
1723 (overlay-get company-pseudo-tooltip-overlay 'company-before))
1724 (overlay-put company-pseudo-tooltip-overlay 'window (selected-window))))
1725
1726 (defun company-pseudo-tooltip-frontend (command)
1727 "A `company-mode' front-end similar to a tool-tip but based on overlays."
1728 (case command
1729 ('pre-command (company-pseudo-tooltip-hide-temporarily))
1730 ('post-command
1731 (let ((old-height (if (overlayp company-pseudo-tooltip-overlay)
1732 (overlay-get company-pseudo-tooltip-overlay
1733 'company-height)
1734 0))
1735 (new-height (company--pseudo-tooltip-height)))
1736 (unless (and (>= (* old-height new-height) 0)
1737 (>= (abs old-height) (abs new-height)))
1738 ;; Redraw needed.
1739 (company-pseudo-tooltip-show-at-point (- (point)
1740 (length company-prefix)))))
1741 (company-pseudo-tooltip-unhide))
1742 ('hide (company-pseudo-tooltip-hide)
1743 (setq company-tooltip-offset 0))
1744 ('update (when (overlayp company-pseudo-tooltip-overlay)
1745 (company-pseudo-tooltip-edit company-candidates
1746 company-selection)))))
1747
1748 (defun company-pseudo-tooltip-unless-just-one-frontend (command)
1749 "`company-pseudo-tooltip-frontend', but not shown for single candidates."
1750 (unless (and (eq command 'post-command)
1751 (not (cdr company-candidates)))
1752 (company-pseudo-tooltip-frontend command)))
1753
1754 ;;; overlay ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1755
1756 (defvar company-preview-overlay nil)
1757 (make-variable-buffer-local 'company-preview-overlay)
1758
1759 (defun company-preview-show-at-point (pos)
1760 (company-preview-hide)
1761
1762 (setq company-preview-overlay (make-overlay pos pos))
1763
1764 (let ((completion(nth company-selection company-candidates)))
1765 (setq completion (propertize completion 'face 'company-preview))
1766 (add-text-properties 0 (length company-common)
1767 '(face company-preview-common) completion)
1768
1769 ;; Add search string
1770 (and company-search-string
1771 (string-match (regexp-quote company-search-string) completion)
1772 (add-text-properties (match-beginning 0)
1773 (match-end 0)
1774 '(face company-preview-search)
1775 completion))
1776
1777 (setq completion (company-strip-prefix completion))
1778
1779 (and (equal pos (point))
1780 (not (equal completion ""))
1781 (add-text-properties 0 1 '(cursor t) completion))
1782
1783 (overlay-put company-preview-overlay 'after-string completion)
1784 (overlay-put company-preview-overlay 'window (selected-window))))
1785
1786 (defun company-preview-hide ()
1787 (when company-preview-overlay
1788 (delete-overlay company-preview-overlay)
1789 (setq company-preview-overlay nil)))
1790
1791 (defun company-preview-frontend (command)
1792 "A `company-mode' front-end showing the selection as if it had been inserted."
1793 (case command
1794 ('pre-command (company-preview-hide))
1795 ('post-command (company-preview-show-at-point (point)))
1796 ('hide (company-preview-hide))))
1797
1798 (defun company-preview-if-just-one-frontend (command)
1799 "`company-preview-frontend', but only shown for single candidates."
1800 (unless (and (eq command 'post-command)
1801 (cdr company-candidates))
1802 (company-preview-frontend command)))
1803
1804 ;;; echo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1805
1806 (defvar company-echo-last-msg nil)
1807 (make-variable-buffer-local 'company-echo-last-msg)
1808
1809 (defvar company-echo-timer nil)
1810
1811 (defvar company-echo-delay .1)
1812
1813 (defun company-echo-show (&optional getter)
1814 (when getter
1815 (setq company-echo-last-msg (funcall getter)))
1816 (let ((message-log-max nil))
1817 (if company-echo-last-msg
1818 (message "%s" company-echo-last-msg)
1819 (message ""))))
1820
1821 (defsubst company-echo-show-soon (&optional getter)
1822 (when company-echo-timer
1823 (cancel-timer company-echo-timer))
1824 (setq company-echo-timer (run-with-timer company-echo-delay nil
1825 'company-echo-show getter)))
1826
1827 (defun company-echo-format ()
1828
1829 (let ((limit (window-width (minibuffer-window)))
1830 (len -1)
1831 ;; Roll to selection.
1832 (candidates (nthcdr company-selection company-candidates))
1833 (i (if company-show-numbers company-selection 99999))
1834 comp msg)
1835
1836 (while candidates
1837 (setq comp (company-reformat (pop candidates))
1838 len (+ len 1 (length comp)))
1839 (if (< i 10)
1840 ;; Add number.
1841 (progn
1842 (setq comp (propertize (format "%d: %s" i comp)
1843 'face 'company-echo))
1844 (incf len 3)
1845 (incf i)
1846 (add-text-properties 3 (+ 3 (length company-common))
1847 '(face company-echo-common) comp))
1848 (setq comp (propertize comp 'face 'company-echo))
1849 (add-text-properties 0 (length company-common)
1850 '(face company-echo-common) comp))
1851 (if (>= len limit)
1852 (setq candidates nil)
1853 (push comp msg)))
1854
1855 (mapconcat 'identity (nreverse msg) " ")))
1856
1857 (defun company-echo-strip-common-format ()
1858
1859 (let ((limit (window-width (minibuffer-window)))
1860 (len (+ (length company-prefix) 2))
1861 ;; Roll to selection.
1862 (candidates (nthcdr company-selection company-candidates))
1863 (i (if company-show-numbers company-selection 99999))
1864 msg comp)
1865
1866 (while candidates
1867 (setq comp (company-strip-prefix (pop candidates))
1868 len (+ len 2 (length comp)))
1869 (when (< i 10)
1870 ;; Add number.
1871 (setq comp (format "%s (%d)" comp i))
1872 (incf len 4)
1873 (incf i))
1874 (if (>= len limit)
1875 (setq candidates nil)
1876 (push (propertize comp 'face 'company-echo) msg)))
1877
1878 (concat (propertize company-prefix 'face 'company-echo-common) "{"
1879 (mapconcat 'identity (nreverse msg) ", ")
1880 "}")))
1881
1882 (defun company-echo-hide ()
1883 (when company-echo-timer
1884 (cancel-timer company-echo-timer))
1885 (unless (equal company-echo-last-msg "")
1886 (setq company-echo-last-msg "")
1887 (company-echo-show)))
1888
1889 (defun company-echo-frontend (command)
1890 "A `company-mode' front-end showing the candidates in the echo area."
1891 (case command
1892 ('pre-command (company-echo-show-soon))
1893 ('post-command (company-echo-show-soon 'company-echo-format))
1894 ('hide (company-echo-hide))))
1895
1896 (defun company-echo-strip-common-frontend (command)
1897 "A `company-mode' front-end showing the candidates in the echo area."
1898 (case command
1899 ('pre-command (company-echo-show-soon))
1900 ('post-command (company-echo-show-soon 'company-echo-strip-common-format))
1901 ('hide (company-echo-hide))))
1902
1903 (defun company-echo-metadata-frontend (command)
1904 "A `company-mode' front-end showing the documentation in the echo area."
1905 (case command
1906 ('pre-command (company-echo-show-soon))
1907 ('post-command (company-echo-show-soon 'company-fetch-metadata))
1908 ('hide (company-echo-hide))))
1909
1910 (provide 'company)
1911 ;;; company.el ends here