;; Copyright (C) 2009 Nikolaj Schumacher
;;
;; Author: Nikolaj Schumacher <bugs * nschum de>
-;; Version: 0.2.1
+;; Version: 0.3
;; Keywords: abbrev, convenience, matchis
;; URL: http://nschum.de/src/emacs/company/
;; Compatibility: GNU Emacs 22.x, GNU Emacs 23.x
;;
;;; Change Log:
;;
+;; Fixed issues with tabbar-mode and line-spacing.
+;; Performance enhancements.
+;;
+;; 2009-04-12 (0.3)
+;; Added `company-begin-commands' option.
;; Added abbrev, tempo and Xcode back-ends.
;; Back-ends are now interactive. You can start them with M-x backend-name.
;; Added `company-begin-with' for starting company from elisp-code.
"Determines which characters trigger an automatic completion.
See `company-auto-complete'. If this is a string, each string character causes
completion. If it is a list of syntax description characters (see
-`modify-char-syntax'), all characters with that syntax auto-complete.
+`modify-syntax-entry'), all characters with that syntax auto-complete.
This can also be a function, which is called with the new input and should
return non-nil if company should auto-complete.
(const :tag "immediate (t)" t)
(number :tag "seconds")))
+(defcustom company-begin-commands t
+ "*A list of commands following which company will start completing.
+If this is t, it will complete after any command. See `company-idle-delay'.
+
+Alternatively any command with a non-nil 'company-begin property is treated as
+if it was on this list."
+ :group 'company
+ :type '(choice (const :tag "Any command" t)
+ (const :tag "Self insert command" '(self-insert-command))
+ (repeat :tag "Commands" function)))
+
(defcustom company-show-numbers nil
"*If enabled, show quick-access numbers for the first ten candidates."
:group 'company
;;; backends ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defun company-grab (regexp &optional expression)
- (when (looking-back regexp)
+(defun company-grab (regexp &optional expression limit)
+ (when (looking-back regexp limit)
(or (match-string-no-properties (or expression 0)) "")))
-(defun company-in-string-or-comment (&optional point)
- (let ((pos (syntax-ppss)))
- (or (nth 3 pos) (nth 4 pos) (nth 7 pos))))
+(defun company-grab-line (regexp &optional expression)
+ (company-grab regexp expression (point-at-bol)))
+
+(defun company-grab-symbol ()
+ (if (looking-at "\\_>")
+ (buffer-substring (point) (save-excursion (skip-syntax-backward "w_")
+ (point)))
+ ""))
+
+(defun company-grab-word ()
+ (if (looking-at "\\>")
+ (buffer-substring (point) (save-excursion (skip-syntax-backward "w")
+ (point)))
+ ""))
+
+(defun company-in-string-or-comment ()
+ (let ((ppss (syntax-ppss)))
+ (or (nth 3 ppss) (nth 4 ppss) (nth 7 ppss))))
;;; completion mechanism ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
"Non-nil, if explicit completion took place.")
(make-variable-buffer-local 'company--explicit-action)
+(defvar company--this-command nil)
+
(defvar company-point nil)
(make-variable-buffer-local 'company-point)
(defsubst company-should-complete (prefix)
(and (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)))
(and company-mode
(not company-candidates)
(let ((company-idle-delay t)
- (company-minimum-prefix-length 0))
+ (company-minimum-prefix-length 0)
+ (company-begin-commands t))
(setq company--explicit-action t)
(company-begin)))
;; Return non-nil if active.
(unless (company-keep this-command)
(condition-case err
(progn
+ (setq company--this-command this-command)
(unless (equal (point) company-point)
(company-begin))
(when company-candidates
"Select the candidate picked by the mouse."
(interactive "e")
(when (nth 4 (event-start event))
- (company-set-selection (- (cdr (posn-col-row (event-start event)))
- (cdr (posn-col-row (posn-at-point)))
+ (company-set-selection (- (cdr (posn-actual-col-row (event-start event)))
+ (cdr (posn-actual-col-row (posn-at-point)))
1))
t))
"Complete the common part of all candidates."
(interactive)
(when (company-manual-begin)
- (if (equal company-common (car company-candidates))
- ;; for success message
+ (if (and (not (cdr company-candidates))
+ (equal company-common (car company-candidates)))
(company-complete-selection)
(insert (company-strip-prefix company-common)))))
`(when (company-manual-begin)
(save-window-excursion
(let ((height (window-height))
- (row (cdr (posn-col-row (posn-at-point)))))
+ (row (cdr (posn-actual-col-row (posn-at-point)))))
,@body
(and (< (window-height) height)
(< (- (window-height) row 2) company-tooltip-limit)
(defun company-buffer-lines (beg end)
(goto-char beg)
- (let ((row (cdr (posn-col-row (posn-at-point))))
+ (let ((row (cdr (posn-actual-col-row (posn-at-point))))
lines)
(while (and (equal (move-to-window-line (incf row)) row)
(<= (point) end))
(overlay-put company-pseudo-tooltip-overlay 'window (selected-window)))))
(defun company-pseudo-tooltip-show-at-point (pos)
- (let ((col-row (posn-col-row (posn-at-point pos))))
- (company-pseudo-tooltip-show (1+ (cdr col-row)) (car col-row) company-selection)))
+ (let ((col-row (posn-actual-col-row (posn-at-point pos))))
+ (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))