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

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

[elpa] master 89bd25a 12/12: Merge commit 'a197b072dc93dbad238f1dc70da01


From: Dmitry Gutov
Subject: [elpa] master 89bd25a 12/12: Merge commit 'a197b072dc93dbad238f1dc70da01e3775ebfb56' from company
Date: Sat, 15 Jul 2017 13:36:45 -0400 (EDT)

branch: master
commit 89bd25a95b75bb612c5e968baed5d90103a3139f
Merge: e9faca6 a197b07
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Merge commit 'a197b072dc93dbad238f1dc70da01e3775ebfb56' from company
---
 packages/company/NEWS.md                |  7 ++++
 packages/company/company-files.el       |  2 +-
 packages/company/company-template.el    | 68 +++++++++++++++++++++++++++------
 packages/company/company.el             | 20 +++++-----
 packages/company/test/core-tests.el     | 23 +++++++++--
 packages/company/test/template-tests.el | 51 +++++++++++++++++++++++++
 6 files changed, 146 insertions(+), 25 deletions(-)

diff --git a/packages/company/NEWS.md b/packages/company/NEWS.md
index 7d8ae3e..b219933 100644
--- a/packages/company/NEWS.md
+++ b/packages/company/NEWS.md
@@ -1,5 +1,12 @@
 # History of user-visible changes
 
+## 2017-07-15 (0.9.4)
+
+* Compatibility with native line numbers display in Emacs 26.
+* `company-files` allows completion after `=`.
+* `company-template` has a new shortcut (`C-d`) for deleting an unmodified
+  template field while cursor is on it.
+
 ## 2017-03-29 (0.9.3)
 
 * New variable `company-echo-truncate-lines`.
diff --git a/packages/company/company-files.el 
b/packages/company/company-files.el
index 4410281..c6102a1 100644
--- a/packages/company/company-files.el
+++ b/packages/company/company-files.el
@@ -70,7 +70,7 @@ The values should use the same format as 
`completion-ignored-extensions'."
          (begin (concat "\\(?:\\.\\{1,2\\}/\\|~/\\|" root "\\)")))
     (list (concat "\"\\(" begin "[^\"\n]*\\)")
           (concat "\'\\(" begin "[^\'\n]*\\)")
-          (concat "\\(?:[ \t]\\|^\\)\\(" begin "[^ \t\n]*\\)"))))
+          (concat "\\(?:[ \t=]\\|^\\)\\(" begin "[^ \t\n]*\\)"))))
 
 (defun company-files--grab-existing-name ()
   ;; Grab the file name.
diff --git a/packages/company/company-template.el 
b/packages/company/company-template.el
index 053429d..930e638 100644
--- a/packages/company/company-template.el
+++ b/packages/company/company-template.el
@@ -1,6 +1,6 @@
 ;;; company-template.el --- utility library for template expansion
 
-;; Copyright (C) 2009, 2010, 2014-2016 Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2010, 2014-2017 Free Software Foundation, Inc.
 
 ;; Author: Nikolaj Schumacher
 
@@ -35,6 +35,12 @@
     (define-key keymap (kbd "TAB") 'company-template-forward-field)
     keymap))
 
+(defvar company-template-field-map
+  (let ((keymap (make-sparse-keymap)))
+    (set-keymap-parent keymap company-template-nav-map)
+    (define-key keymap (kbd "C-d") 'company-template-clear-field)
+    keymap))
+
 (defvar-local company-template--buffer-templates nil)
 
 ;; interactive 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -55,19 +61,52 @@
 
 (defun company-template-forward-field ()
   (interactive)
+  (let ((start (point))
+        (next-field-start (company-template-find-next-field)))
+    (push-mark)
+    (goto-char next-field-start)
+    (company-template-remove-field (company-template-field-at start))))
+
+(defun company-template-clear-field ()
+  "Clear the field at point."
+  (interactive)
+  (let ((ovl (company-template-field-at (point))))
+    (when ovl
+      (company-template-remove-field ovl t)
+      (let ((after-clear-fn
+             (overlay-get ovl 'company-template-after-clear)))
+        (when (functionp after-clear-fn)
+          (funcall after-clear-fn))))))
+
+(defun company-template--after-clear-c-like-field ()
+  "Function that can be called after deleting a field of a c-like template.
+For c-like templates it is set as `after-post-fn' property on fields in
+`company-template-add-field'.  If there is a next field, delete everything
+from point to it.  If there is no field after point, remove preceding comma
+if present."
+  (let* ((pos (point))
+         (next-field-start (company-template-find-next-field))
+         (last-field-p (not (company-template-field-at next-field-start))))
+    (cond ((and (not last-field-p)
+                (< pos next-field-start)
+                (string-match "^[ ]*,+[ ]*$" (buffer-substring-no-properties
+                                              pos next-field-start)))
+           (delete-region pos next-field-start))
+          ((and last-field-p
+                (looking-back ",+[ ]*" (line-beginning-position)))
+           (delete-region (match-beginning 0) pos)))))
+
+(defun company-template-find-next-field ()
   (let* ((start (point))
-         (templates (company-template-templates-at (point)))
+         (templates (company-template-templates-at start))
          (minimum (apply 'max (mapcar 'overlay-end templates)))
          (fields (cl-loop for templ in templates
                           append (overlay-get templ 
'company-template-fields))))
-    (dolist (pos (mapcar 'overlay-start fields))
+    (dolist (pos (mapcar 'overlay-start fields) minimum)
       (and pos
-           (> pos (point))
+           (> pos start)
            (< pos minimum)
-           (setq minimum pos)))
-    (push-mark)
-    (goto-char minimum)
-    (company-template-remove-field (company-template-field-at start))))
+           (setq minimum pos)))))
 
 (defun company-template-field-at (&optional point)
   (cl-loop for ovl in (overlays-at (or point (point)))
@@ -93,10 +132,12 @@
         (delq templ company-template--buffer-templates))
   (delete-overlay templ))
 
-(defun company-template-add-field (templ beg end &optional display)
+(defun company-template-add-field (templ beg end &optional display 
after-clear-fn)
   "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."
+Leave point at the end of the field.
+AFTER-CLEAR-FN is a function that can be used to apply custom behavior
+after deleting a field in `company-template-remove-field'."
   (cl-assert templ)
   (when (> end (overlay-end templ))
     (move-overlay templ (overlay-start templ) end))
