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

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

[elpa] externals/company 6206db868a 18/24: Rewrite company-safe-pixel-su


From: ELPA Syncer
Subject: [elpa] externals/company 6206db868a 18/24: Rewrite company-safe-pixel-substring to make more tests pass in batch
Date: Mon, 6 Nov 2023 09:57:38 -0500 (EST)

branch: externals/company
commit 6206db868a48cfa8e788d3329a1b9fbdff8db077
Author: Dmitry Gutov <dmitry@gutov.dev>
Commit: Dmitry Gutov <dmitry@gutov.dev>

    Rewrite company-safe-pixel-substring to make more tests pass in batch
    
    vertical-motion doesn't work well in batch mode, so it exposed some corner
    cases.  And the result is more readable anyway.
    
    The last test still didn't work in batch; make it interactive-only.
---
 company.el              | 49 +++++++++++++++++++------------------------------
 test/frontends-tests.el |  1 +
 2 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/company.el b/company.el
index 19c3c9dd23..2209d950cd 100644
--- a/company.el
+++ b/company.el
@@ -2933,7 +2933,7 @@ from the candidates list.")
   (let ((from-chars 0)
         (to-chars 0)
         spw-from spw-to
-        spw-from-prev spw-to-prev
+        spw-to-prev
         front back
         (orig-buf (window-buffer))
         (bis buffer-invisibility-spec)
@@ -2948,20 +2948,13 @@ from the candidates list.")
 
             (vertical-motion (cons (/ from (frame-char-width)) 0))
             (setq from-chars (point))
-            (while (and (<
-                         (setq spw-from
-                               (car
-                                (window-text-pixel-size nil (point-min) 
(point) 55555)))
-                         from)
+            (setq spw-from
+                  (car (window-text-pixel-size nil (point-min) (point) 55555)))
+            (while (and (< spw-from from)
                         (not (eolp)))
-              (when (<= spw-from from)
-                (setq from-chars (point)))
-              (forward-char 1)
-              (setq spw-from-prev spw-from))
-
-            (when (and (/= from-chars (point-max)) (> spw-from from))
-              (goto-char from-chars)
               (forward-char 1)
+              (setq spw-from
+                    (car (window-text-pixel-size nil (point-min) (point) 
55555)))
               (setq from-chars (point)))
 
             (if (= from-chars (point-max))
@@ -2972,33 +2965,29 @@ from the candidates list.")
                   (setq to-chars (point-max))
                 (vertical-motion (cons (/ to (frame-char-width)) 0))
                 (setq to-chars (point))
-                (while (and (not (eolp))
-                            (<
-                             (setq spw-to
-                                   (car
-                                    (window-text-pixel-size nil (point-min) 
(point) 55555)))
-                             to))
-                  (when (<= spw-to to)
-                    (setq to-chars (point)))
+                (setq spw-to
+                      (car (window-text-pixel-size nil (point-min) (point) 
55555)))
+                (while (and (< spw-to to)
+                            (not (eolp)))
+                  (setq spw-to-prev spw-to)
                   (forward-char 1)
-                  (setq spw-to-prev spw-to
-                        spw-to nil)))
+                  (setq spw-to
+                        (car (window-text-pixel-size nil (point-min) (point) 
55555)))
+                  (when (<= spw-to to)
+                    (setq to-chars (point)))))
 
-              (unless spw-from-prev (setq spw-from-prev spw-from))
               (unless spw-to-prev (setq spw-to-prev spw-to))
 
               (when (> spw-from from)
                 (setq front (propertize " " 'display
                                         `(space . (:width (,(- spw-from 
from)))))))
-              (when (and to (or (not spw-to) (> spw-to to)))
+              (when (and to (/= spw-to to))
                 (setq back (propertize
                             " " 'display
                             `(space . (:width (,(- to
-                                                   (or
-                                                    spw-to-prev
-                                                    (car 
(window-text-pixel-size
-                                                          nil (point-min) 
to-chars 55555)))
-                                                   )))))))
+                                                   (if (< spw-to to)
+                                                       spw-to
+                                                     spw-to-prev))))))))
               (concat front (buffer-substring from-chars to-chars) back)))
         (set-window-buffer nil orig-buf t)))))
 
diff --git a/test/frontends-tests.el b/test/frontends-tests.el
index 3aeb526969..0ae84d26fd 100644
--- a/test/frontends-tests.el
+++ b/test/frontends-tests.el
@@ -496,6 +496,7 @@
              "-*-fzzbar"))))
 
 (ert-deftest company-modify-line-with-prettify ()
+  :tags '(interactive)
   (with-temp-buffer
     (insert "lambda foo bar")
     (setq-local prettify-symbols-alist '(("lambda" . ?λ)))



reply via email to

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