Skip to content

Commit

Permalink
Support max-width for popup instance
Browse files Browse the repository at this point in the history
Patch of pull request #29 cannot be merged now. I fix it for
current popup.el.
  • Loading branch information
syohex committed Jan 23, 2014
1 parent c3ebfba commit 69d5bf9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,18 @@ 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

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.

Expand Down Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion popup.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -474,6 +481,7 @@ number at the point."
height
&key
min-height
max-width
around
(face 'popup-face)
mouse-face
Expand All @@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -996,6 +1009,7 @@ HELP-DELAY is a delay of displaying helps."
width
(height 15)
min-height
max-width
truncate
margin
margin-left
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 69d5bf9

Please sign in to comment.