]> code.delx.au - gnu-emacs-elpa/commitdiff
Introduce `company--auto-completion', rename 'common to 'safe
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 22 Mar 2013 05:07:04 +0000 (09:07 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 22 Mar 2013 05:21:51 +0000 (09:21 +0400)
NEWS.md
company-clang.el
company-eclim.el
company.el

diff --git a/NEWS.md b/NEWS.md
index f53a9fe43ac171fb4c575db91a7fb9bacb70f03b..157e6def728f891f128b2db5aefc4d7c30afb67a 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,13 +2,14 @@
 
 ## Next
 
+* `company-eclim` and `company-clang` only expand the template on explicit user
+  action (such as `company-complete-{selection,number,mouse}`).
 * `company-template` has some breaking changes.  When point is at one of the
   fields, it's displayed at the beginning, not right after it; `<tab>` jumps to
   the next field, `forward-word` and `subword-forward` remappings are removed;
   when you jump to the next field, if the current one hasn't been edited, the
   overlay gets removed but the text remains.
-* `company-eclim` shows method overloads and inserts templates for calls.
-* `company-clang` ObjC arguments template insertion now requires explicit user action.
+* `company-eclim` shows method overloads and expands templates for calls.
 * `company-clang-objc-templatify` does not insert spaces after colons anymore.
 * `company-clang` is now only initialized in supported buffers.
   So, no error messages if you don't have Clang until you open a C file.
index 9dbd12d9241148d57c5090944a0e7e068fc40ab5..fc426d3b7d63096431aa4a45cc589b0749690565 100644 (file)
@@ -245,9 +245,9 @@ Completions only work correctly when the buffer has been saved.
                "#]" " "
                (replace-regexp-in-string "[<{[]#\\|#[>}]" "" meta t)
                t))))
-    (common (and (derived-mode-p 'objc-mode)
-                 (string-match ":" arg)
-                 (substring arg 0 (match-beginning 0))))
+    (safe (and (derived-mode-p 'objc-mode)
+               (string-match ":" arg)
+               (substring arg 0 (match-beginning 0))))
     (post-completion (and (derived-mode-p 'objc-mode)
                           (string-match ":" arg)
                           (company-clang-objc-templatify arg)))))
index c481dd9d9bf5b3f88ea75248e9ec17fa4d289667..fd74a013acdc9ea6243f3efb37112bc56b22ae91 100644 (file)
@@ -167,8 +167,8 @@ Completions only work correctly when the buffer has been saved.
     (meta (company-eclim--meta arg))
     ;; because "" doesn't return everything
     (no-cache (equal arg ""))
-    (common (when (string-match "(" arg)
-              (substring arg 0 (match-beginning 0))))
+    (safe (when (string-match "(" arg)
+            (substring arg 0 (match-beginning 0))))
     (post-completion (when (string-match "([^)]" arg)
                        (company-eclim--templatify arg)))))
 
index fe87eed697945834b3bb9ece4fafd6a1c3f979f9..ff4f29f686d43667da5be60a57ba59b024996df6 100644 (file)
@@ -696,6 +696,10 @@ keymap during active completions (`company-active-map'):
   "Non-nil, if explicit completion took place.")
 (make-variable-buffer-local 'company--explicit-action)
 
+(defvar company--auto-completion nil
+  "Non-nil when current candidate is being completed automatically.
+Controlled by `company-auto-complete'.")
+
 (defvar company--point-max nil)
 (make-variable-buffer-local 'company--point-max)
 
@@ -787,12 +791,15 @@ can retrieve meta-data for them."
   (push (cons company-prefix company-candidates) company-candidates-cache)
   ;; Calculate common.
   (let ((completion-ignore-case (company-call-backend 'ignore-case)))
-    (let ((common (try-completion company-prefix company-candidates)))
-      (setq company-common (or (company-call-backend 'common common)
-                               common))))
+    (setq company-common (company--safe-candidate
+                          (try-completion company-prefix company-candidates))))
   (when (eq company-common t)
     (setq company-candidates nil)))
 
+(defun company--safe-candidate (str)
+  (or (company-call-backend 'safe str)
+      str))
+
 (defun company-calculate-candidates (prefix)
   (let ((candidates (cdr (assoc prefix company-candidates-cache)))
         (ignore-case (company-call-backend 'ignore-case)))
@@ -922,7 +929,8 @@ can retrieve meta-data for them."
         ;; auto-complete
         (save-excursion
           (goto-char company-point)
-          (company-complete-selection)
+          (let ((company--auto-completion t))
+            (company-complete-selection))
           nil))
        ((and (company--string-incremental-p company-prefix new-prefix)
              (company-require-match-p))
@@ -1334,7 +1342,10 @@ and invoke the normal binding."
   "Complete the selected candidate."
   (interactive)
   (when (company-manual-begin)
-    (company-finish (nth company-selection company-candidates))))
+    (let ((result (nth company-selection company-candidates)))
+      (when company--auto-completion
+        (setq result (company--safe-candidate result)))
+      (company-finish result))))
 
 (defun company-complete-common ()
   "Complete the common part of all candidates."