;; Author: Nikolaj Schumacher
;; Maintainer: Dmitry Gutov <dgutov@yandex.ru>
;; URL: http://company-mode.github.io/
-;; Version: 0.8.6-cvs
+;; Version: 0.8.7
;; Keywords: abbrev, convenience, matching
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
(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."
(interactive
- (list (let ((n (- (event-basic-type last-command-event) ?0)))
+ (list (let* ((type (event-basic-type last-command-event))
+ (char (if (characterp type)
+ ;; Number on the main row.
+ type
+ ;; Keypad number, if bound directly.
+ (car (last (string-to-list (symbol-name type))))))
+ (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))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
limit
(length lst)))
+(defsubst company--window-height ()
+ (if (fboundp 'window-screen-lines)
+ (floor (window-screen-lines))
+ (window-body-height)))
+
+(defsubst company--window-width ()
+ (let ((ww (window-body-width)))
+ ;; Account for the line continuation column.
+ (when (zerop (cadr (window-fringes)))
+ (cl-decf ww))
+ (unless (or (display-graphic-p)
+ (version< "24.3.1" emacs-version))
+ ;; Emacs 24.3 and earlier included margins
+ ;; in window-width when in TTY.
+ (cl-decf ww
+ (let ((margins (window-margins)))
+ (+ (or (car margins) 0)
+ (or (cdr margins) 0)))))
+ ww))
+
(defun company--replacement-string (lines old column nl &optional align-top)
(cl-decf column company-tooltip-margin)
(while old
(push (company-modify-line (pop old)
(company--offset-line (pop lines) offset)
- column) new))
+ column)
+ new))
;; Append whole new lines.
(while lines
(push (concat (company-space-string column)
(defun company--create-lines (selection limit)
(let ((len company-candidates-length)
- (numbered 99999)
(window-width (company--window-width))
lines
width
(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))
;; show
-(defsubst company--window-height ()
- (if (fboundp 'window-screen-lines)
- (floor (window-screen-lines))
- (window-body-height)))
-
-(defsubst company--window-width ()
- (let ((ww (window-body-width)))
- ;; Account for the line continuation column.
- (when (zerop (cadr (window-fringes)))
- (cl-decf ww))
- (unless (or (display-graphic-p)
- (version< "24.3.1" emacs-version))
- ;; Emacs 24.3 and earlier included margins
- ;; in window-width when in TTY.
- (cl-decf ww
- (let ((margins (window-margins)))
- (+ (or (car margins) 0)
- (or (cdr margins) 0)))))
- ww))
-
(defun company--pseudo-tooltip-height ()
"Calculate the appropriate tooltip height.
Returns a negative number if the tooltip should be displayed above point."