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

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

[elpa] externals/vertico-posframe 7840617866 1/3: Simplify vertico-posfr


From: ELPA Syncer
Subject: [elpa] externals/vertico-posframe 7840617866 1/3: Simplify vertico-posframe.
Date: Tue, 4 Jan 2022 20:57:43 -0500 (EST)

branch: externals/vertico-posframe
commit 7840617866c6f0518ad85e077db2be90b86c556e
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    Simplify vertico-posframe.
    
            * vertico-posframe.el (vertico-posframe-cursor)
            (vertico-posframe--minibuffer-cover)
            (vertico-posframe--create-minibuffer-cover)
            (vertico-posframe--hide-minibuffer-cover)
            (vertico-posframe--minibuffer-message): removed.
            (vertico-posframe--show, vertico-posframe--display)
            (vertico-posframe--hide, vertico-posframe--setup)
            (vertico-posframe-cleanup, vertico-posframe-mode): simplify.
---
 vertico-posframe.el | 133 ++++++++++++++++++----------------------------------
 1 file changed, 46 insertions(+), 87 deletions(-)

diff --git a/vertico-posframe.el b/vertico-posframe.el
index d9bb3f26e1..59f029d82c 100644
--- a/vertico-posframe.el
+++ b/vertico-posframe.el
@@ -130,13 +130,7 @@ minibuffer will not be hided by minibuffer-cover."
   "Face used by the vertico-posframe's border."
   :group 'vertico-posframe)
 
-(defface vertico-posframe-cursor
-  '((t (:inherit cursor)))
-  "Face used by the vertico-posframe's fake cursor."
-  :group 'vertico-posframe)
-
-(defvar vertico-posframe--buffer " *vertico-posframe--buffer*")
-(defvar vertico-posframe--minibuffer-cover " 
*vertico-posframe--minibuffer-cover*")
+(defvar vertico-posframe--buffer nil)
 
 ;; Fix warn
 (defvar exwm--connection)
@@ -178,79 +172,56 @@ Optional argument FRAME ."
                   (let ((width (round (* (frame-width) 0.62))))
                     (min width (or vertico-posframe-width width))))))
 
