;; Author: Nikolaj Schumacher
;; Maintainer: Dmitry Gutov <dgutov@yandex.ru>
;; URL: http://company-mode.github.io/
-;; Version: 0.8.7
+;; Version: 0.8.8-cvs
;; Keywords: abbrev, convenience, matching
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
of the following:
`prefix': The back-end should return the text to be completed. It must be
-text immediately before point. Returning nil passes control to the next
-back-end. The function should return `stop' if it should complete but
-cannot (e.g. if it is in the middle of a string). Instead of a string,
-the back-end may return a cons where car is the prefix and cdr is used in
-`company-minimum-prefix-length' test. It must be either number or t, and
-in the latter case the test automatically succeeds.
+text immediately before point. Returning nil from this command passes
+control to the next back-end. The function should return `stop' if it
+should complete but cannot (e.g. if it is in the middle of a string).
+Instead of a string, the back-end may return a cons where car is the prefix
+and cdr is used in `company-minimum-prefix-length' test. It must be either
+number or t, and in the latter case the test automatically succeeds.
`candidates': The second argument is the prefix to be completed. The
return value should be a list of candidates that match the prefix.
Non-prefix matches are also supported (candidates that don't start with the
prefix, but match it in some backend-defined way). Backends that use this
-feature must disable cache (return t to `no-cache') and should also respond
-to `match'.
+feature must disable cache (return t to `no-cache') and might also want to
+respond to `match'.
Optional commands:
backends should store the related information on candidates using text
properties.
-`match': The second argument is a completion candidate. Backends that
-provide non-prefix completions should return the position of the end of
-text in the candidate that matches `prefix'. It will be used when
-rendering the popup.
+`match': The second argument is a completion candidate. Return the index
+after the end of text matching `prefix' within the candidate string. It
+will be used when rendering the popup. This command only makes sense for
+backends that provide non-prefix completion.
`require-match': If this returns t, the user is not allowed to enter
anything not offered as a candidate. Use with care! The default value nil
(interactive)
(setq this-command last-command))
-(global-set-key '[31415926] 'company-ignore)
+(global-set-key '[company-dummy-event] 'company-ignore)
(defun company-input-noop ()
- (push 31415926 unread-command-events))
+ (push 'company-dummy-event unread-command-events))
(defun company--posn-col-row (posn)
(let ((col (car (posn-col-row posn)))
;; XXX: Return value we check here is subject to change.
(if (eq (company-call-backend 'ignore-case) 'keep-prefix)
(insert (company-strip-prefix candidate))
- (delete-region (- (point) (length company-prefix)) (point))
- (insert candidate)))
+ (unless (equal company-prefix candidate)
+ (delete-region (- (point) (length company-prefix)) (point))
+ (insert candidate))))
(defmacro company-with-candidate-inserted (candidate &rest body)
"Evaluate BODY with CANDIDATE temporarily inserted.
;; We want to support non-prefix completion, so filtering is the
;; responsibility of each respective backend, not ours.
;; On the other hand, we don't want to replace non-prefix input in
- ;; `company-complete-common'.
+ ;; `company-complete-common', unless there's only one candidate.
(setq company-common
(if (cdr company-candidates)
- (let ((common (try-completion company-prefix company-candidates)))
- (if (eq common t)
- ;; Mulple equal strings, probably with different
- ;; annotations.
- company-prefix
+ (let ((common (try-completion "" company-candidates)))
+ (when (string-prefix-p company-prefix common
+ completion-ignore-case)
common))
(car company-candidates)))))
(setq this-command 'company-complete-common))))
(defun company-complete-number (n)
- "Insert the Nth candidate.
+ "Insert the Nth candidate visible in the tooltip.
To show the number next to the candidates in some back-ends, enable
`company-show-numbers'. When called interactively, uses the last typed
character, stripping the modifiers. That character must be a digit."
(n (- char ?0)))
(if (zerop n) 10 n))))
(when (company-manual-begin)
- (and (or (< n 1) (> n company-candidates-length))
+ (and (or (< n 1) (> n (- company-candidates-length
+ company-tooltip-offset)))
(error "No candidate number %d" n))
(cl-decf n)
- (company-finish (nth n company-candidates))))
+ (company-finish (nth (+ n company-tooltip-offset)
+ company-candidates))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(string-width company-common)
0)))
(ann-ralign company-tooltip-align-annotations)
- (value (company--clean-string value))
(ann-truncate (< width
(+ (length value) (length annotation)
(if ann-ralign 1 0))))
(floor (window-screen-lines))
(window-body-height)))
-(defsubst company--window-width ()
+(defun company--window-width ()
(let ((ww (window-body-width)))
;; Account for the line continuation column.
(when (zerop (cadr (window-fringes)))
(let ((margins (window-margins)))
(+ (or (car margins) 0)
(or (cdr margins) 0)))))
+ (when (and word-wrap
+ (version< emacs-version "24.4.51.5"))
+ ;; http://debbugs.gnu.org/18384
+ (cl-decf ww))
ww))
(defun company--replacement-string (lines old column nl &optional align-top)
(defun company--create-lines (selection limit)
(let ((len company-candidates-length)
- (numbered 99999)
(window-width (company--window-width))
lines
width
(dotimes (_ len)
(let* ((value (pop lines-copy))
(annotation (company-call-backend 'annotation value)))
- (when (and annotation company-tooltip-align-annotations)
- ;; `lisp-completion-at-point' adds a space.
- (setq annotation (comment-string-strip annotation t nil)))
+ (setq value (company--clean-string value))
+ (when annotation
+ (when company-tooltip-align-annotations
+ ;; `lisp-completion-at-point' adds a space.
+ (setq annotation (comment-string-strip annotation t nil)))
+ (setq annotation (company--clean-string annotation)))
(push (cons value annotation) items)
- (setq width (max (+ (string-width value)
+ (setq width (max (+ (length value)
(if (and annotation company-tooltip-align-annotations)
(1+ (length annotation))
(length annotation)))
(setq width (min window-width
(max company-tooltip-minimum-width
- (if (and company-show-numbers
- (< company-tooltip-offset 10))
+ (if company-show-numbers
(+ 2 width)
width))))
- ;; number can make tooltip too long
- (when company-show-numbers
- (setq numbered company-tooltip-offset))
-
- (let ((items (nreverse items)) new)
+ (let ((items (nreverse items))
+ (numbered (if company-show-numbers 0 99999))
+ new)
(when previous
(push (company--scrollpos-line previous width) new))
(defun company-preview-show-at-point (pos)
(company-preview-hide)
- (setq company-preview-overlay (make-overlay pos pos))
-
(let ((completion (nth company-selection company-candidates)))
(setq completion (propertize completion 'face 'company-preview))
(add-text-properties 0 (length company-common)
(and (equal pos (point))
(not (equal completion ""))
- (add-text-properties 0 1 '(cursor t) completion))
-
- (let ((ov company-preview-overlay))
- (overlay-put ov 'after-string completion)
- (overlay-put ov 'window (selected-window)))))
+ (add-text-properties 0 1 '(cursor 1) completion))
+
+ (let ((beg pos)
+ (ptf-workaround (and
+ company-pseudo-tooltip-overlay
+ (char-before pos)
+ (eq ?\n (char-after pos)))))
+ ;; Try to accomodate for the pseudo-tooltip overlay,
+ ;; which may start at the same position if it's at eol.
+ (when ptf-workaround
+ (cl-decf beg)
+ (setq completion (concat (buffer-substring beg pos) completion)))
+
+ (setq company-preview-overlay (make-overlay beg pos))
+
+ (let ((ov company-preview-overlay))
+ (overlay-put ov (if ptf-workaround 'display 'after-string)
+ completion)
+ (overlay-put ov 'window (selected-window))))))
(defun company-preview-hide ()
(when company-preview-overlay