emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 21/35: Define and use `company-grab-symbol-cons'


From: Dmitry Gutov
Subject: [elpa] 21/35: Define and use `company-grab-symbol-cons'
Date: Sat, 19 Apr 2014 10:12:18 +0000

dgutov pushed a commit to branch master
in repository elpa.

commit bc1b047226164ef40834b4e30f7767dcd2e56c39
Author: Dmitry Gutov <address@hidden>
Date:   Fri Apr 4 06:17:24 2014 +0300

    Define and use `company-grab-symbol-cons'
    
    Closes #88
---
 NEWS.md          |    1 +
 company-clang.el |   14 ++++----------
 company.el       |   11 +++++++++++
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index fae1a92..d0203d8 100644
--- 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).
diff --git a/company-clang.el b/company-clang.el
index 42a5487..4c7b0c7 100644
--- a/company-clang.el
+++ b/company-clang.el
@@ -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))
diff --git a/company.el b/company.el
index 8f29d4d..24b00cb 100644
--- a/company.el
+++ b/company.el
@@ -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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]