]> git.eshelyaron.com Git - emacs.git/commitdiff
Inherit text props in Completion Preview insertion commands
authorEshel Yaron <me@eshelyaron.com>
Sat, 29 Jun 2024 09:51:10 +0000 (11:51 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 29 Jun 2024 09:51:10 +0000 (11:51 +0200)
When completing with Completion Preview mode commands,
inherit text properties from surrounding text similarly to
other completion commands, such as 'completion-at-point'.

* lisp/completion-preview.el (completion-preview-insert)
(completion-preview-partial-insert)
(completion-preview-complete): Use 'insert-and-inherit'
instead of 'insert' to insert text for completion.
* test/lisp/completion-preview-tests.el
(completion-preview-insert-inherits-text-properties): New
test.

lisp/completion-preview.el
test/lisp/completion-preview-tests.el

index f0a094864b4a6ae3ee7da2316d8c374a012d6ff9..d8a010a94b7f5f188fe43affc4f8a892b2f3a683 100644 (file)
@@ -558,7 +558,7 @@ point, otherwise hide it."
          (str (concat pre com (nth ind all))))
     (completion-preview-active-mode -1)
     (goto-char end)
-    (insert (substring-no-properties aft))
+    (insert-and-inherit (substring-no-properties aft))
     (when (functionp efn) (funcall efn str 'finished))))
 
 (defun completion-preview-partial-insert (fun &rest args)
@@ -583,7 +583,7 @@ Beyond moving point, FUN should not modify the current buffer."
             (save-excursion
               (goto-char end)
               ;; Temporarily insert the full completion candidate.
-              (insert (substring-no-properties aft)))
+              (insert-and-inherit (substring-no-properties aft)))
             ;; Set point to the end of the prefix that we want to keep.
             (apply fun args)
             (unless (< end (point))
@@ -683,7 +683,7 @@ completions list."
           (completion-preview--inhibit-update)
           (completion-at-point))
       ;; Otherwise, insert the common prefix and update the preview.
-      (insert ins)
+      (insert-and-inherit ins)
       (let ((suf (nth cur all))
             (pos (point)))
         (if (or (string-empty-p suf) (null suf))
index 35b69681ce694831c8a192b265f8cd717d18efad..b50d999e69a8384bc02207a0f81e79c07d1a2a97 100644 (file)
@@ -411,6 +411,19 @@ instead."
       (should-not exit-fn-called)
       (should-not exit-fn-args))))
 
+(ert-deftest completion-preview-insert-inherits-text-properties ()
+  "Test that `completion-preview-insert' inherits text properties."
+  (with-temp-buffer
+    (setq-local completion-at-point-functions
+                (list (completion-preview-tests--capf '("foobar" "foobaz"))))
+    (insert (propertize "foo" 'prop 'val))
+    (let ((this-command 'self-insert-command))
+      (completion-preview--post-command))
+    (completion-preview-tests--check-preview "bar" 'completion-preview-common)
+    (completion-preview-insert)
+    (should (string= (buffer-string) "foobar"))
+    (should (eq (get-text-property 6 'prop) 'val))))
+
 (ert-deftest completion-preview-cursor-type ()
   "Test modification of `cursor-type' when completion preview is visible."
   (with-temp-buffer