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

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

[elpa] master 5deda28 31/31: Merge commit '3eda0ba23921d43b733f7975e56d4


From: Dmitry Gutov
Subject: [elpa] master 5deda28 31/31: Merge commit '3eda0ba23921d43b733f7975e56d490a34b9f30b' from company
Date: Sun, 14 Apr 2019 22:06:21 -0400 (EDT)

branch: master
commit 5deda282729c23fe9f2751724ae2f294fd7c4a97
Merge: a2911f6 3eda0ba
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Merge commit '3eda0ba23921d43b733f7975e56d490a34b9f30b' from company
---
 packages/company/NEWS.md            |  18 +++++
 packages/company/company-clang.el   |  15 ++--
 packages/company/company-tng.el     |  20 ++++++
 packages/company/company.el         | 133 +++++++++++++++++++++---------------
 packages/company/test/capf-tests.el |  32 +++++----
 packages/company/test/core-tests.el |  28 +++++++-
 6 files changed, 170 insertions(+), 76 deletions(-)

diff --git a/packages/company/NEWS.md b/packages/company/NEWS.md
index 72f86d7..8404398 100644
--- a/packages/company/NEWS.md
+++ b/packages/company/NEWS.md
@@ -1,5 +1,23 @@
 # History of user-visible changes
 
+## 2019-04-15 (0.9.10)
+
+* `company-clang`: better compatibility with Clang 8
+  ([#885](https://github.com/company-mode/company-mode/issues/885)).
+* The change in `company-clang` regarding identity #defines is reverted because
+  it affected other completions as well
+  ([#884](https://github.com/company-mode/company-mode/issues/884)).
+* `company-idle-delay` now accepts a function which generates the idle time or
+  nil indicating no idle completion.
+* Add custom variable `company-show-numbers-function` to make numbers of
+  candidates customizable. 
+* When a symbol is already typed in full, calling `M-x company-complete` will
+  now run its post-completion action (e.g. inserting method parameters
+  template). Calling `M-x company-manual-begin` or invoking a backend command
+  directly will show the popup
+  ([#150](https://github.com/company-mode/company-mode/issues/150),
+  [#476](https://github.com/company-mode/company-mode/issues/476)).
+
 ## 2018-12-13 (0.9.9)
 
 * Fix for the changes in the previous release.
diff --git a/packages/company/company-clang.el 
b/packages/company/company-clang.el
index d43eebb..c0899b6 100644
--- a/packages/company/company-clang.el
+++ b/packages/company/company-clang.el
@@ -1,6 +1,6 @@
 ;;; company-clang.el --- company-mode completion backend for Clang  -*- 
lexical-binding: t -*-
 
-;; Copyright (C) 2009, 2011, 2013-2017  Free Software Foundation, Inc.
+;; Copyright (C) 2009, 2011, 2013-2019  Free Software Foundation, Inc.
 
 ;; Author: Nikolaj Schumacher
 
@@ -111,7 +111,7 @@ or automatically through a custom 
`company-clang-prefix-guesser'."
 ;; TODO: Handle Pattern (syntactic hints would be neat).
 ;; Do we ever see OVERLOAD (or OVERRIDE)?
 (defconst company-clang--completion-pattern
-  "^COMPLETION: \\_<\\(%s[a-zA-Z0-9_:]*\\)\\(?: : \\(.*\\)$\\)?$")
+  "^COMPLETION: \\_<\\(%s[a-zA-Z0-9_:]*\\)\\(?:\\(?: (InBase)\\)? : 
\\(.*\\)$\\)?$")
 
 (defconst company-clang--error-buffer-name "*clang-error*")
 
@@ -134,12 +134,11 @@ or automatically through a custom 
`company-clang-prefix-guesser'."
           (when (string-match ":" match)
             (setq match (substring match 0 (match-beginning 0)))))
         (let ((meta (match-string-no-properties 2)))
-          (unless (equal match meta)
-            (when meta
-              (put-text-property 0 1 'meta
-                                 (company-clang--strip-formatting meta)
-                                 match))
-            (push match lines)))))
+          (when (and meta (not (string= match meta)))
+            (put-text-property 0 1 'meta
+                               (company-clang--strip-formatting meta)
+                               match)))
+        (push match lines)))
     lines))
 
 (defun company-clang--meta (candidate)
diff --git a/packages/company/company-tng.el b/packages/company/company-tng.el
index a1d7173..9b495c6 100644
--- a/packages/company/company-tng.el
+++ b/packages/company/company-tng.el
@@ -63,6 +63,26 @@
 ;;
 ;; We recommend to disable `company-require-match' to allow free typing at any
 ;; point.
+;;
+;; By default, company-tng doesn't work well with backends that use
+;; `post-completion' (for actions such as expanding snippets in
+;; company-yasnippet or company-template). In company-tng, completion 
candidates
+;; are inserted into the buffer as the user selects them and the completion is
+;; finished implicitly when the user continues typing after selecting a
+;; candidate. Modifying the buffer (by expanding a snippet) when the user
+;; continues typing would be surprising and undesirable, since the candidate 
was
+;; already inserted into the buffer. For this reason company-tng disables
+;; `post-completion' in all backends.
+;;
+;; YASnippet and company-tng both use TAB, which causes conflicts. The
+;; recommended way to use YASnippet with company-tng is to choose a different
+;; key for expanding a snippet and moving to the next snippet field:
+;;
+;;   (define-key yas-minor-mode-map "\C-j" 'yas-expand)
+;;   (define-key yas-keymap "\C-j" 'yas-next-field-or-maybe-expand)
+;;   (dolist (keymap (list yas-minor-mode-map yas-keymap))
+;;     (define-key keymap (kbd "TAB") nil)
+;;     (define-key keymap [(tab)] nil))
 
 ;;; Code:
 
diff --git a/packages/company/company.el b/packages/company/company.el
index 47f353e..44177e7 100644
--- a/packages/company/company.el
+++ b/packages/company/company.el
@@ -1,11 +1,11 @@
 ;;; company.el --- Modular text completion framework  -*- lexical-binding: t 
-*-
 
-;; Copyright (C) 2009-2018  Free Software Foundation, Inc.
+;; Copyright (C) 2009-2019  Free Software Foundation, Inc.
 
 ;; Author: Nikolaj Schumacher
 ;; Maintainer: Dmitry Gutov <address@hidden>
 ;; URL: http://company-mode.github.io/
-;; Version: 0.9.9
+;; Version: 0.9.10
 ;; Keywords: abbrev, convenience, matching
 ;; Package-Requires: ((emacs "24.3"))
 
@@ -584,6 +584,7 @@ The prefix still has to satisfy 
`company-minimum-prefix-length' before that
 happens.  The value of nil means no idle completion."
   :type '(choice (const :tag "never (nil)" nil)
                  (const :tag "immediate (0)" 0)
