From 06ca7849f29189687aa380a2c3d9c84c7859aabe Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Fri, 22 Mar 2013 09:07:04 +0400 Subject: [PATCH] Introduce `company--auto-completion', rename 'common to 'safe --- NEWS.md | 5 +++-- company-clang.el | 6 +++--- company-eclim.el | 4 ++-- company.el | 21 ++++++++++++++++----- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index f53a9fe43..157e6def7 100644 --- 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; `` 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. diff --git a/company-clang.el b/company-clang.el index 9dbd12d92..fc426d3b7 100644 --- a/company-clang.el +++ b/company-clang.el @@ -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))))) diff --git a/company-eclim.el b/company-eclim.el index c481dd9d9..fd74a013a 100644 --- a/company-eclim.el +++ b/company-eclim.el @@ -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))))) diff --git a/company.el b/company.el index fe87eed69..ff4f29f68 100644 --- a/company.el +++ b/company.el @@ -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." -- 2.39.2