[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master f45b11e 033/173: Don't replace the default argument values
From: |
Dmitry Gutov |
Subject: |
[elpa] master f45b11e 033/173: Don't replace the default argument values with `argN` anymore |
Date: |
Thu, 23 Jun 2016 00:28:36 +0000 (UTC) |
branch: master
commit f45b11ea6e65872ae5c42cff56203dd72247cde5
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Don't replace the default argument values with `argN` anymore
Closes #336
---
NEWS.md | 5 +++++
company-template.el | 34 ++++++++++++----------------------
test/template-tests.el | 40 +++++++++++++++++++++-------------------
3 files changed, 38 insertions(+), 41 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index 755e1fe..b464b8e 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,11 @@
## Next
+* `company-template-c-like-templatify` does not replace the default argument
+ 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.
+* `company-template-add-field` calling convention has changed.
* New user option `company-dabbrev-ignore-invisible`.
* `company-ropemacs` was removed. `ropemacs` supports completion via
`completion-at-point-functions` starting with version 0.8.
diff --git a/company-template.el b/company-template.el
index 2c11217..9c42545 100644
--- a/company-template.el
+++ b/company-template.el
@@ -1,6 +1,6 @@
;;; company-template.el
-;; Copyright (C) 2009, 2010, 2014 Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2010, 2014-2015 Free Software Foundation, Inc.
;; Author: Nikolaj Schumacher
@@ -93,16 +93,14 @@
(delq templ company-template--buffer-templates))
(delete-overlay templ))
-(defun company-template-add-field (templ pos text &optional display)
- "Add new field to template TEMPL at POS, inserting TEXT.
+(defun company-template-add-field (templ beg end &optional display)
+ "Add new field to template TEMPL spanning from BEG to END.
When DISPLAY is non-nil, set the respective property on the overlay.
Leave point at the end of the field."
(cl-assert templ)
- (goto-char pos)
- (insert text)
- (when (> (point) (overlay-end templ))
- (move-overlay templ (overlay-start templ) (point)))
- (let ((ov (make-overlay pos (+ pos (length text))))
+ (when (> end (overlay-end templ))
+ (move-overlay templ (overlay-start templ) end))
+ (let ((ov (make-overlay beg end))
(siblings (overlay-get templ 'company-template-fields)))
;; (overlay-put ov 'evaporate t)
(overlay-put ov 'intangible t)
@@ -149,7 +147,6 @@ Leave point at the end of the field."
(defun company-template-c-like-templatify (call)
(let* ((end (point-marker))
(beg (- (point) (length call)))
- (cnt 0)
(templ (company-template-declare-template beg end))
paren-open paren-close)
(with-syntax-table (make-syntax-table (syntax-table))
@@ -167,31 +164,24 @@ Leave point at the end of the field."
(forward-char 1)
(backward-sexp)
(forward-char)
- (setq cnt (company-template--c-like-args templ angle-close
- cnt))))
+ (company-template--c-like-args templ angle-close)))
(when (looking-back "\\((\\*)\\)(" (line-beginning-position))
(delete-region (match-beginning 1) (match-end 1)))
(when paren-open
(goto-char paren-open)
- (company-template--c-like-args templ paren-close cnt)))
+ (company-template--c-like-args templ paren-close)))
(if (overlay-get templ 'company-template-fields)
(company-template-move-to-first templ)
(company-template-remove-template templ)
(goto-char end))))
-(defun company-template--c-like-args (templ end counter)
+(defun company-template--c-like-args (templ end)
(let ((last-pos (point)))
(while (re-search-forward "\\([^,]+\\),?" end 'move)
(when (zerop (car (parse-partial-sexp last-pos (point))))
- (let ((sig (buffer-substring-no-properties last-pos (match-end 1))))
- (save-excursion
- (company-template-add-field templ last-pos
- (format "arg%d" counter) sig)
- (delete-region (point) (+ (point) (length sig))))
- (skip-chars-forward " ")
- (setq last-pos (point))
- (cl-incf counter)))))
- counter)
+ (company-template-add-field templ last-pos (match-end 1))
+ (skip-chars-forward " ")
+ (setq last-pos (point))))))
(provide 'company-template)
;;; company-template.el ends here
diff --git a/test/template-tests.el b/test/template-tests.el
index d589ebd..3917d2d 100644
--- a/test/template-tests.el
+++ b/test/template-tests.el
@@ -22,6 +22,13 @@
(require 'company-tests)
(require 'company-template)
+(defun company-template-field-assert-text (str &optional pos)
+ (let ((field (company-template-field-at pos)))
+ (should (equal (buffer-substring-no-properties
+ (overlay-start field)
+ (overlay-end field))
+ str))))
+
(ert-deftest company-template-removed-after-the-last-jump ()
(with-temp-buffer
(insert "{ }")
@@ -29,8 +36,8 @@
(let ((tpl (company-template-declare-template (point) (1- (point-max)))))
(save-excursion
(dotimes (_ 2)
- (insert " ")
- (company-template-add-field tpl (point) "foo")))
+ (insert " foo")
+ (company-template-add-field tpl (- (point) 3) (point))))
(company-call 'template-forward-field)
(should (= 3 (point)))
(company-call 'template-forward-field)
@@ -46,8 +53,8 @@
(goto-char 2)
(let ((tpl (company-template-declare-template (point) (1- (point-max)))))
(save-excursion
- (insert " ")
- (company-template-add-field tpl (point) "bar"))
+ (insert " bar")
+ (company-template-add-field tpl (- (point) 3) (point)))
(company-call 'template-move-to-first tpl)
(should (= 3 (point)))
(dolist (c (string-to-list "tee"))
@@ -64,37 +71,32 @@
(let ((text "foo(int a, short b)"))
(insert text)
(company-template-c-like-templatify text)
- (should (equal "foo(arg0, arg1)" (buffer-string)))
- (should (looking-at "arg0"))
- (should (equal "int a"
- (overlay-get (company-template-field-at) 'display))))))
+ (should (equal "foo(int a, short b)" (buffer-string)))
+ (company-template-field-assert-text "int a"))))
(ert-deftest company-template-c-like-templatify-trims-after-closing-paren ()
(with-temp-buffer
(let ((text "foo(int a, short b)!@ #1334 a"))
(insert text)
(company-template-c-like-templatify text)
- (should (equal "foo(arg0, arg1)" (buffer-string)))
- (should (looking-at "arg0")))))
+ (should (equal "foo(int a, short b)" (buffer-string)))
+ (company-template-field-assert-text "int a"))))
(ert-deftest company-template-c-like-templatify-generics ()
(with-temp-buffer
(let ((text "foo<TKey, TValue>(int i, Dict<TKey, TValue>, long l)"))
(insert text)
(company-template-c-like-templatify text)
- (should (equal "foo<arg0, arg1>(arg2, arg3, arg4)" (buffer-string)))
- (should (looking-at "arg0"))
- (should (equal "TKey" (overlay-get (company-template-field-at)
'display)))
- (search-forward "arg3")
+ (should (equal (buffer-string) text))
+ (company-template-field-assert-text "TKey")
+ (search-forward "Dict")
(forward-char -1)
- (should (equal "Dict<TKey, TValue>"
- (overlay-get (company-template-field-at) 'display))))))
+ (company-template-field-assert-text "Dict<TKey, TValue>"))))
(ert-deftest company-template-c-like-func-ptr ()
(with-temp-buffer
(let ((text "foo(*)(int)"))
(insert text)
(company-template-c-like-templatify text)
- (should (equal "foo(arg0)" (buffer-string)))
- (should (looking-at "arg0"))
- (should (equal "int" (overlay-get (company-template-field-at)
'display))))))
+ (should (equal (buffer-string) "foo(int)"))
+ (company-template-field-assert-text "int"))))
- [elpa] master 4646d35 078/173: Allow advising company-dabbrev(-code)? regex generation, (continued)
- [elpa] master 4646d35 078/173: Allow advising company-dabbrev(-code)? regex generation, Dmitry Gutov, 2016/06/22
- [elpa] master ed3e711 084/173: company-yasnippet: Disable cache (#422), Dmitry Gutov, 2016/06/22
- [elpa] master 7d14350 051/173: company-eclim-executable: Pick up the value of eclim-executable, if present, Dmitry Gutov, 2016/06/22
- [elpa] master 9e66366 067/173: Fix #404 by blanking out line-prefix again, Dmitry Gutov, 2016/06/22
- [elpa] master 433ae92 072/173: Retouch the docstring further, Dmitry Gutov, 2016/06/22
- [elpa] master 02d0e74 074/173: Modernize the Commentary a bit, Dmitry Gutov, 2016/06/22
- [elpa] master 7d005c4 080/173: Document some company-grab- functions, Dmitry Gutov, 2016/06/22
- [elpa] master 07a4e9e 094/173: Travis: Try to fix the "held broken packages", Dmitry Gutov, 2016/06/22
- [elpa] master 7779820 092/173: Remove completions without annotations when considering duplicates, Dmitry Gutov, 2016/06/22
- [elpa] master f1ca92f 042/173: Update NEWS [ci skip], Dmitry Gutov, 2016/06/22
- [elpa] master f45b11e 033/173: Don't replace the default argument values with `argN` anymore,
Dmitry Gutov <=
- [elpa] master 35f4178 043/173: Allow including window-start in the doc-buffer return value, Dmitry Gutov, 2016/06/22
- [elpa] master b0a946d 052/173: company-clang--start-process: Only erase buffer when there's no existing process, Dmitry Gutov, 2016/06/22
- [elpa] master 5e29e41 003/173: company-files--grab-existing-name: Check if the file is remote, Dmitry Gutov, 2016/06/22
- [elpa] master 7579ced 055/173: Fix a bug reference, Dmitry Gutov, 2016/06/22
- [elpa] master 05987e6 056/173: Fix #362 (arbitrary jumping of point), Dmitry Gutov, 2016/06/22
- [elpa] master 679846a 065/173: Makefile: allow package and elpa targets to run without git, Dmitry Gutov, 2016/06/22
- [elpa] master 33f7bbc 077/173: Fix some compilation warnings, Dmitry Gutov, 2016/06/22
- [elpa] master d39b956 059/173: Introduce company-indent-or-complete-common, Dmitry Gutov, 2016/06/22
- [elpa] master 478f124 087/173: company-dabbrev-code-modes: Improve Customize labels, Dmitry Gutov, 2016/06/22
- [elpa] master 4a6eea9 089/173: Use company-dabbrev-char-regexp more consistently (#433), Dmitry Gutov, 2016/06/22