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
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.
(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
(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
(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)"))))