[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu 1ce7aa2543 1/3: Generic corfu--popup-show/hide/su
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu 1ce7aa2543 1/3: Generic corfu--popup-show/hide/support-p |
Date: |
Sat, 4 Feb 2023 03:57:26 -0500 (EST) |
branch: externals/corfu
commit 1ce7aa2543408333d0f552a1475eef5dce29a5a5
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Generic corfu--popup-show/hide/support-p
Using cl-defgeneric allows other packages, e.g., corfu-terminal, to
implement these functions, providing alternative display methods.
Otherwise corfu-terminal has to resort to advices.
See #248
---
corfu.el | 114 +++++++++++++++++++++++++++++++--------------------------------
1 file changed, 57 insertions(+), 57 deletions(-)
diff --git a/corfu.el b/corfu.el
index 15082b9444..fde7ecdffe 100644
--- a/corfu.el
+++ b/corfu.el
@@ -455,55 +455,6 @@ FRAME is the existing frame."
(redirect-frame-focus frame parent)
frame))
-(defun corfu--popup-show (pos off width lines &optional curr lo bar)
- "Show LINES as popup at POS - OFF.
-WIDTH is the width of the popup.
-The current candidate CURR is highlighted.
-A scroll bar is displayed from LO to LO+BAR."
- (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."
(when (and (frame-live-p frame) (frame-visible-p frame))
@@ -520,14 +471,6 @@ A scroll bar is displayed from LO to LO+BAR."
(set-frame-parameter frame 'corfu--hide-timer
(run-at-time 0 nil #'corfu--hide-frame-deferred
frame))))
-(defun corfu--popup-hide ()
- "Hide Corfu popup."
- (corfu--hide-frame corfu--frame))
-
-(defun corfu--popup-support-p ()
- "Return non-nil if child frames are supported."
- (display-graphic-p))
-
(defun corfu--move-to-front (elem list)
"Move ELEM to front of LIST."
(if-let (found (member elem list))
@@ -971,6 +914,63 @@ See `completion-in-region' for the arguments BEG, END,
TABLE, PRED."
Auto completion is only performed if the tick did not change."
(list (selected-window) (current-buffer) (buffer-chars-modified-tick)
(point)))
+(cl-defgeneric corfu--popup-show (pos off width lines &optional curr lo bar)
+ "Show LINES as popup at POS - OFF.
+WIDTH is the width of the popup.
+The current candidate CURR is highlighted.
+A scroll bar is displayed from LO to LO+BAR."
+ (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)))))))
+
+(cl-defgeneric corfu--popup-hide ()
+ "Hide Corfu popup."
+ (corfu--hide-frame corfu--frame))
+
+(cl-defgeneric corfu--popup-support-p ()
+ "Return non-nil if child frames are supported."
+ (display-graphic-p))
+
(cl-defgeneric corfu--insert (status)
"Insert current candidate, exit with STATUS if non-nil."
(pcase-let* ((`(,beg ,end . ,_) completion-in-region--data)