;; Copyright (C) 2009 Nikolaj Schumacher
;;
;; Author: Nikolaj Schumacher <bugs * nschum de>
-;; Version: 0.3
+;; Version: 0.3.1
;; Keywords: abbrev, convenience, matchis
;; URL: http://nschum.de/src/emacs/company/
;; Compatibility: GNU Emacs 22.x, GNU Emacs 23.x
;;
;;; Change Log:
;;
+;; 2009-04-15 (0.3.1)
+;; Added 'stop prefix to prevent dabbrev from completing inside of symbols.
;; Fixed issues with tabbar-mode and line-spacing.
;; Performance enhancements.
;;
'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.
+back-end. The function should return 'stop if it should complete but cannot
+(e.g. if it is in the middle of a string).
'candidates: The second argument is the prefix to be completed. The
return value should be a list of candidates that start with the prefix.
(if (looking-at "\\_>")
(buffer-substring (point) (save-excursion (skip-syntax-backward "w_")
(point)))
- ""))
+ (unless (and (char-after) (memq (char-syntax (char-after)) '(?w ?_)))
+ "")))
(defun company-grab-word ()
(if (looking-at "\\>")
(buffer-substring (point) (save-excursion (skip-syntax-backward "w")
(point)))
- ""))
+ (unless (and (char-after) (eq (char-syntax (char-after)) ?w))
+ "")))
(defun company-in-string-or-comment ()
(let ((ppss (syntax-ppss)))
;; It's mory efficient to fix it only when they are displayed.
(concat company-prefix (substring candidate (length company-prefix))))
-(defsubst company-should-complete (prefix)
- (and (eq company-idle-delay t)
+(defun company--should-complete ()
+ (and (not (or buffer-read-only overriding-terminal-local-map
+ overriding-local-map))
+ (eq company-idle-delay t)
(or (eq t company-begin-commands)
(memq company--this-command company-begin-commands)
(and (symbolp this-command) (get this-command 'company-begin)))
- (not (and transient-mark-mode mark-active))
- (>= (length prefix) company-minimum-prefix-length)))
+ (not (and transient-mark-mode mark-active))))
(defsubst company-call-frontends (command)
(dolist (frontend company-frontends)
company-auto-complete-chars)))))
(defun company-continue ()
- (when company-candidates
- (when (funcall company-backend 'no-cache company-prefix)
- ;; Don't complete existing candidates, fetch new ones.
- (setq company-candidates-cache nil))
- (let ((new-prefix (funcall company-backend 'prefix)))
- (unless (and (= (- (point) (length new-prefix))
- (- company-point (length company-prefix)))
- (or (equal company-prefix new-prefix)
- (let ((c (company-calculate-candidates new-prefix)))
- ;; t means complete/unique.
- (if (eq c t)
- (progn (company-cancel new-prefix) t)
- (when (consp c)
- (setq company-prefix new-prefix)
- (company-update-candidates c)
- t)))))
- (if (company-auto-complete-p company-point (point))
- (save-excursion
- (goto-char company-point)
- (company-complete-selection)
+ (when (funcall company-backend 'no-cache company-prefix)
+ ;; Don't complete existing candidates, fetch new ones.
+ (setq company-candidates-cache nil))
+ (let ((new-prefix (funcall company-backend 'prefix)))
+ (unless (and (= (- (point) (length new-prefix))
+ (- company-point (length company-prefix)))
+ (or (equal company-prefix new-prefix)
+ (let ((c (company-calculate-candidates new-prefix)))
+ ;; t means complete/unique.
+ (if (eq c t)
+ (progn (company-cancel new-prefix) t)
+ (when (consp c)
+ (setq company-prefix new-prefix)
+ (company-update-candidates c)
+ t)))))
+ (if (company-auto-complete-p company-point (point))
+ (save-excursion
+ (goto-char company-point)
+ (company-complete-selection)
+ (setq company-candidates nil))
+ (if (not (and (company-incremental-p company-prefix new-prefix)
+ (company-require-match-p)))
+ (progn
+ (when (equal company-prefix (car company-candidates))
+ ;; cancel, but last input was actually success
+ (company-cancel company-prefix))
(setq company-candidates nil))
- (if (not (and (company-incremental-p company-prefix new-prefix)
- (company-require-match-p)))
- (progn
- (when (equal company-prefix (car company-candidates))
- ;; cancel, but last input was actually success
- (company-cancel company-prefix))
- (setq company-candidates nil))
- (backward-delete-char (length new-prefix))
- (insert company-prefix)
- (ding)
- (message "Matching input is required")))
- company-candidates))))
+ (backward-delete-char (length new-prefix))
+ (insert company-prefix)
+ (ding)
+ (message "Matching input is required")))
+ company-candidates)))
(defun company-begin ()
- (if (or buffer-read-only overriding-terminal-local-map overriding-local-map)
- ;; Don't complete in these cases.
- (setq company-candidates nil)
- (company-continue)
- (unless company-candidates
- (let (prefix)
- (dolist (backend (if company-backend
- ;; prefer manual override
- (list company-backend)
- (cons company-backend company-backends)))
- (when (and (functionp backend)
- (setq prefix (funcall backend 'prefix)))
- (setq company-backend backend)
- (when (company-should-complete prefix)
- (let ((c (company-calculate-candidates prefix)))
- ;; t means complete/unique. We don't start, so no hooks.
- (when (consp c)
- (setq company-prefix prefix)
- (company-update-candidates c)
- (run-hook-with-args 'company-completion-started-hook
- (company-explicit-action-p))
- (company-call-frontends 'show))))
- (return prefix))))))
+ (when (if company-candidates
+ (not (company-continue))
+ (company--should-complete))
+ (let (prefix)
+ (dolist (backend (if company-backend
+ ;; prefer manual override
+ (list company-backend)
+ company-backends))
+ (when (and (functionp backend)
+ (setq prefix (funcall backend 'prefix)))
+ (when (and (stringp prefix)
+ (>= (length prefix) company-minimum-prefix-length))
+ (setq company-backend backend
+ company-prefix prefix)
+ (let ((c (company-calculate-candidates prefix)))
+ ;; t means complete/unique. We don't start, so no hooks.
+ (when (consp c)
+ (company-update-candidates c)
+ (run-hook-with-args 'company-completion-started-hook
+ (company-explicit-action-p))
+ (company-call-frontends 'show))))
+ (return prefix)))))
(if company-candidates
(progn
(when (and company-end-of-buffer-workaround (eobp))
(setq this-command 'company-complete-common))))
(defun company-complete-number (n)
- "Complete the Nth candidate."
+ "Complete the Nth candidate.
+To show the number next to the candidates in some back-ends, enable
+`company-show-numbers'."
(when (company-manual-begin)
(and (< n 1) (> n company-candidates-length)
(error "No candidate number %d" n))
(setq lines-copy lines)
;; number can make tooltip too long
- (and company-show-numbers
- (< (setq numbered company-tooltip-offset) 10)
- (incf width 2))
+ (when company-show-numbers
+ (setq numbered company-tooltip-offset))
(when previous
(push (propertize (company-safe-substring previous 0 width)
(defun company-pseudo-tooltip-show-at-point (pos)
(let ((col-row (posn-actual-col-row (posn-at-point pos))))
- (company-pseudo-tooltip-show (1+ (cdr col-row)) (car col-row)
- company-selection)))
+ (when col-row
+ (company-pseudo-tooltip-show (1+ (cdr col-row)) (car col-row)
+ company-selection))))
(defun company-pseudo-tooltip-edit (lines selection)
(let* ((old-string (overlay-get company-pseudo-tooltip-overlay 'company-old))