+                 (function :tag "Predicate function")
                  (number :tag "seconds")))
 
 (defcustom company-tooltip-idle-delay .5
@@ -632,6 +633,14 @@ commands in the `company-' namespace, abort completion."
   :type '(choice (const :tag "off" nil)
                  (const :tag "on" t)))
 
+(defcustom company-show-numbers-function #'company--show-numbers
+  "Function called to get custom quick-access numbers for the first then 
candidates.
+
+If nil falls back to default function that generates 1...8, 9, 0. The function 
get
+the number of candidates (from 1 to 10 means 1st to 10th candidate) and should
+return a string prefixed with one space."
+  :type 'function)
+
 (defcustom company-selection-wrap-around nil
   "If enabled, selecting item before first or after last wraps around."
   :type '(choice (const :tag "off" nil)
@@ -832,7 +841,7 @@ means that `company-mode' is always turned on except in 
`message-mode' buffers."
 (defun company--company-command-p (keys)
   "Checks if the keys are part of company's overriding keymap"
   (or (equal [company-dummy-event] keys)
-      (lookup-key company-my-keymap keys)))
+      (commandp (lookup-key company-my-keymap keys))))
 
 ;; Hack:
 ;; Emacs calculates the active keymaps before reading the event.  That means we
@@ -1207,9 +1216,8 @@ can retrieve meta-data for them."
                   common))
             (car company-candidates)))))
 
-(defun company-calculate-candidates (prefix)
-  (let ((candidates (cdr (assoc prefix company-candidates-cache)))
-        (ignore-case (company-call-backend 'ignore-case)))
+(defun company-calculate-candidates (prefix ignore-case)
+  (let ((candidates (cdr (assoc prefix company-candidates-cache))))
     (or candidates
         (when company-candidates-cache
           (let ((len (length prefix))
@@ -1227,17 +1235,17 @@ can retrieve meta-data for them."
           ;; Save in cache.
           (push (cons prefix candidates) company-candidates-cache)))
     ;; Only now apply the predicate and transformers.
-    (setq candidates (company--postprocess-candidates candidates))
-    (when candidates
-      (if (or (cdr candidates)
-              (not (eq t (compare-strings (car candidates) nil nil
-                                          prefix nil nil ignore-case))))
-          candidates
-        ;; Already completed and unique; don't start.
-        t))))
+    (company--postprocess-candidates candidates)))
+
+(defun company--unique-match-p (candidates prefix ignore-case)
+  (and candidates
+       (not (cdr candidates))
+       (eq t (compare-strings (car candidates) nil nil
+                              prefix nil nil ignore-case))))
 
 (defun company--fetch-candidates (prefix)
   (let* ((non-essential (not (company-explicit-action-p)))
+         (inhibit-redisplay t)
          (c (if (or company-selection-changed
                     ;; FIXME: This is not ideal, but we have not managed to 
deal
                     ;; with these situations in a better way yet.
@@ -1246,8 +1254,7 @@ can retrieve meta-data for them."
               (company-call-backend-raw 'candidates prefix))))
     (if (not (eq (car c) :async))
         c
-      (let ((res 'none)
-            (inhibit-redisplay t))
+      (let ((res 'none))
         (funcall
          (cdr c)
          (lambda (candidates)
@@ -1538,14 +1545,14 @@ prefix match (same case) will be prioritized."
     ;; Don't complete existing candidates, fetch new ones.
     (setq company-candidates-cache nil))
   (let* ((new-prefix (company-call-backend 'prefix))
+         (ignore-case (company-call-backend 'ignore-case))
          (c (when (and (company--good-prefix-p new-prefix)
                        (setq new-prefix (company--prefix-str new-prefix))
                        (= (- (point) (length new-prefix))
                           (- company-point (length company-prefix))))
-              (company-calculate-candidates new-prefix))))
+              (company-calculate-candidates new-prefix ignore-case))))
     (cond
-     ((eq c t)
-      ;; t means complete/unique.
+     ((company--unique-match-p c new-prefix ignore-case)
       ;; Handle it like completion was aborted, to differentiate from user
       ;; calling one of Company's commands to insert the candidate,
       ;; not to trigger template expansion, etc.
@@ -1583,23 +1590,29 @@ prefix match (same case) will be prioritized."
               (company--multi-backend-adapter backend 'prefix)))
       (when prefix
         (when (company--good-prefix-p prefix)
-          (setq company-prefix (company--prefix-str prefix)
-                company-backend backend
-                c (company-calculate-candidates company-prefix))
-          (if (not (consp c))
-              (progn
-                (when company--manual-action
-                  (message "No completion found"))
-                (when (eq c t)
-                  ;; t means complete/unique.
-                  ;; Run the hooks anyway, to e.g. clear the cache.
-                  (company-cancel 'unique)))
-            (when company--manual-action
-              (setq company--manual-prefix prefix))
-            (company-update-candidates c)
-            (run-hook-with-args 'company-completion-started-hook
-                                (company-explicit-action-p))
-            (company-call-frontends 'show)))
+          (let ((ignore-case (company-call-backend 'ignore-case)))
+            (setq company-prefix (company--prefix-str prefix)
+                  company-backend backend
+                  c (company-calculate-candidates company-prefix ignore-case))
+            (cond
+             ((and (company--unique-match-p c company-prefix ignore-case)
+                   (if company--manual-action
+                       ;; If `company-manual-begin' was called, the user
+                       ;; really wants something to happen.  Otherwise...
+                       (ignore (message "Sole completion"))
+                     t))
+              ;; ...abort and run the hooks, e.g. to clear the cache.
+              (company-cancel 'unique))
+             ((null c)
+              (when company--manual-action
+                (message "No completion found")))
+             (t ;; We got completions!
+              (when company--manual-action
+                (setq company--manual-prefix prefix))
+              (company-update-candidates c)
+              (run-hook-with-args 'company-completion-started-hook
+                                  (company-explicit-action-p))
+              (company-call-frontends 'show)))))
         (cl-return c)))))
 
 (defun company--perform ()
@@ -1636,8 +1649,6 @@ prefix match (same case) will be prioritized."
     (company-call-frontends 'hide)
     (company-enable-overriding-keymap nil)
     (when prefix
-      ;; FIXME: RESULT can also be e.g. `unique'.  We should call
-      ;; `company-completion-finished-hook' in that case, with right argument.
       (if (stringp result)
           (let ((company-backend backend))
             (run-hook-with-args 'company-completion-finished-hook result)
@@ -1692,25 +1703,28 @@ prefix match (same case) will be prioritized."
               (company--perform)))
           (if company-candidates
               (company-call-frontends 'post-command)
-            (and (or (numberp company-idle-delay)
-                     ;; Deprecated.
-                     (eq company-idle-delay t))
-                 (not defining-kbd-macro)
-                 (company--should-begin)
-                 (setq company-timer
-                       (run-with-timer (company--idle-delay) nil
-                                       'company-idle-begin
-                                       (current-buffer) (selected-window)
-                                       (buffer-chars-modified-tick) 
(point))))))
+            (let ((delay (company--idle-delay)))
+             (and (numberp delay)
+                  (not defining-kbd-macro)
+                  (company--should-begin)
+                  (setq company-timer
+                        (run-with-timer delay nil
+                                        'company-idle-begin
+                                        (current-buffer) (selected-window)
+                                        (buffer-chars-modified-tick) 
(point)))))))
       (error (message "Company: An error occurred in post-command")
              (message "%s" (error-message-string err))
              (company-cancel))))
   (company-install-map))
 
 (defun company--idle-delay ()
-  (if (memql company-idle-delay '(t 0 0.0))
-      0.01
-    company-idle-delay))
+  (let ((delay
+          (if (functionp company-idle-delay)
+              (funcall company-idle-delay)
+            company-idle-delay)))
+    (if (memql delay '(t 0 0.0))
+        0.01
+      delay)))
 
 (defvar company--begin-inhibit-commands '(company-abort
                                           company-complete-mouse
@@ -1817,7 +1831,8 @@ each one wraps a part of the input string."
           (and (not (string= re ""))
                company-search-filtering
                (lambda (candidate) (string-match re candidate))))
-         (cc (company-calculate-candidates company-prefix)))
+         (cc (company-calculate-candidates company-prefix
+                                           (company-call-backend 
'ignore-case))))
     (unless cc (user-error "No match"))
     (company-update-candidates cc)))
 
@@ -2173,10 +2188,12 @@ inserted."
   (interactive)
   (when (company-manual-begin)
     (if (or company-selection-changed
-            (eq last-command 'company-complete-common))
+            (and (eq real-last-command 'company-complete)
+                 (eq last-command 'company-complete-common)))
         (call-interactively 'company-complete-selection)
       (call-interactively 'company-complete-common)
-      (setq this-command 'company-complete-common))))
+      (when company-candidates
+        (setq this-command 'company-complete-common)))))
 
 (defun company-complete-number (n)
   "Insert the Nth candidate visible in the tooltip.
@@ -2632,6 +2649,9 @@ If SHOW-VERSION is non-nil, show the version in the echo 
area."
           new
           (company-safe-substring old (+ offset (length new)))))
 
+(defun company--show-numbers (numbered)
+  (format " %d" (mod numbered 10)))
+
 (defsubst company--window-height ()
   (if (fboundp 'window-screen-lines)
       (floor (window-screen-lines))
@@ -2784,7 +2804,7 @@ If SHOW-VERSION is non-nil, show the version in the echo 
area."
           (when (< numbered 10)
             (cl-decf width 2)
             (cl-incf numbered)
-            (setq right (concat (format " %d" (mod numbered 10)) right)))
+            (setq right (concat (funcall company-show-numbers-function 
numbered) right)))
           (push (concat
                  (company-fill-propertize str annotation
                                           width (equal i selection)
@@ -3047,6 +3067,9 @@ Delay is determined by `company-tooltip-idle-delay'."
 (defun company--show-inline-p ()
   (and (not (cdr company-candidates))
        company-common
+       (not (eq t (compare-strings company-prefix nil nil
+                                   (car company-candidates) nil nil
+                                   t)))
        (or (eq (company-call-backend 'ignore-case) 'keep-prefix)
            (string-prefix-p company-prefix company-common))))
 
diff --git a/packages/company/test/capf-tests.el 
b/packages/company/test/capf-tests.el
index c8d4202..80a204d 100644
--- a/packages/company/test/capf-tests.el
+++ b/packages/company/test/capf-tests.el
@@ -26,6 +26,7 @@
 
 (require 'company-tests)
 (require 'company-capf)
+(require 'cl-lib)
 
 (defmacro company-capf-with-buffer (contents &rest body)
   (declare (indent 0) (debug (sexp &rest form)))
@@ -55,6 +56,19 @@
     (should company-candidates)
     (should (member "with-current-buffer" company-candidates))))
 
+(defun company--remove-but-these-properties (string keep)
+  "Remove from STRING all text properties but the ones in KEEP."
+  (remove-list-of-text-properties
+   0 (length string)
+   (cl-set-difference
+    (cl-loop for start = 0 then (next-property-change start string)
+             while start
+             append (cl-loop for (k _v) on (text-properties-at start string)
+                             by #'cddr collect k))
+    keep)
+   string)
+  string)
+
 (ert-deftest company-basic-capf-highlighting ()
   "Test basic `company-capf' support, with basic prefix completion."
   (company-capf-with-buffer
@@ -66,10 +80,8 @@
            (render
             (and cand
                  (company-fill-propertize cand nil (length cand) nil nil 
nil))))
-      ;; remove `font-lock-face' and `mouse-face' text properties that aren't
-      ;; relevant to our test
-      (remove-list-of-text-properties
-       0 (length cand) '(font-lock-face mouse-face) render)
+      ;; remove text properties that aren't relevant to our test
+      (company--remove-but-these-properties render '(face))
       (should
        (ert-equal-including-properties
         render
@@ -99,10 +111,8 @@
            (render
             (and cand
                  (company-fill-propertize cand nil (length cand) nil nil 
nil))))
-      ;; remove `font-lock-face' and `mouse-face' text properties that aren't
-      ;; relevant to our test
-      (remove-list-of-text-properties
-       0 (length cand) '(font-lock-face mouse-face) render)
+      ;; remove text properties that aren't relevant to our test
+      (company--remove-but-these-properties render '(face))
       (should
        (ert-equal-including-properties
         render
@@ -125,10 +135,8 @@
            (render
             (and cand
                  (company-fill-propertize cand nil (length cand) nil nil 
nil))))
-      ;; remove `font-lock-face' and `mouse-face' text properties that aren't
-      ;; relevant to our test
-      (remove-list-of-text-properties
-       0 (length cand) '(font-lock-face mouse-face) render)
+      ;; remove text properties that aren't relevant to our test
+      (company--remove-but-these-properties render '(face))
       (should
        (ert-equal-including-properties
         render
diff --git a/packages/company/test/core-tests.el 
b/packages/company/test/core-tests.el
index 2e0c77f..d7f0103 100644
--- a/packages/company/test/core-tests.el
+++ b/packages/company/test/core-tests.el
@@ -48,6 +48,32 @@
       (company-abort)
       (should (null company--manual-prefix)))))
 
+(ert-deftest company-auto-begin-unique-cancels ()
+  (with-temp-buffer
+    (insert "abc")
+    (company-mode)
+    (let (company-frontends
+          (company-backends
+           (list (lambda (command &optional _)
+                   (cl-case command
+                     (prefix (buffer-substring (point-min) (point)))
+                     (candidates '("abc")))))))
+      (company-auto-begin)
+      (should (equal nil company-candidates)))))
+
+(ert-deftest company-manual-begin-unique-shows-completion ()
+  (with-temp-buffer
+    (insert "abc")
+    (company-mode)
+    (let (company-frontends
+          (company-backends
+           (list (lambda (command &optional _)
+                   (cl-case command
+                     (prefix (buffer-substring (point-min) (point)))
+                     (candidates '("abc")))))))
+      (company-manual-begin)
+      (should (equal '("abc") company-candidates)))))
+
 (ert-deftest company-abort-manual-when-too-short ()
   (let ((company-minimum-prefix-length 5)
         (company-abort-manual-when-too-short t)
@@ -127,7 +153,7 @@
                    (annotation "3")
                    (candidates '("e"))
                    (post-completion "74"))))))
-    (let ((candidates (company-calculate-candidates nil)))
+    (let ((candidates (company-calculate-candidates nil nil)))
       (should (equal candidates '("a" "b" "c" "d" "e")))
       (should (equal t (company-call-backend 'ignore-case)))
       (should (equal "1" (company-call-backend 'annotation (nth 0 
candidates))))



reply via email to

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