]> code.delx.au - gnu-emacs-elpa/commitdiff
Handle function pointers in annotation and template expansion
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 15 Mar 2015 23:06:06 +0000 (01:06 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 15 Mar 2015 23:06:32 +0000 (01:06 +0200)
Fixes #322

company-clang.el
company-template.el
test/clang-tests.el
test/template-tests.el

index 4929bad414561050e7f8fee7afe36b98ef85340e..0c4252eff46407572b7451b21e97ecbc3757b868 100644 (file)
@@ -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)
index 21ae01181f996c89944f16790826062369889d1e..2c1121775d154d93e3b89f9feb0af97a28ba4352 100644 (file)
@@ -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)))
index 09ba11429f23d0fe49d63df14a27950c0f8429b9..f2d55cc42d53f814cc0225d462c10fe03e6ca37f 100644 (file)
@@ -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)"))))
index 09548c4234e857c05098bfd81fc8584583ee5e35..d589ebdce534ea5e73e85ee06a83be0a9474ed97 100644 (file)
       (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))))))