From b0f206a2e8deb4c168d7dc989f4516741ae49a8c Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 16 Mar 2015 01:06:06 +0200 Subject: [PATCH] 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 4929bad41..0c4252eff 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 21ae01181..2c1121775 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 09ba11429..f2d55cc42 100644 --- a/test/clang-tests.el +++ b/test/clang-tests.el @@ -44,3 +44,7 @@ "shared_ptr<_Tp> make_shared(_Args &&__args...)"))) (should (equal (company-clang 'annotation str) "(_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 09548c423..d589ebdce 100644 --- a/test/template-tests.el +++ b/test/template-tests.el @@ -89,3 +89,12 @@ (forward-char -1) (should (equal "Dict" (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)))))) -- 2.39.2