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

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

[elpa] externals/corfu 360feabcd5 2/4: Take corfu-default face height in


From: ELPA Syncer
Subject: [elpa] externals/corfu 360feabcd5 2/4: Take corfu-default face height into account for popup size (Fix #149)
Date: Wed, 30 Nov 2022 00:57:33 -0500 (EST)

branch: externals/corfu
commit 360feabcd50f0924b31fcf1c7d00b06c51c1ccea
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Take corfu-default face height into account for popup size (Fix #149)
    
    Try this:
    
    (set-face-attribute 'corfu-default nil :height 0.8)
---
 corfu.el                      | 92 +++++++++++++++++++++----------------------
 extensions/corfu-popupinfo.el | 11 ++++--
 2 files changed, 53 insertions(+), 50 deletions(-)

diff --git a/corfu.el b/corfu.el
index 85df408389..b58be55fad 100644
--- a/corfu.el
+++ b/corfu.el
@@ -344,8 +344,8 @@ The completion backend can override this with
     map)
   "Ignore all mouse clicks.")
 
-(defun corfu--make-buffer (name content)
-  "Create buffer with NAME and CONTENT."
+(defun corfu--make-buffer (name)
+  "Create buffer with NAME."
   (let ((fr face-remapping-alist)
         (ls line-spacing)
         (buffer (get-buffer-create name)))
@@ -357,11 +357,7 @@ The completion backend can override this with
       (setq-local face-remapping-alist (copy-tree fr)
                   line-spacing ls)
       (cl-pushnew 'corfu-default (alist-get 'default face-remapping-alist))
-      (with-silent-modifications
-        (erase-buffer)
-        (insert content)
-        (goto-char (point-min))))
-    buffer))
+      buffer)))
 
 ;; Function adapted from posframe.el by tumashu
 (defvar x-gtk-resize-child-frames) ;; Not present on non-gtk builds
@@ -447,45 +443,49 @@ FRAME is the existing frame."
 WIDTH is the width of the popup.
 The current candidate CURR is highlighted.
 A scroll bar is displayed from LO to LO+BAR."
