emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 5fc4a9a 034/173: Update company-clang-objc-templatify in l


From: Dmitry Gutov
Subject: [elpa] master 5fc4a9a 034/173: Update company-clang-objc-templatify in line with the previous change
Date: Thu, 23 Jun 2016 00:28:36 +0000 (UTC)

branch: master
commit 5fc4a9a0b0c75f4f128ad01ca8befd1928399c86
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    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 b464b8e..ff92863 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 cc392e4..d0e2b84 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 9c42545..d90458c 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 abe690b..2b8b105 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 3917d2d..4db3ce3 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)"))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]