]> code.delx.au - gnu-emacs-elpa/commitdiff
Define and use `company-grab-symbol-cons'
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 4 Apr 2014 03:17:24 +0000 (06:17 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 4 Apr 2014 03:17:24 +0000 (06:17 +0300)
Closes #88

NEWS.md
company-clang.el
company.el

diff --git a/NEWS.md b/NEWS.md
index fae1a92bde95321124d45a286e319b582365c589..d0203d80ca567ff6dbd0ff71cb66b247498cd71a 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 ## Next
 
+* New function `company-grab-symbol-cons`.
 * `company-clang` fetches completion candidates asynchronously.
 * Added support for asynchronous back-ends (experimental).
 * Support for back-end command `crop` dropped (it was never documented).
index 42a548784c0a036ffbf4463641f043fd8039a1ca..4c7b0c7426f2acc4b4d27e7eadc47ee2c8ce60b0 100644 (file)
@@ -237,15 +237,9 @@ or automatically through a custom `company-clang-prefix-guesser'."
          (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) 2))))
-            (cons symbol t)
-          symbol)
-      'stop)))
+  (if company-clang-begin-after-member-access
+      (company-grab-symbol-cons "\\.\\|->\\|::" 2)
+    (company-grab-symbol)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -311,7 +305,7 @@ passed via standard input."
                  buffer-file-name
                  company-clang-executable
                  (not (company-in-string-or-comment))
-                 (company-clang--prefix)))
+                 (or (company-clang--prefix) 'stop)))
     (candidates (cons :async
                       (lambda (cb) (company-clang--candidates arg cb))))
     (meta       (company-clang--meta arg))
index 8f29d4d053c76463710efaa2d24ce16e5357a8b8..24b00cb21974d60b18e05e3f8f656fc10b788f7e 100644 (file)
@@ -784,6 +784,17 @@ means that `company-mode' is always turned on except in `message-mode' buffers."
     (unless (and (char-after) (eq (char-syntax (char-after)) ?w))
       "")))
 
+(defun company-grab-symbol-cons (idle-begin-after-re &optional max-len)
+  (let ((symbol (company-grab-symbol)))
+    (when symbol
+      (save-excursion
+        (forward-char (- (length symbol)))
+        (if (looking-back idle-begin-after-re (if max-len
+                                                  (- (point) max-len)
+                                                (line-beginning-position)))
+            (cons symbol t)
+          symbol)))))
+
 (defun company-in-string-or-comment ()
   (let ((ppss (syntax-ppss)))
     (or (car (setq ppss (nthcdr 3 ppss)))