;; Author: Nikolaj Schumacher
;; Maintainer: Dmitry Gutov <dgutov@yandex.ru>
;; URL: http://company-mode.github.io/
-;; Version: 0.8.5
+;; Version: 0.8.6
;; Keywords: abbrev, convenience, matching
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
(defcustom company-begin-commands '(self-insert-command
org-self-insert-command
+ orgtbl-self-insert-command
c-scope-operator
c-electric-colon
c-electric-lt-gt
(define-key keymap "\C-s" 'company-search-candidates)
(define-key keymap "\C-\M-s" 'company-filter-candidates)
(dotimes (i 10)
- (define-key keymap (kbd (format "M-%d" i)) 'company-complete-number))
+ (define-key keymap (read-kbd-macro (format "M-%d" i)) 'company-complete-number))
keymap)
"Keymap that is enabled during an active completion.")
res))))
(defun company-call-backend-raw (&rest args)
- (condition-case err
+ (condition-case-unless-debug err
(if (functionp company-backend)
(apply company-backend args)
(apply #'company--multi-backend-adapter company-backend args))
(if (eq (company-call-backend 'ignore-case) 'keep-prefix)
(insert (company-strip-prefix candidate))
(delete-region (- (point) (length company-prefix)) (point))
- (insert-before-markers candidate)))
+ (insert candidate)))
(defmacro company-with-candidate-inserted (candidate &rest body)
"Evaluate BODY with CANDIDATE temporarily inserted.
(defun company-call-frontends (command)
(dolist (frontend company-frontends)
- (condition-case err
+ (condition-case-unless-debug err
(funcall frontend command)
(error (error "Company: Front-end %s error \"%s\" on command %s"
frontend (error-message-string err) command)))))
(eq pos (point))
(when (company-auto-begin)
(company-input-noop)
- (company-post-command))))
+ (let ((this-command 'company-idle-begin))
+ (company-post-command)))))
(defun company-auto-begin ()
(and company-mode
(defun company-pre-command ()
(unless (company-keep this-command)
- (condition-case err
+ (condition-case-unless-debug err
(when company-candidates
(company-call-frontends 'pre-command)
(unless (company--should-continue)
(company-uninstall-map))
(defun company-post-command ()
+ (when (null this-command)
+ ;; Happens when the user presses `C-g' while inside
+ ;; `flyspell-post-command-hook', for example.
+ ;; Or any other `post-command-hook' function that can call `sit-for',
+ ;; or any quittable timer function.
+ (company-abort)
+ (setq this-command 'company-abort))
(unless (company-keep this-command)
- (condition-case err
+ (condition-case-unless-debug err
(progn
(unless (equal (point) company-point)
(let (company-idle-delay) ; Against misbehavior while debugging.
(defun company-search-printing-char ()
(interactive)
(company-search-assert-enabled)
- (setq company-search-string
- (concat (or company-search-string "") (string last-command-event))
- company-search-lighter (concat " Search: \"" company-search-string
- "\""))
- (let ((pos (company-search company-search-string
- (nthcdr company-selection company-candidates))))
+ (let* ((ss (concat company-search-string (string last-command-event)))
+ (pos (company-search ss (nthcdr company-selection company-candidates))))
(if (null pos)
(ding)
+ (setq company-search-string ss
+ company-search-lighter (concat " Search: \"" ss "\""))
(company-set-selection (+ company-selection pos) t))))
(defun company-search-repeat-forward ()
(company-set-selection (- company-selection pos 1) t))))
(defun company-create-match-predicate ()
- (setq company-candidates-predicate
- `(lambda (candidate)
- ,(if company-candidates-predicate
- `(and (string-match ,company-search-string candidate)
- (funcall ,company-candidates-predicate
- candidate))
- `(string-match ,company-search-string candidate))))
+ (let ((ss company-search-string))
+ (setq company-candidates-predicate
+ (when ss (lambda (candidate) (string-match ss candidate)))))
(company-update-candidates
(company-apply-predicate company-candidates company-candidates-predicate))
;; Invalidate cache.
(defun company-fill-propertize (value annotation width selected left right)
(let* ((margin (length left))
(common (or (company-call-backend 'match value)
- (length company-common)))
+ (if company-common
+ (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))))
line)))
line))
+(defun company--clean-string (str)
+ (replace-regexp-in-string
+ "\\([^[:graph:] ]\\)\\|\\(\ufeff\\)\\|[[:multibyte:]]"
+ (lambda (match)
+ (cond
+ ((match-beginning 1)
+ ;; FIXME: Better char for 'non-printable'?
+ ;; We shouldn't get any of these, but sometimes we might.
+ "\u2017")
+ ((match-beginning 2)
+ ;; Zero-width non-breakable space.
+ "")
+ ((> (string-width match) 1)
+ (concat
+ (make-string (1- (string-width match)) ?\ufeff)
+ match))
+ (t match)))
+ str))
+
;;; replace
(defun company-buffer-lines (beg end)
;; `lisp-completion-at-point' adds a space.
(setq annotation (comment-string-strip annotation t nil)))
(push (cons value annotation) items)
- (setq width (max (+ (length value)
+ (setq width (max (+ (string-width value)
(if (and annotation company-tooltip-align-annotations)
(1+ (length annotation))
(length annotation)))
(end (save-excursion
(move-to-window-line (+ row (abs height)))
(point)))
- (ov (make-overlay (if nl beg (1- beg)) end nil t))
+ (ov (make-overlay (if nl beg (1- beg)) end nil t t))
(args (list (mapcar 'company-plainify
(company-buffer-lines beg end))
column nl above)))