From: Dmitry Gutov Date: Wed, 7 Jan 2015 17:49:47 +0000 (+0300) Subject: Support template functions in company-clang annotations X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/eef07a5dda89d7af9f9d2838e8f773966b6d46c7 Support template functions in company-clang annotations Fixes #271 --- diff --git a/company-clang.el b/company-clang.el index f30bf1493..459056d0b 100644 --- a/company-clang.el +++ b/company-clang.el @@ -150,7 +150,13 @@ or automatically through a custom `company-clang-prefix-guesser'." ((string-match "[^:]:[^:]" meta) (substring meta (1+ (match-beginning 0)))) ((string-match "\\((.*)[ a-z]*\\'\\)" meta) - (match-string 1 meta))))) + (let ((paren (match-beginning 1))) + (if (not (eq (aref meta (1- paren)) ?>)) + (match-string 1 meta) + (with-temp-buffer + (insert meta) + (goto-char paren) + (substring meta (1- (search-backward "<")))))))))) (defun company-clang--strip-formatting (text) (replace-regexp-in-string diff --git a/test/clang-tests.el b/test/clang-tests.el index 4d23a299c..c8c03b780 100644 --- a/test/clang-tests.el +++ b/test/clang-tests.el @@ -9,3 +9,17 @@ (should (equal "createBookWithTitle:arg0 andAuthor:arg1" (buffer-string))) (should (looking-at "arg0")) (should (null (overlay-get (company-template-field-at) 'display)))))) + +(ert-deftest company-clang-simple-annotation () + (let ((str (propertize + "foo" 'meta + "wchar_t * wmemchr(wchar_t *__p, wchar_t __c, size_t __n)"))) + (should (equal (company-clang 'annotation str) + "(wchar_t *__p, wchar_t __c, size_t __n)")))) + +(ert-deftest company-clang-generic-annotation () + (let ((str (propertize + "foo" 'meta + "shared_ptr<_Tp> make_shared(_Args &&__args...)"))) + (should (equal (company-clang 'annotation str) + "(_Args &&__args...)"))))