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

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

[elpa] master b0f206a 020/173: Handle function pointers in annotation an


From: Dmitry Gutov
Subject: [elpa] master b0f206a 020/173: Handle function pointers in annotation and template expansion
Date: Thu, 23 Jun 2016 00:28:35 +0000 (UTC)

branch: master
commit b0f206a2e8deb4c168d7dc989f4516741ae49a8c
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Handle function pointers in annotation and template expansion
    
    Fixes #322
---
 company-clang.el       |   12 ++++++++++++
 company-template.el    |    2 ++
 test/clang-tests.el    |    4 ++++
 test/template-tests.el |    9 +++++++++
 4 files changed, 27 insertions(+)

diff --git a/company-clang.el b/company-clang.el
index 4929bad..0c4252e 100644
--- a/company-clang.el
+++ b/company-clang.el
@@ -144,6 +144,18 @@ or automatically through a custom 
`company-clang-prefix-guesser'."
   (get-text-property 0 'meta candidate))
 
 (defun company-clang--annotation (candidate)
+  (let ((ann (company-clang--annotation-1 candidate)))
+    (if (not (string-prefix-p "(*)" ann))
+        ann
+      (with-temp-buffer
+        (insert ann)
+        (search-backward ")")
+        (let ((pt (1+ (point))))
+          (forward-symbol 1)
+          (delete-region pt (point)))
+        (buffer-string)))))
+
+(defun company-clang--annotation-1 (candidate)
   (let ((meta (company-clang--meta candidate)))
     (cond
      ((null meta) nil)
diff --git a/company-template.el b/company-template.el
index 21ae011..2c11217 100644
--- a/company-template.el
+++ b/company-template.el
@@ -169,6 +169,8 @@ Leave point at the end of the field."
           (forward-char)
           (setq cnt (company-template--c-like-args templ angle-close
                                                    cnt))))
+      (when (looking-back "\\((\\*)\\)(" (line-beginning-position))
+        (delete-region (match-beginning 1) (match-end 1)))
       (when paren-open
         (goto-char paren-open)
         (company-template--c-like-args templ paren-close cnt)))
diff --git a/test/clang-tests.el b/test/clang-tests.el
index 09ba114..f2d55cc 100644
--- a/test/clang-tests.el
+++ b/test/clang-tests.el
@@ -44,3 +44,7 @@
               "shared_ptr<_Tp> make_shared<typename _Tp>(_Args &&__args...)")))
     (should (equal (company-clang 'annotation str)
                    "<typename _Tp>(_Args &&__args...)"))))
+
+(ert-deftest company-clang-func-ptr-annotation ()
+  (let ((str (propertize "foo" 'meta "void (*)(int) foo")))
+    (should (equal (company-clang 'annotation str) "(*)(int)"))))
diff --git a/test/template-tests.el b/test/template-tests.el
index 09548c4..d589ebd 100644
--- a/test/template-tests.el
+++ b/test/template-tests.el
@@ -89,3 +89,12 @@
       (forward-char -1)
       (should (equal "Dict<TKey, TValue>"
                      (overlay-get (company-template-field-at) 'display))))))
+
+(ert-deftest company-template-c-like-func-ptr ()
+  (with-temp-buffer
+    (let ((text "foo(*)(int)"))
+      (insert text)
+      (company-template-c-like-templatify text)
+      (should (equal "foo(arg0)" (buffer-string)))
+      (should (looking-at "arg0"))
+      (should (equal "int" (overlay-get (company-template-field-at) 
'display))))))



reply via email to

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