-(defun vertico-posframe--display (lines)
+(defun vertico-posframe--display (_lines)
   "Display LINES in posframe."
   (let* ((show-minibuffer-p (vertico-posframe--show-minibuffer-p))
-         (count (vertico-posframe--format-count))
-         (prompt (propertize (minibuffer-prompt) 'face 'minibuffer-prompt))
-         ;; NOTE: Vertico count in minibuffer is before-string of an
-         ;; overlay, so minibuffer contents will not include it.
-         (contents (minibuffer-contents))
-         (n (+ (length count)
-               (max (point) (+ (length prompt) 1))))
-         ;; FIXME: make sure background and foreground do
-         ;; not have similar color. ivy-posframe have not
-         ;; this problem, I can not find the reason.
-         (cursor-face
-          (list :foreground (face-attribute 'default :background)
-                :inherit 'vertico-posframe-cursor)))
-    (with-current-buffer (get-buffer-create vertico-posframe--buffer)
-      (setq-local inhibit-read-only nil
-                  inhibit-modification-hooks t
-                  cursor-in-non-selected-windows 'box)
-      (erase-buffer)
-      (insert count prompt contents "\n" (string-join lines))
-      (add-text-properties n (+ n 1) `(face ,cursor-face)))
+         (minibuffer-window (active-minibuffer-window))
+         (minibuffer (current-buffer))
+         (point (point)))
+    (setq vertico-posframe--buffer (current-buffer))
+    (window-resize minibuffer-window
+                   (- (window-pixel-height minibuffer-window))
+                   nil nil 'pixelwise)
+    (set-window-vscroll minibuffer-window 100)
+    (when show-minibuffer-p
+      (set-window-vscroll minibuffer-window 0))
     (with-selected-window (vertico-posframe-last-window)
-      ;; Create a posframe to cover minibuffer.
-      (if show-minibuffer-p
-          (vertico-posframe--hide-minibuffer-cover)
-        (vertico-posframe--create-minibuffer-cover))
-      (vertico-posframe--show))))
+      (vertico-posframe--show minibuffer point))))
 
 (defun vertico-posframe--format-count ()
   "Format vertico count."
   (propertize (or (vertico--format-count) "") 'face 'minibuffer-prompt))
 
-(defun vertico-posframe--show (&optional string)
+(defun vertico-posframe--show (minibuffer minibuffer-window-point)
   "`posframe-show' of vertico-posframe.
-Show STRING when it is a string."
-  (apply #'posframe-show
-         vertico-posframe--buffer
-         :string string
-         :font vertico-posframe-font
-         :poshandler vertico-posframe-poshandler
-         :background-color (face-attribute 'vertico-posframe :background nil t)
-         :foreground-color (face-attribute 'vertico-posframe :foreground nil t)
-         :border-width vertico-posframe-border-width
-         :border-color (face-attribute 'vertico-posframe-border :background 
nil t)
-         :override-parameters vertico-posframe-parameters
-         :refposhandler vertico-posframe-refposhandler
-         :hidehandler #'vertico-posframe-hidehandler
-         :lines-truncate t
-         (funcall vertico-posframe-size-function)))
-
-(defun vertico-posframe--create-minibuffer-cover (&optional string)
-  "Create minibuffer cover."
-  (let ((color (face-background 'default nil))
-        (win (active-minibuffer-window)))
-    (posframe-show vertico-posframe--minibuffer-cover
-                   :string (or string (make-string (frame-width) ?\ ))
-                   :position (cons 0 (- (frame-pixel-height) 
(window-pixel-height win)))
-                   :height (+ (window-height win) 1)
-                   :background-color color
-                   :foreground-color color
-                   :lines-truncate t
-                   :timeout 3)))
-
-(defun vertico-posframe--hide-minibuffer-cover ()
-  "Hide minibuffer cover."
-  ;; FIXME: delay 0.1 second to remove minibuffer cover, which can
-  ;; limit minibuffer flicker.
-  (run-with-timer
-   0.1 nil
-   (lambda ()
-     (posframe-hide vertico-posframe--minibuffer-cover))))
+
+MINIBUFFER will be showed by `posframe-show'.  After
+`posframe-show' is called, window-point will be set to
+MINIBUFFER-WINDOW-POINT."
+  (let ((posframe (apply #'posframe-show
+                         minibuffer
+                         :font vertico-posframe-font
+                         :poshandler vertico-posframe-poshandler
+                         :background-color (face-attribute 'vertico-posframe 
:background nil t)
+                         :foreground-color (face-attribute 'vertico-posframe 
:foreground nil t)
+                         :border-width vertico-posframe-border-width
+                         :border-color (face-attribute 
'vertico-posframe-border :background nil t)
+                         :override-parameters vertico-posframe-parameters
+                         :refposhandler vertico-posframe-refposhandler
+                         :hidehandler #'vertico-posframe-hidehandler
+                         :lines-truncate t
+                         :refresh 0.5
+                         (funcall vertico-posframe-size-function))))
+    ;; NOTE: `posframe-show' will force set window-point to 0, so we
+    ;; need reset it again after `posframe-show'.
+    (when (numberp minibuffer-window-point)
+      (let ((window (frame-root-window posframe)))
+        (when (window-live-p window)
+          (set-window-point window minibuffer-window-point))))
+    ;; NOTE: posframe will hide cursor, so we need let it show again.
+    (with-current-buffer minibuffer
+      (setq-local cursor-type t)
+      (setq-local cursor-in-non-selected-windows 'box))))
 
 (defun vertico-posframe--show-minibuffer-p ()
   "Test show minibuffer or not."
@@ -277,27 +248,17 @@ Show STRING when it is a string."
 (defun vertico-posframe--hide ()
   "Hide vertico buffer."
   (when (posframe-workable-p)
-    (posframe-hide vertico-posframe--buffer)
-    (vertico-posframe--hide-minibuffer-cover)))
+    (posframe-hide vertico-posframe--buffer)))
 
 (defun vertico-posframe--setup ()
   "Setup minibuffer overlay, which pushes the minibuffer content down."
-  (add-hook 'minibuffer-exit-hook 'vertico-posframe--hide nil 'local)
-  (setq-local cursor-type '(bar . 0)))
-
-(defun vertico-posframe--minibuffer-message (message &rest _args)
-  "Advice function of `minibuffer-message'.
-Argument MESSAGE ."
-  (let* ((count (vertico-posframe--format-count))
-         (contents (buffer-string)))
-    (vertico-posframe--show (concat count contents message))))
+  (add-hook 'minibuffer-exit-hook 'vertico-posframe--hide nil 'local))
 
 ;;;###autoload
 (defun vertico-posframe-cleanup ()
   "Remove frames and buffers used for vertico-posframe."
   (interactive)
-  (posframe-delete vertico-posframe--buffer)
-  (posframe-delete vertico-posframe--minibuffer-cover))
+  (posframe-delete vertico-posframe--buffer))
 
 ;;;###autoload
 (define-minor-mode vertico-posframe-mode
@@ -305,11 +266,9 @@ Argument MESSAGE ."
   :global t
   (cond
    (vertico-posframe-mode
-    (advice-add #'minibuffer-message :before 
#'vertico-posframe--minibuffer-message)
-    (advice-add #'vertico--display-candidates :override 
#'vertico-posframe--display)
+    (advice-add #'vertico--display-candidates :after 
#'vertico-posframe--display)
     (advice-add #'vertico--setup :after #'vertico-posframe--setup))
    (t
-    (advice-remove #'minibuffer-message #'vertico-posframe--minibuffer-message)
     (advice-remove #'vertico--display-candidates #'vertico-posframe--display)
     (advice-remove #'vertico--setup #'vertico-posframe--setup))))
 



reply via email to

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