From 5fc4a9a0b0c75f4f128ad01ca8befd1928399c86 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 5 Apr 2015 21:48:07 +0300 Subject: [PATCH] Update company-clang-objc-templatify in line with the previous change --- NEWS.md | 1 + company-clang.el | 18 ------------------ company-template.el | 27 +++++++++++++++++++++++++++ test/clang-tests.el | 9 --------- test/template-tests.el | 17 +++++++++++++++++ 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/NEWS.md b/NEWS.md index b464b8ea9..ff928632a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ values with `argN` anymore ([#336](https://github.com/company-mode/company-mode/issues/336)). This affects `company-clang` and all third-party backends that use this function. +* Likewise for `company-clang-objc-templatify`. * `company-template-add-field` calling convention has changed. * New user option `company-dabbrev-ignore-invisible`. * `company-ropemacs` was removed. `ropemacs` supports completion via diff --git a/company-clang.el b/company-clang.el index cc392e4c1..d0e2b84b8 100644 --- a/company-clang.el +++ b/company-clang.el @@ -289,24 +289,6 @@ or automatically through a custom `company-clang-prefix-guesser'." ver)) 0))) -(defun company-clang-objc-templatify (selector) - (let* ((end (point-marker)) - (beg (- (point) (length selector) 1)) - (templ (company-template-declare-template beg end)) - (cnt 0)) - (save-excursion - (goto-char beg) - (catch 'stop - (while (search-forward ":" end t) - (when (looking-at "([^)]*) ?") - (delete-region (match-beginning 0) (match-end 0))) - (company-template-add-field templ (point) (format "arg%d" cnt)) - (if (< (point) end) - (insert " ") - (throw 'stop t)) - (cl-incf cnt)))) - (company-template-move-to-first templ))) - (defun company-clang (command &optional arg &rest ignored) "`company-mode' completion back-end for Clang. Clang is a parser for C and ObjC. Clang version 1.1 or newer is required. diff --git a/company-template.el b/company-template.el index 9c42545c0..d90458c19 100644 --- a/company-template.el +++ b/company-template.el @@ -183,5 +183,32 @@ Leave point at the end of the field." (skip-chars-forward " ") (setq last-pos (point)))))) +;; objc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun company-clang-objc-templatify (selector) + (let* ((end (point-marker)) + (beg (- (point) (length selector) 1)) + (templ (company-template-declare-template beg end)) + (cnt 0)) + (save-excursion + (goto-char beg) + (catch 'stop + (while (search-forward ":" end t) + (if (looking-at "\\(([^)]*)\\) ?") + (company-template-add-field templ (point) (match-end 1)) + ;; Not sure which conditions this case manifests under, but + ;; apparently it did before, when I wrote the first test for this + ;; function. FIXME: Revisit it. + (company-template-add-field templ (point) + (progn + (insert (format "arg%d" cnt)) + (point))) + (when (< (point) end) + (insert " ")) + (cl-incf cnt)) + (when (>= (point) end) + (throw 'stop t))))) + (company-template-move-to-first templ))) + (provide 'company-template) ;;; company-template.el ends here diff --git a/test/clang-tests.el b/test/clang-tests.el index abe690b38..2b8b10550 100644 --- a/test/clang-tests.el +++ b/test/clang-tests.el @@ -22,15 +22,6 @@ (require 'company-tests) (require 'company-clang) -(ert-deftest company-clang-objc-templatify () - (with-temp-buffer - (let ((text "createBookWithTitle:andAuthor:")) - (insert text) - (company-clang-objc-templatify text) - (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 diff --git a/test/template-tests.el b/test/template-tests.el index 3917d2dca..4db3ce3cb 100644 --- a/test/template-tests.el +++ b/test/template-tests.el @@ -100,3 +100,20 @@ (company-template-c-like-templatify text) (should (equal (buffer-string) "foo(int)")) (company-template-field-assert-text "int")))) + +(ert-deftest company-clang-objc-templatify-empty-args () + (with-temp-buffer + (let ((text "createBookWithTitle:andAuthor:")) + (insert text) + (company-clang-objc-templatify text) + (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-objc-templatify () + (with-temp-buffer + (let ((text "createBookWithTitle:(NSString) andAuthor:(id)")) + (insert text) + (company-clang-objc-templatify text) + (should (equal (buffer-string) text)) + (company-template-field-assert-text "(NSString)")))) -- 2.39.2