@@ -109,6 +150,10 @@ Leave point at the end of the field."
       (overlay-put ov 'display display))
     (overlay-put ov 'company-template-parent templ)
     (overlay-put ov 'insert-in-front-hooks '(company-template-insert-hook))
+    (when after-clear-fn
+      (overlay-put ov 'company-template-after-clear after-clear-fn))
+    (overlay-put ov 'keymap company-template-field-map)
+    (overlay-put ov 'priority 101)
     (push ov siblings)
     (overlay-put templ 'company-template-fields siblings)))
 
@@ -179,7 +224,8 @@ Leave point at the end of the field."
   (let ((last-pos (point)))
     (while (re-search-forward "\\([^,]+\\),?" end 'move)
       (when (zerop (car (parse-partial-sexp last-pos (point))))
-        (company-template-add-field templ last-pos (match-end 1))
+        (company-template-add-field templ last-pos (match-end 1) nil
+                                    
#'company-template--after-clear-c-like-field)
         (skip-chars-forward " ")
         (setq last-pos (point))))))
 
diff --git a/packages/company/company.el b/packages/company/company.el
index e48c2d9..4551bb6 100644
--- a/packages/company/company.el
+++ b/packages/company/company.el
@@ -5,7 +5,7 @@
 ;; Author: Nikolaj Schumacher
 ;; Maintainer: Dmitry Gutov <address@hidden>
 ;; URL: http://company-mode.github.io/
-;; Version: 0.9.3
+;; Version: 0.9.4
 ;; Keywords: abbrev, convenience, matching
 ;; Package-Requires: ((emacs "24.3"))
 
@@ -341,7 +341,7 @@ of the following:
 `prefix': The backend should return the text to be completed.  It must be
 text immediately before point.  Returning nil from this command passes
 control to the next backend.  The function should return `stop' if it
-should complete but cannot (e.g. if it is in the middle of a string).
+should complete but cannot (e.g. when in the middle of a symbol).
 Instead of a string, the backend may return a cons (PREFIX . LENGTH)
 where LENGTH is a number used in place of PREFIX's length when
 comparing against `company-minimum-prefix-length'.  LENGTH can also
@@ -835,7 +835,8 @@ means that `company-mode' is always turned on except in 
`message-mode' buffers."
     (cons (+ col (window-hscroll)) row)))
 
 (defun company--col-row (&optional pos)
-  (company--posn-col-row (posn-at-point pos)))
+  (let (display-line-numbers)
+    (company--posn-col-row (posn-at-point pos))))
 
 (defun company--row (&optional pos)
   (cdr (company--col-row pos)))
@@ -1509,8 +1510,9 @@ prefix match (same case) will be prioritized."
       (setq company-prefix new-prefix)
       (company-update-candidates c)
       c)
-     ((company-auto-complete-p (buffer-substring-no-properties
-                                (point) company-point))
+     ((and (> (point) company-point)
+           (company-auto-complete-p (buffer-substring-no-properties
+                                     (point) company-point)))
       ;; auto-complete
       (save-excursion
         (goto-char company-point)
@@ -2339,6 +2341,7 @@ If SHOW-VERSION is non-nil, show the version in the echo 
area."
   "Pop a buffer with information about completions at point."
   (interactive)
   (let* ((bb company-backends)
+         (mode (symbol-name major-mode))
          backend
          (prefix (cl-loop for b in bb
                           thereis (let ((company-backend b))
@@ -2364,6 +2367,8 @@ If SHOW-VERSION is non-nil, show the version in the echo 
area."
     (insert "\n")
     (insert "Used backend: " (pp-to-string backend))
     (insert "\n")
+    (insert "Major mode: " mode)
+    (insert "\n")
     (insert "Prefix: " (pp-to-string prefix))
     (insert "\n")
     (insert (message  "Completions:"))
@@ -2568,11 +2573,6 @@ If SHOW-VERSION is non-nil, show the version in the echo 
area."
           new
           (company-safe-substring old (+ offset (length new)))))
 
-(defsubst company--length-limit (lst limit)
-  (if (nthcdr limit lst)
-      limit
-    (length lst)))
-
 (defsubst company--window-height ()
   (if (fboundp 'window-screen-lines)
       (floor (window-screen-lines))
diff --git a/packages/company/test/core-tests.el 
b/packages/company/test/core-tests.el
index 977f1cf..6c846d2 100644
--- a/packages/company/test/core-tests.el
+++ b/packages/company/test/core-tests.el
@@ -157,16 +157,16 @@
   (let ((one (lambda (command &optional _)
                (cl-case command
                  (prefix "a")
-                 (candidates '("aa" "ca" "ba")))))
+                 (candidates (list "aa" "ca" "ba")))))
         (two (lambda (command &optional _)
                (cl-case command
                  (prefix "a")
-                 (candidates '("bb" "ab")))))
+                 (candidates (list "bb" "ab")))))
         (tri (lambda (command &optional _)
                (cl-case command
                  (prefix "a")
                  (sorted t)
-                 (candidates '("cc" "bc" "ac"))))))
+                 (candidates (list "cc" "bc" "ac"))))))
     (let ((company-backend (list one two tri :separate)))
       (should (company-call-backend 'sorted))
       (should-not (company-call-backend 'duplicates))
@@ -315,6 +315,23 @@
         (company-call 'backward-delete-char 1)
         (should (eq 2 company-candidates-length))))))
 
+(ert-deftest company-backspace-into-bad-prefix ()
+  (with-temp-buffer
+    (insert "ab")
+    (company-mode)
+    (let (company-frontends
+          (company-minimum-prefix-length 2)
+          (company-backends
+           (list (lambda (command &optional _)
+                   (cl-case command
+                     (prefix (buffer-substring (point-min) (point)))
+                     (candidates '("abcd" "abef")))))))
+      (let ((company-idle-delay 'now))
+        (company-auto-begin))
+      (company-call 'backward-delete-char-untabify 1)
+      (should (string= "a" (buffer-string)))
+      (should (null company-candidates)))))
+
 (ert-deftest company-auto-complete-explicit ()
   (with-temp-buffer
     (insert "ab")
diff --git a/packages/company/test/template-tests.el 
b/packages/company/test/template-tests.el
index da746bd..bcca8a8 100644
--- a/packages/company/test/template-tests.el
+++ b/packages/company/test/template-tests.el
@@ -117,3 +117,54 @@
       (company-template-objc-templatify text)
       (should (equal (buffer-string) text))
       (company-template-field-assert-text "(NSString)"))))
+
+(ert-deftest company-template-clear-field-c-like-first-arg ()
+  (with-temp-buffer
+    (let ((text "foo(int a, short b)"))
+      (insert text)
+      (company-template-c-like-templatify text)
+      (company-template-clear-field)
+      (should (equal "foo(short b)" (buffer-string))))))
+
+(ert-deftest company-template-clear-field-c-like-last-arg ()
+  (with-temp-buffer
+    (let ((text "foo(int a, short b)"))
+      (insert text)
+      (company-template-c-like-templatify text)
+      (insert "42")
+      (company-template-forward-field)
+      (company-template-clear-field)
+      (should (equal "foo(42)" (buffer-string))))))
+
+(ert-deftest company-template-clear-field-c-like-generic-1 ()
+  (with-temp-buffer
+    (let ((text "foo<TValue>(int a, short b)"))
+      (insert text)
+      (company-template-c-like-templatify text)
+      (company-template-clear-field)
+      (should (equal "foo<>(int a, short b)" (buffer-string))))))
+
+(ert-deftest company-template-clear-field-c-like-generic-2 ()
+  (with-temp-buffer
+    (let ((text "foo<TKey, TValue>(int a, short b)"))
+      (insert text)
+      (company-template-c-like-templatify text)
+      (company-template-clear-field)
+      (should (equal "foo<TValue>(int a, short b)" (buffer-string))))))
+
+(ert-deftest company-template-clear-field-objc-first-arg ()
+  (with-temp-buffer
+    (let ((text "createBookWithTitle:andAuthor:"))
+      (insert text)
+      (company-template-objc-templatify text)
+      (company-template-clear-field)
+      (should (equal "createBookWithTitle: andAuthor:arg1" (buffer-string))))))
+
+(ert-deftest company-template-insert-hook-c-like-field ()
+  (with-temp-buffer
+    (let ((text "foo(int a, short b)"))
+      (insert text)
+      (company-template-c-like-templatify text)
+      (let ((ovl (company-template-field-at (point))))
+        (company-template-insert-hook ovl nil)
+        (should (equal "foo(, short b)" (buffer-string)))))))



reply via email to

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