;; 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:
;;
+;; Added back-end `company-dabbrev-code' for generic code.
+;; Fixed `company-begin-with'.
+;;
+;; 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.
(defcustom company-backends '(company-elisp company-nxml company-css
company-semantic company-xcode company-gtags
company-etags company-oddmuse company-files
- company-dabbrev)
+ company-dabbrev-code company-dabbrev)
"*The list of active back-ends (completion engines).
Each back-end is a function that takes a variable number of arguments.
The first argument is the command requested from the back-end. It is one
'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).
+\(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.
'sorted: The back-end may return t here to indicate that the candidates
are sorted and will not need to be sorted again.
+'duplicates: If non-nil, company will take care of removing duplicates
+from the list.
+
'no-cache: Usually company doesn't ask for candidates again as completion
progresses, unless the back-end returns t for this command. The second
argument is the latest prefix.
c company-candidates-predicate)))
(unless (funcall company-backend 'sorted)
(setq c (sort c 'string<)))
+ (when (company-call-backend 'duplicates)
+ ;; strip duplicates
+ (let ((c2 c))
+ (while c2
+ (setcdr c2 (progn (while (equal (pop c2) (car c2)))
+ c2)))))
c))))
(if (or (cdr candidates)
(not (equal (car candidates) prefix)))
company-candidates)))
(defun company-begin ()
- (when (if company-candidates
- (not (company-continue))
- (company--should-complete))
+ (when (and (not (and company-candidates (company-continue)))
+ (company--should-complete))
(let (prefix)
(dolist (backend (if company-backend
;; prefer manual override
(defvar company-callback nil)
(make-variable-buffer-local 'company-callback)
+(defvar company-begin-with-marker nil)
+(make-variable-buffer-local 'company-begin-with-marker)
+
(defun company-remove-callback (&optional ignored)
(remove-hook 'company-completion-finished-hook company-callback t)
- (remove-hook 'company-completion-cancelled-hook 'company-remove-callback t))
+ (remove-hook 'company-completion-cancelled-hook 'company-remove-callback t)
+ (remove-hook 'company-completion-finished-hook 'company-remove-callback t)
+ (set-marker company-begin-with-marker nil))
(defun company-begin-backend (backend &optional callback)
"Start a completion at point using BACKEND."
'functionp nil "company-")))
(when val
(list (intern val)))))
- (when callback
- (setq company-callback
- `(lambda (completion)
- (funcall ',callback completion)
- (company-remove-callback)))
- (add-hook 'company-completion-cancelled-hook 'company-remove-callback nil t)
+ (when (setq company-callback callback)
(add-hook 'company-completion-finished-hook company-callback nil t))
+ (add-hook 'company-completion-cancelled-hook 'company-remove-callback nil t)
+ (add-hook 'company-completion-finished-hook 'company-remove-callback nil t)
(setq company-backend backend)
;; Return non-nil if active.
(or (company-manual-begin)
\(company-begin-with '\(\"foo\" \"foobar\" \"foobarbaz\"\)\)"
(company-begin-backend
(let ((start (- (point) (or prefix-length 0))))
+ (setq company-begin-with-marker (copy-marker (point) t))
`(lambda (command &optional arg &rest ignored)
- (case command-history
- ('prefix (message "prefix %s" (buffer-substring ,start (point)))
- (when (>= (point) ,start)
+ (case command
+ ('prefix (when (equal (point)
+ (marker-position company-begin-with-marker))
(buffer-substring ,start (point))))
('candidates (all-completions arg ',candidates))
('require-match ,require-match))))