completion/helm: refactor posframe support (again)

This commit is contained in:
Henrik Lissner 2018-08-07 14:42:58 +02:00
parent 85e837e06a
commit 3d363d4cb1
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 19 additions and 33 deletions

View file

@ -17,36 +17,18 @@ bottom, which is easier on the eyes on big displays."
;;;###autoload
(defun +helm-posframe-display (buffer &optional _resume)
"TODO"
(setq +helm--posframe-last-window (selected-window))
(require 'posframe)
(setq helm--buffer-in-new-frame-p t)
(setq +helm--posframe-last-window (selected-window)
helm--buffer-in-new-frame-p t)
(posframe-show
(setq +helm--posframe-buffer buffer)
:position (point)
:poshandler +helm-posframe-handler
:internal-border-width +helm-posframe-border-width
:respect-header-line t
:respect-mode-line t
:width
(cond ((functionp helm-display-buffer-default-width)
(funcall helm-display-buffer-default-width))
((integerp helm-display-buffer-default-width)
helm-display-buffer-default-width)
((floatp helm-display-buffer-default-width)
(truncate (* (frame-width) helm-display-buffer-default-width)))
((min (max (truncate (* (frame-width) 0.8))
100)
140)))
:height
(cond ((functionp helm-display-buffer-default-height)
(funcall helm-display-buffer-default-height))
((integerp helm-display-buffer-default-height)
helm-display-buffer-default-height)
((floatp helm-display-buffer-default-height)
(truncate (* (frame-height) helm-display-buffer-default-height)))
((truncate (* (frame-height) 0.4)))))
(when +helm-posframe-font-scale
:override-parameters +helm-posframe-parameters)
(unless (or (null +helm-posframe-text-scale)
(= +helm-posframe-text-scale 0))
(with-current-buffer buffer
(text-scale-set +helm-posframe-font-scale))))
(text-scale-set +helm-posframe-text-scale))))
;;;###autoload
(defun +helm|posframe-cleanup ()
@ -54,7 +36,10 @@ bottom, which is easier on the eyes on big displays."
;; Ensure the underlying window is switched to, to ensure that frame is given
;; proper focus; this gives the modeline a chance to refresh.
(select-window +helm--posframe-last-window)
(setq +helm--posframe-last-frame nil)
;;
(posframe-delete +helm--posframe-buffer))
;;;###autoload
(defun +helm*fix-get-font-height (orig-fn position)
(ignore-errors (funcall orig-fn position)))

View file

@ -20,13 +20,17 @@ This falls back to git-grep (then grep) if none of these available.")
a cons cell representing the X and Y coordinates. See
`posframe-poshandler-frame-center' as a reference.")
(defvar +helm-posframe-font-scale 1
(defvar +helm-posframe-text-scale 1
"The text-scale to use in the helm childframe. Set to nil for no scaling. Can
be negative.")
(defvar +helm-posframe-border-width 8
"The text-scale to use in the helm childframe. Set to nil for no scaling. Can
be negative.")
(defvar +helm-posframe-parameters
'((internal-border-width . 8)
(min-width . 80)
(min-height . 16)
(width . 0.5)
(height . 0.55))
"TODO")
;;
@ -78,11 +82,8 @@ be negative.")
(when (and EMACS26+ (featurep! +childframe))
(setq helm-display-function #'+helm-posframe-display
helm-display-buffer-default-height 0.42
helm-echo-input-in-header-line t)
;; Fix "Specified window is not displaying the current buffer" error
(defun +helm*fix-get-font-height (orig-fn position)
(ignore-errors (funcall orig-fn position)))
(advice-add #'posframe--get-font-height :around #'+helm*fix-get-font-height))
(let ((fuzzy (featurep! +fuzzy)))