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

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

[nongnu] elpa/popup 69d5bf9 095/184: Support max-width for popup instanc


From: ELPA Syncer
Subject: [nongnu] elpa/popup 69d5bf9 095/184: Support max-width for popup instance
Date: Wed, 6 Oct 2021 00:01:19 -0400 (EDT)

branch: elpa/popup
commit 69d5bf9e42bdf11b0d5d78800c1c6d97289ea4aa
Author: Syohei YOSHIDA <syohex@gmail.com>
Commit: Syohei YOSHIDA <syohex@gmail.com>

    Support max-width for popup instance
    
    Patch of pull request #29 cannot be merged now. I fix it for
    current popup.el.
---
 README.md |  8 ++++++--
 popup.el  | 19 ++++++++++++++++++-
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index f4b1814..c2e2c3c 100644
--- a/README.md
+++ b/README.md
@@ -117,7 +117,7 @@ All of these fields can be accessed by `popup-<field>` 
function.
 
 ### Function: `popup-create`
 
-    popup-create point width height &key min-height around face
+    popup-create point width height &key min-height max-width around face
     selection-face scroll-bar margin-left margin-right symbol parent
     parent-offset => popup
 
@@ -125,6 +125,10 @@ Create a popup instance at `POINT` with `WIDTH` and 
`HEIGHT`.
 
 `MIN-HEIGHT` is the minimal height of the popup. The default value is 0.
 
+`MAX-WIDTH` is the maximum width of the popup. The default value is
+nil (no limit). If a floating point, the value refers to the ratio of
+the window. If an integer, limit is in characters.
+
 If `AROUND` is non-nil, the popup will be displayed around the point
 but not at the point.
 
@@ -244,7 +248,7 @@ something about what cursor points to.
 
 ### Function: `popup-tip`
 
-    popup-tip string &key point around width height min-height
+    popup-tip string &key point around width height min-height max-width
     truncate margin margin-left margin-right scroll-bar parent
     parent-offset nowait nostrip prompt
 
diff --git a/popup.el b/popup.el
index b00c6b8..7767cb0 100644
--- a/popup.el
+++ b/popup.el
@@ -37,6 +37,13 @@
 
 ;;; Utilities
 
+(defun popup-calculate-max-width (max-width)
+  "Determines whether the width desired is
+character or window proportion based, And returns the result."
+  (cl-typecase max-width
+    (integer max-width)
+    (float (* (ceiling (/ (round (* max-width (window-width))) 10.0)) 10))))
+
 (defvar popup-use-optimized-column-computation t
   "Use the optimized column computation routine.
 If there is a problem, please set it nil.")
@@ -474,6 +481,7 @@ number at the point."
                         height
                         &key
                         min-height
+                        max-width
                         around
                         (face 'popup-face)
                         mouse-face
@@ -491,6 +499,10 @@ number at the point."
 MIN-HEIGHT is a minimal height of the popup. The default value is
 0.
 
+MAX-WIDTH is the maximum width of the popup. The default value is
+nil (no limit). If a floating point, the value refers to the ratio of
+the window. If an integer, limit is in characters.
+
 If AROUND is non-nil, the popup will be displayed around the
 point but not at the point.
 
@@ -521,7 +533,8 @@ KEYMAP is a keymap that will be put on the popup contents."
   (unless point
     (setq point
           (if parent (popup-child-point parent parent-offset) (point))))
-
+  (when max-width
+    (setq width (min width (popup-calculate-max-width max-width))))
   (save-excursion
     (goto-char point)
     (let* ((row (line-number-at-pos))
@@ -996,6 +1009,7 @@ HELP-DELAY is a delay of displaying helps."
                      width
                      (height 15)
                      min-height
+                     max-width
                      truncate
                      margin
                      margin-left
@@ -1036,6 +1050,7 @@ PROMPT is a prompt string when reading events during 
event loop."
 
   (setq tip (popup-create point width height
                           :min-height min-height
+                          :max-width max-width
                           :around around
                           :margin-left margin-left
                           :margin-right margin-right
@@ -1272,6 +1287,7 @@ PROMPT is a prompt string when reading events during 
event loop."
                        (around t)
                        (width (popup-preferred-width list))
                        (height 15)
+                       max-width
                        margin
                        margin-left
                        margin-right
@@ -1332,6 +1348,7 @@ isearch canceled. The arguments is whole filtered list of 
items."
       ;; Make scroll-bar space as margin-right
       (cl-decf margin-right))
   (setq menu (popup-create point width height
+                           :max-width max-width
                            :around around
                            :face 'popup-menu-face
                            :mouse-face 'popup-menu-mouse-face



reply via email to

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