]> code.delx.au - gnu-emacs-elpa/commitdiff
Close #19
authorDmitry Gutov <dgutov@yandex.ru>
Mon, 6 May 2013 06:19:39 +0000 (10:19 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Mon, 6 May 2013 06:21:00 +0000 (10:21 +0400)
NEWS.md
company-clang.el
company.el

diff --git a/NEWS.md b/NEWS.md
index db8cbe0521c437bdf2e056bb51177732148893fa..d8a0c9113b982b90a0681e3d43a5643bf3e232f3 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
 
 ## Next
 
+* `company-backends`: `prefix` command can return `t` in the cdr.
+* `company-clang-begin-after-member-access`: New option.
 * Mouse click outside the tooltip aborts completion.
 * `company-clang` uses standard input to pass the contents of current buffer to
   Clang 2.9+, otherwise saves the buffer and passes the path to the file.
index 947afe2394b70fc949c0e9938df452a63944cf23..6abebe7e36fd4c17d87acb85227f39f70cce916c 100644 (file)
   "Location of clang executable."
   :type 'file)
 
+(defcustom company-clang-begin-after-member-access t
+  "When non-nil, automatic completion will start whenever the current symbol
+is preceded by \".\" or \"->\", ignoring `company-minimum-prefix-length'.
+
+If `company-begin-commands' is a list, it should include `c-electric-lt-gt'.")
+
 (defcustom company-clang-arguments nil
   "Additional arguments to pass to clang when completing.
 Prefix files (-include ...) can be selected with
@@ -201,6 +207,17 @@ Prefix files (-include ...) can be selected with
          prefix
          (company-clang--build-complete-args (- (point) (length prefix)))))
 
+(defun company-clang--prefix ()
+  (let ((symbol (company-grab-symbol)))
+    (if symbol
+        (if (and company-clang-begin-after-member-access
+                 (save-excursion
+                   (forward-char (- (length symbol)))
+                   (looking-back "\\.\\|->" (- (point) 3))))
+            (cons symbol t)
+          symbol)
+      'stop)))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defconst company-clang-required-version 1.1)
@@ -263,7 +280,7 @@ input."
                  buffer-file-name
                  company-clang-executable
                  (not (company-in-string-or-comment))
-                 (or (company-grab-symbol) 'stop)))
+                 (company-clang--prefix)))
     (candidates (company-clang--candidates arg))
     (meta (gethash arg company-clang--meta-cache))
     (crop (and (string-match ":\\|(" arg)
index 2a9b9db32cdb25715e557c6b89e879700fea15a0..901aac1cb6dd7c99ad733fe2f7c3ad5571381ad8 100644 (file)
@@ -280,13 +280,12 @@ 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
 of the following:
 
-`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\).  If the returned value is only
-part of the prefix (e.g. the part after \"->\" in C), the back-end may return a
-cons of prefix and prefix length, which is then used in the
-`company-minimum-prefix-length' test.
+`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\).  Instead of a string, the back-end may return a
+cons where car is the prefix and cdr is used in `company-minimum-prefix-length'
+test. It's either number or t, in which case the test automatically succeeds.
 
 `candidates': The second argument is the prefix to be completed.  The
 return value should be a list of candidates that start with the prefix.
@@ -951,8 +950,9 @@ can retrieve meta-data for them."
 (defun company--good-prefix-p (prefix)
   (and (or (company-explicit-action-p)
            (unless (eq prefix 'stop)
-             (>= (or (cdr-safe prefix) (length prefix))
-                 company-minimum-prefix-length)))
+             (or (eq (cdr-safe prefix) t)
+                 (>= (or (cdr-safe prefix) (length prefix))
+                     company-minimum-prefix-length))))
        (stringp (or (car-safe prefix) prefix))))
 
 (defun company--continue ()