]> code.delx.au - gnu-emacs-elpa/commitdiff
Update company-clang-objc-templatify in line with the previous change
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 5 Apr 2015 18:48:07 +0000 (21:48 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 5 Apr 2015 18:48:53 +0000 (21:48 +0300)
NEWS.md
company-clang.el
company-template.el
test/clang-tests.el
test/template-tests.el

diff --git a/NEWS.md b/NEWS.md
index b464b8ea9c73a3d0a5cda44ec5986fc1efe7ef6b..ff928632ad92067705dabde68b9aec3b399a25db 100644 (file)
--- 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
index cc392e4c1085bbcd45512b3984e893b336f0983f..d0e2b84b8d2fac5d61281f97a6146d0d46fbec1a 100644 (file)
@@ -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.
index 9c42545c0b5d60a06bfa4c1f893ab2ef1f47a5de..d90458c19e867d52fcc57b16ab61204d446b26eb 100644 (file)
@@ -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
index abe690b386c1e953d6c0cc3f6c682f6361299a8c..2b8b105508e02f3baf36b5509759ee6ffbb1579a 100644 (file)
 (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
index 3917d2dca41cbfb20ba59dc48397f49f0b5f3133..4db3ce3cbff0d733b09525fb0aff879fbd5bbc79 100644 (file)
       (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)"))))