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

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

[elpa] externals/posframe b6e5188 1/2: Add :max-width/height and proper


From: ELPA Syncer
Subject: [elpa] externals/posframe b6e5188 1/2: Add :max-width/height and proper deal with :width/height.
Date: Tue, 2 Nov 2021 21:57:23 -0400 (EDT)

branch: externals/posframe
commit b6e5188aebb5006d3bcaa218fa4d82c6b44b7e13
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    Add :max-width/height and proper deal with :width/height.
    
        * posframe.el (posframe-show)
        (posframe--set-frame-size, posframe--run-refresh-timer): Deal with 
:max-height and :max-width.
---
 posframe.el | 66 +++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 42 insertions(+), 24 deletions(-)

diff --git a/posframe.el b/posframe.el
index d93ef7d..dcccafe 100644
--- a/posframe.el
+++ b/posframe.el
@@ -288,6 +288,8 @@ ACCEPT-FOCUS."
                          poshandler-extra-info
                          width
                          height
+                         max-width
+                         max-height
                          min-width
                          min-height
                          x-pixel-offset
@@ -429,13 +431,11 @@ the buffer name will hide for ibuffer and `list-buffers'.
 If NO-PROPERTIES is non-nil, The STRING's properties will
 be removed before being shown in posframe.
 
- (6) WIDTH, MIN-WIDTH, HEIGHT and MIN-HEIGHT
+ (6) HEIGHT, MAX-HEIGHT, MIN-HEIGHT, WIDTH, MAX-WIDTH and MIN-WIDTH
 
-WIDTH, MIN-WIDTH, HEIGHT and MIN-HEIGHT, specify bounds on the
-new total size of posframe.  MIN-HEIGHT and MIN-WIDTH default to
-the values of ‘window-min-height’ and ‘window-min-width’
-respectively.  These arguments are specified in the canonical
-character width and height of posframe.
+These arguments are specified in the canonical character width
+and height of posframe, more details can be found in docstring of
+`fit-frame-to-buffer',
 
  (7) LEFT-FRINGE and RIGHT-FRINGE
 
@@ -537,6 +537,16 @@ You can use `posframe-delete-all' to delete all posframes."
   (let* ((position (or position (point)))
          (min-width (or min-width 1))
          (min-height (or min-height 1))
+         (width (when width
+                  (max min-width
+                       (if (numberp max-width)
+                           (min width max-width)
+                         width))))
+         (height (when height
+                   (max min-height
+                        (if (numberp max-height)
+                            (min height max-height)
+                          height))))
          (x-pixel-offset (or x-pixel-offset 0))
          (y-pixel-offset (or y-pixel-offset 0))
          ;;-----------------------------------------------------
@@ -603,7 +613,7 @@ You can use `posframe-delete-all' to delete all posframes."
 
       ;; Set posframe's size
       (posframe--set-frame-size
-       posframe height min-height width min-width)
+       posframe height max-height min-height width max-width min-width)
 
       ;; Get new position of posframe.
       (setq position
@@ -645,7 +655,7 @@ You can use `posframe-delete-all' to delete all posframes."
 
       ;; Re-adjust posframe's size when buffer's content has changed.
       (posframe--run-refresh-timer
-       posframe refresh height min-height width min-width)
+       posframe refresh height max-height min-height width max-width min-width)
 
       ;; Make sure not hide buffer's content for scroll down.
       (let ((window (frame-root-window posframe--frame)))
@@ -758,7 +768,7 @@ will be removed."
       (erase-buffer)
       (insert str))))
 
-(defun posframe--fit-frame-to-buffer (posframe height min-height width 
min-width)
+(defun posframe--fit-frame-to-buffer (posframe max-height min-height max-width 
min-width)
   "POSFRAME version of function `fit-frame-to-buffer'.
 Arguments HEIGHT, MIN-HEIGHT, WIDTH, MIN-WIDTH are similar
 function `fit-frame-to-buffer''s."
@@ -768,18 +778,21 @@ function `fit-frame-to-buffer''s."
     ;; 
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=e0de9f3295b4c46cb7198ec0b9634809d7b7a36d
     (if (functionp 'fit-frame-to-buffer-1)
         (fit-frame-to-buffer-1
-         posframe height min-height width min-width nil nil nil)
+         posframe max-height min-height max-width min-width nil nil nil)
       (fit-frame-to-buffer
-       posframe height min-height width min-width))))
+       posframe max-height min-height max-width min-width))))
 
-(defun posframe--set-frame-size (posframe height min-height width min-width)
+(defun posframe--set-frame-size (posframe height max-height min-height width 
max-width min-width)
   "Set POSFRAME's size.
 It will set the size by the POSFRAME's HEIGHT, MIN-HEIGHT
 WIDTH and MIN-WIDTH."
-  (posframe--fit-frame-to-buffer
-   posframe height min-height width min-width)
+  (unless (and width height)
+    (posframe--fit-frame-to-buffer
+     posframe max-height min-height max-width min-width))
+  (when height (set-frame-height posframe height))
+  (when width (set-frame-width posframe width))
   (setq-local posframe--last-posframe-size
-              (list height min-height width min-width)))
+              (list height max-height min-height width max-width min-width)))
 
 (defun posframe--set-frame-position (posframe position
                                               parent-frame-width
@@ -821,13 +834,18 @@ This need PARENT-FRAME-WIDTH and PARENT-FRAME-HEIGHT"
   (when (frame-live-p frame)
     (make-frame-invisible frame)))
 
-(defun posframe--run-refresh-timer (posframe repeat
-                                             height min-height
-                                             width min-width)
+(defun posframe--run-refresh-timer (posframe
+                                    repeat
+                                    height
+                                    max-height
+                                    min-height
+                                    width
+                                    max-width
+                                    min-width)
   "Refresh POSFRAME every REPEAT seconds.
 
-It will set POSFRAME's size by the posframe's HEIGHT, MIN-HEIGHT,
-WIDTH and MIN-WIDTH."
+It will set POSFRAME's size by the posframe's HEIGHT, MAX-HEIGHT, MIN-HEIGHT,
+WIDTH MAX-WIDTH and MIN-WIDTH."
   (when (and (numberp repeat) (> repeat 0))
     (unless (and width height)
       (when (timerp posframe--refresh-timer)
@@ -838,9 +856,9 @@ WIDTH and MIN-WIDTH."
                    #'(lambda (frame height min-height width min-width)
                        (let ((frame-resize-pixelwise t))
                          (when (and frame (frame-live-p frame))
-                           (posframe--fit-frame-to-buffer
-                            frame height min-height width min-width))))
-                   posframe height min-height width min-width)))))
+                           (posframe--set-frame-size
+                            frame height max-height min-height width max-width 
min-width))))
+                   posframe height max-height min-height width max-width 
min-width)))))
 
 (defun posframe-refresh (buffer-or-name)
   "Refresh posframe pertaining to BUFFER-OR-NAME.
@@ -870,7 +888,7 @@ to do similar job:
       (when (or (equal buffer-or-name (car buffer-info))
                 (equal buffer-or-name (cdr buffer-info)))
         (with-current-buffer buffer-or-name
-          (apply #'posframe--fit-frame-to-buffer
+          (apply #'posframe--set-frame-size
                  frame posframe--last-posframe-size))))))
 
 (defun posframe-hide (buffer-or-name)



reply via email to

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