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

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

[elpa] externals/posframe ae00691 1/5: Add poshandler for centering belo


From: Feng Shu
Subject: [elpa] externals/posframe ae00691 1/5: Add poshandler for centering below point
Date: Wed, 3 Feb 2021 03:19:36 -0500 (EST)

branch: externals/posframe
commit ae00691e35d52fc059e80c5fea798f005985ec1c
Author: Sheng Yang <yangsheng6810@gmail.com>
Commit: Sheng Yang <yangsheng6810@gmail.com>

    Add poshandler for centering below point
    
    Add poshandler posframe-poshandler-point-window-center
---
 posframe.el | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/posframe.el b/posframe.el
index c220223..980b635 100644
--- a/posframe.el
+++ b/posframe.el
@@ -456,6 +456,7 @@ The builtin poshandler functions are listed below:
 15. `posframe-poshandler-point-top-left-corner'
 16. `posframe-poshandler-point-bottom-left-corner'
 17. `posframe-poshandler-point-bottom-left-corner-upward'
+18. `posframe-poshandler-point-window-center'
 
 This posframe's buffer is BUFFER-OR-NAME, which can be a buffer
 or a name of a (possibly nonexistent) buffer.
@@ -965,19 +966,21 @@ of `posframe-show'."
     (cons (+ (car position) x-pixel-offset)
           (+ (cdr position) y-pixel-offset))))
 
-(defun posframe-poshandler-point-bottom-left-corner (info &optional 
font-height upward)
+(defun posframe-poshandler-point-bottom-left-corner (info &optional 
font-height upward centering)
   "Posframe's position hanlder.
 
 Get bottom-left-corner pixel position of a point,
 the structure of INFO can be found in docstring
 of `posframe-show'.
 
-Optional argument FONT-HEIGHT ."
+Optional argument FONT-HEIGHT, UPWARD, CENTERING ."
   (let* ((x-pixel-offset (plist-get info :x-pixel-offset))
          (y-pixel-offset (plist-get info :y-pixel-offset))
          (posframe-width (plist-get info :posframe-width))
          (posframe-height (plist-get info :posframe-height))
          (window (plist-get info :parent-window))
+         (window-left (plist-get info :parent-window-left))
+         (window-width (plist-get info :parent-window-width))
          (xmax (plist-get info :parent-frame-width))
          (ymax (plist-get info :parent-frame-height))
          (position-info (plist-get info :position-info))
@@ -997,13 +1000,24 @@ Optional argument FONT-HEIGHT ."
                    y-pixel-offset))
          (font-height (or font-height (plist-get info :font-height)))
          (y-bottom (+ y-top font-height)))
-    (cons (max 0 (min x (- xmax (or posframe-width 0))))
+    (cons (if centering
+              (+ window-left (/ (- window-width posframe-width) 2))
+            (max 0 (min x (- xmax (or posframe-width 0)))))
           (max 0 (if (if upward
                          (> (- y-bottom (or posframe-height 0)) 0)
                        (> (+ y-bottom (or posframe-height 0)) ymax))
                      (- y-top (or posframe-height 0))
                    y-bottom)))))
 
+(defun posframe-poshandler-point-window-center (info)
+  "Posframe's position hanlder.
+
+Get a position of a point, by which a window-centered posframe
+can be put below it, the structure of INFO can be found in
+docstring of `posframe-show'. "
+
+  (posframe-poshandler-point-bottom-left-corner info nil nil t))
+
 (defun posframe-poshandler-point-bottom-left-corner-upward (info)
   "Posframe's position hanlder.
 



reply via email to

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