]> code.delx.au - gnu-emacs-elpa/blobdiff - company.el
Bumped version to 0.3.
[gnu-emacs-elpa] / company.el
index 2ebaa66e8c1bc4e834891e0d71e0f817e5f781d2..c064b3d83595d6add60360d624344f4c3a895674 100644 (file)
@@ -3,7 +3,7 @@
 ;; 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
 ;; Enable company-mode with M-x company-mode.  For further information look at
 ;; the documentation for `company-mode' (C-h f company-mode RET)
 ;;
+;; If you want to start a specific back-end, call it interactively or use
+;; `company-begin-backend'.  For example:
+;; M-x company-abbrev will prompt for and insert an abbrev.
+;;
 ;; To write your own back-end, look at the documentation for `company-backends'.
 ;; Here is a simple example completing "foo":
 ;;
 ;;
 ;;; Change Log:
 ;;
+;; 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.
 ;;    Added hooks.
 ;;    Added `company-require-match' and `company-auto-complete' options.
 (add-to-list 'debug-ignored-errors "^No \\(document\\|loc\\)ation available$")
 (add-to-list 'debug-ignored-errors "^Company not ")
 (add-to-list 'debug-ignored-errors "^No candidate number ")
+(add-to-list 'debug-ignored-errors "^Cannot complete at point$")
 
 (defgroup company nil
   "Extensible inline text completion mechanism"
@@ -227,8 +236,9 @@ The visualized data is stored in `company-prefix', `company-candidates',
                          (function :tag "custom function" nil))))
 
 (defcustom company-backends '(company-elisp company-nxml company-css
-                              company-semantic company-gtags company-etags
-                              company-oddmuse company-files company-dabbrev)
+                              company-semantic company-xcode company-gtags
+                              company-etags company-oddmuse company-files
+                              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
@@ -267,7 +277,8 @@ user that choice with `company-require-match'.  Return value 'never overrides
 that option the other way around.
 
 The back-end should return nil for all commands it does not support or
-does not know about."
+does not know about.  It should also be callable interactively and use
+`company-begin-backend' to start itself in that case."
   :group 'company
   :type '(repeat (function :tag "function" nil)))
 
@@ -311,19 +322,29 @@ This can be overridden by the back-end, if it returns t or 'never to
                         'company-explicit-action-p)
                  (const :tag "On" t)))
 
-(defcustom company-auto-complete '(?\  ?\( ?\) ?. ?\" ?$ ?\' ?< ?| ?!)
+(defcustom company-auto-complete 'company-explicit-action-p
+  "Determines when to auto-complete.
+If this is enabled, all characters from `company-auto-complete-chars' complete
+the selected completion.  This can also be a function."
+  :group 'company
+  :type '(choice (const :tag "Off" nil)
+                 (function :tag "Predicate function")
+                 (const :tag "On, if user interaction took place"
+                        'company-explicit-action-p)
+                 (const :tag "On" t)))
+
+(defcustom company-auto-complete-chars '(?\  ?\( ?\) ?. ?\" ?$ ?\' ?< ?| ?!)
   "Determines which characters trigger an automatic completion.
-If this is a function, it is called with the new input and should return non-nil
-if company should auto-complete.
+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.
 
-If this is a string, all characters in that string will complete automatically.
+This can also be a function, which is called with the new input and should
+return non-nil if company should auto-complete.
 
-A list of characters represent the syntax (see `modify-syntax-entry') of
-characters that complete automatically."
+A character that is part of a valid candidate never starts auto-completion."
   :group 'company
-  :type '(choice (const :tag "Off" nil)
-                 (function :tag "Predicate function")
-                 (string :tag "Characters")
+  :type '(choice (string :tag "Characters")
                  (set :tag "Syntax"
                       (const :tag "Whitespace" ?\ )
                       (const :tag "Symbol" ?_)
@@ -338,7 +359,8 @@ characters that complete automatically."
                       (const :tag "Comment ender." ?>)
                       (const :tag "Character-quote." ?/)
                       (const :tag "Generic string fence." ?|)
-                      (const :tag "Generic comment fence." ?!))))
+                      (const :tag "Generic comment fence." ?!))
+                 (function :tag "Predicate function")))
 
 (defcustom company-idle-delay .7
   "*The idle delay in seconds until automatic completions starts.
@@ -349,6 +371,17 @@ immediately when a prefix of `company-minimum-prefix-length' is reached."
                  (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
@@ -407,7 +440,8 @@ Completions can be searched with `company-search-candidates' or
 inactive, as well.
 
 The completion data is retrieved using `company-backends' and displayed using
-`company-frontends'.
+`company-frontends'.  If you want to start a specific back-end, call it
+interactively or use `company-begin-backend'.
 
 regular keymap (`company-mode-map'):
 
@@ -542,6 +576,9 @@ keymap during active completions (`company-active-map'):
 
 (defsubst company-should-complete (prefix)
   (and (eq company-idle-delay t)
+       (or (eq t company-begin-commands)
+           (memq 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)))
 
@@ -636,7 +673,8 @@ keymap during active completions (`company-active-map'):
   (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.
@@ -662,11 +700,14 @@ keymap during active completions (`company-active-map'):
   "Return non-nil, if input starts with punctuation or parentheses."
   (and (> end beg)
        (if (functionp company-auto-complete)
-           (funcall company-auto-complete (buffer-substring beg end))
-         (if (consp company-auto-complete)
-             (memq (char-syntax (char-after beg)) company-auto-complete)
+           (funcall company-auto-complete)
+         company-auto-complete)
+       (if (functionp company-auto-complete-chars)
+           (funcall company-auto-complete-chars (buffer-substring beg end))
+         (if (consp company-auto-complete-chars)
+             (memq (char-syntax (char-after beg)) company-auto-complete-chars)
            (string-match (buffer-substring beg (1+ beg))
-                         company-auto-complete)))))
+                         company-auto-complete-chars)))))
 
 (defun company-continue ()
   (when company-candidates
@@ -1040,8 +1081,8 @@ followed by `company-search-kill-others' after each input."
   "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)))))
 
@@ -1159,6 +1200,11 @@ when the selection has been changed, the selected candidate is completed."
 
 (defun company-begin-backend (backend &optional callback)
   "Start a completion at point using BACKEND."
+  (interactive (let ((val (completing-read "Company back-end: "
+                                           obarray
+                                           'functionp nil "company-")))
+                 (when val
+                   (list (intern val)))))
   (when callback
     (setq company-callback
           `(lambda (completion)
@@ -1167,7 +1213,9 @@ when the selection has been changed, the selected candidate is completed."
     (add-hook 'company-completion-cancelled-hook 'company-remove-callback nil t)
     (add-hook 'company-completion-finished-hook company-callback nil t))
   (setq company-backend backend)
-  (company-manual-begin))
+  ;; Return non-nil if active.
+  (or (company-manual-begin)
+      (error "Cannot complete at point")))
 
 (defun company-begin-with (candidates
                            &optional prefix-length require-match callback)