-  (let* ((ch (default-line-height))
-         (cw (default-font-width))
-         (ml (ceiling (* cw corfu-left-margin-width)))
-         (mr (ceiling (* cw corfu-right-margin-width)))
-         (bw (ceiling (min mr (* cw corfu-bar-width))))
-         (marginl (and (> ml 0) (propertize " " 'display `(space :width 
(,ml)))))
-         (marginr (and (> mr 0) (propertize " " 'display `(space :align-to 
right))))
-         (sbar (when (> bw 0)
-                 (concat (propertize " " 'display `(space :align-to (- right 
(,mr))))
-                         (propertize " " 'display `(space :width (,(- mr bw))))
-                         (propertize " " 'face 'corfu-bar 'display `(space 
:width (,bw))))))
-         (pos (posn-x-y (posn-at-point pos)))
-         (width (+ (* width cw) ml mr))
-         (height (* (length lines) ch))
-         (edge (window-inside-pixel-edges))
-         (border (alist-get 'child-frame-border-width corfu--frame-parameters))
-         (x (max 0 (min (+ (car edge) (- (or (car pos) 0) ml (* cw off) 
border))
-                        (- (frame-pixel-width) width))))
-         (yb (+ (cadr edge) (window-tab-line-height) (or (cdr pos) 0) ch))
-         (y (if (> (+ yb (* corfu-count ch) ch ch) (frame-pixel-height))
-                (- yb height ch border border)
-              yb))
-         (row 0))
-    (setq corfu--frame
-          (corfu--make-frame
-           corfu--frame x y width height
-           (corfu--make-buffer
-            " *corfu*"
-            (mapconcat (lambda (line)
-                         (let ((str (concat marginl line
-                                            (if (and lo (<= lo row (+ lo bar)))
-                                                sbar
-                                              marginr))))
-                           (when (eq row curr)
-                             (add-face-text-property
-                              0 (length str) 'corfu-current 'append str))
-                           (cl-incf row)
-                           str))
-                       lines "\n"))))))
+  (let ((lh (default-line-height)))
+    (with-current-buffer (corfu--make-buffer " *corfu*")
+      (let* ((ch (default-line-height))
+             (cw (default-font-width))
+             (ml (ceiling (* cw corfu-left-margin-width)))
+             (mr (ceiling (* cw corfu-right-margin-width)))
+             (bw (ceiling (min mr (* cw corfu-bar-width))))
+             (marginl (and (> ml 0) (propertize " " 'display `(space :width 
(,ml)))))
+             (marginr (and (> mr 0) (propertize " " 'display `(space :align-to 
right))))
+             (sbar (when (> bw 0)
+                     (concat (propertize " " 'display `(space :align-to (- 
right (,mr))))
+                             (propertize " " 'display `(space :width (,(- mr 
bw))))
+                             (propertize " " 'face 'corfu-bar 'display `(space 
:width (,bw))))))
+             (pos (posn-x-y (posn-at-point pos)))
+             (width (+ (* width cw) ml mr))
+             ;; XXX HACK: Minimum popup height must be at least 1 line of the
+             ;; parent frame (#261).
+             (height (max lh (* (length lines) ch)))
+             (edge (window-inside-pixel-edges))
+             (border (alist-get 'child-frame-border-width 
corfu--frame-parameters))
+             (x (max 0 (min (+ (car edge) (- (or (car pos) 0) ml (* cw off) 
border))
+                            (- (frame-pixel-width) width))))
+             (yb (+ (cadr edge) (window-tab-line-height) (or (cdr pos) 0) lh))
+             (y (if (> (+ yb (* corfu-count ch) lh lh) (frame-pixel-height))
+                    (- yb height lh border border)
+                  yb))
+             (row 0))
+        (with-silent-modifications
+          (erase-buffer)
+          (insert (mapconcat (lambda (line)
+                               (let ((str (concat marginl line
+                                                  (if (and lo (<= lo row (+ lo 
bar)))
+                                                      sbar
+                                                    marginr))))
+                                 (when (eq row curr)
+                                   (add-face-text-property
+                                    0 (length str) 'corfu-current 'append str))
+                                 (cl-incf row)
+                                 str))
+                             lines "\n"))
+          (goto-char (point-min)))
+        (setq corfu--frame (corfu--make-frame corfu--frame x y
+                                              width height 
(current-buffer)))))))
 
 (defun corfu--hide-frame-deferred (frame)
   "Deferred hiding of child FRAME."
diff --git a/extensions/corfu-popupinfo.el b/extensions/corfu-popupinfo.el
index 58195bb6aa..6980f2f235 100644
--- a/extensions/corfu-popupinfo.el
+++ b/extensions/corfu-popupinfo.el
@@ -328,11 +328,14 @@ form (X Y WIDTH HEIGHT DIR)."
            (coords-changed (not (equal new-coords 
corfu-popupinfo--coordinates))))
       (when cand-changed
         (if-let (content (funcall corfu-popupinfo--function candidate))
-            (with-current-buffer (corfu--make-buffer " *corfu-popupinfo*" 
content)
+            (with-current-buffer (corfu--make-buffer " *corfu-popupinfo*")
+              (with-silent-modifications
+                (erase-buffer)
+                (insert content)
+                (goto-char (point-min)))
               ;; TODO Could we somehow refill the buffer intelligently?
-              ;;(let ((inhibit-read-only t))
-              ;;  (setq fill-column corfu-popupinfo-max-width)
-              ;;  (fill-region (point-min) (point-max)))
+              ;; (setq fill-column corfu-popupinfo-max-width)
+              ;; (fill-region (point-min) (point-max))
               (dolist (var corfu-popupinfo--buffer-parameters)
                 (set (make-local-variable (car var)) (cdr var)))
               (setf face-remapping-alist (copy-tree face-remapping-alist)



reply via email to

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