completion/helm: refactor posframe config
This commit is contained in:
parent
7f5e778b0c
commit
860dff3e63
3 changed files with 86 additions and 25 deletions
59
modules/completion/helm/autoload/posframe.el
Normal file
59
modules/completion/helm/autoload/posframe.el
Normal file
|
@ -0,0 +1,59 @@
|
|||
;;; completion/helm/autoload/posframe.el -*- lexical-binding: t; -*-
|
||||
|
||||
(add-hook 'helm-cleanup-hook #'+helm|posframe-cleanup)
|
||||
|
||||
;;;###autoload
|
||||
(defun +helm-poshandler-frame-center-near-bottom (info)
|
||||
"Display the child frame in the center of the frame, slightly closer to the
|
||||
bottom, which is easier on the eyes on big displays."
|
||||
(let ((parent-frame (plist-get info :parent-frame))
|
||||
(pos (posframe-poshandler-frame-center info)))
|
||||
(cons (car pos)
|
||||
(truncate (/ (frame-pixel-height parent-frame)
|
||||
1.8)))))
|
||||
|
||||
(defvar +helm--posframe-buffer nil)
|
||||
(defvar +helm--posframe-last-window nil)
|
||||
;;;###autoload
|
||||
(defun +helm-posframe-display (buffer &optional _resume)
|
||||
"TODO"
|
||||
(setq +helm--posframe-last-window (selected-window))
|
||||
(require 'posframe)
|
||||
(posframe-show
|
||||
(setq +helm--posframe-buffer buffer)
|
||||
:poshandler +helm-posframe-handler
|
||||
:internal-border-width (truncate (/ (frame-fringe-width) 2))
|
||||
: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
|
||||
(with-current-buffer buffer
|
||||
(text-scale-set +helm-posframe-font-scale))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +helm|posframe-cleanup ()
|
||||
"TODO"
|
||||
;; 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))
|
||||
|
|
@ -13,6 +13,17 @@ silently ignored.
|
|||
|
||||
If you want to already use git-grep or grep, set this to nil.")
|
||||
|
||||
;; Posframe (requires +childframe)
|
||||
(defvar +helm-posframe-handler
|
||||
#'+helm-poshandler-frame-center-near-bottom
|
||||
"The function that determines the location of the childframe. It should return
|
||||
a cons cell representing the X and Y coordinates. See
|
||||
`posframe-poshandler-frame-center' as a reference.")
|
||||
|
||||
(defvar +helm-posframe-font-scale 1
|
||||
"The text-scale to use in the helm childframe. Set to nil for no scaling. Can
|
||||
be negative.")
|
||||
|
||||
|
||||
;;
|
||||
;; Packages
|
||||
|
@ -50,7 +61,15 @@ If you want to already use git-grep or grep, set this to nil.")
|
|||
helm-ff-auto-update-initial-value nil
|
||||
helm-find-files-doc-header nil
|
||||
;; Don't override evil-ex's completion
|
||||
helm-mode-handle-completion-in-region nil)
|
||||
helm-mode-handle-completion-in-region nil
|
||||
;; default sizes
|
||||
helm-display-buffer-default-width nil
|
||||
helm-display-buffer-default-height 0.25)
|
||||
|
||||
(when (and EMACS26+ (featurep! +childframe))
|
||||
(setq helm-display-function #'+helm-posframe-display
|
||||
helm-display-buffer-default-height 0.3)
|
||||
(advice-add #'posframe--get-font-height :override #'ignore))
|
||||
|
||||
(let ((fuzzy (featurep! +fuzzy)))
|
||||
(setq helm-mode-fuzzy-match fuzzy
|
||||
|
@ -154,28 +173,6 @@ If you want to already use git-grep or grep, set this to nil.")
|
|||
:config (setq wgrep-auto-save-buffer t))
|
||||
|
||||
|
||||
(def-package! posframe
|
||||
:when (and EMACS26+ (featurep! +childframe))
|
||||
:after helm
|
||||
:config
|
||||
(defvar +helm--posframe-buffer nil)
|
||||
|
||||
(defun +helm-posframe-display (buffer &optional _resume)
|
||||
(posframe-show
|
||||
(setq +helm--posframe-buffer buffer)
|
||||
:poshandler #'posframe-poshandler-frame-bottom-left-corner
|
||||
:left-fringe 10
|
||||
:width (frame-width)
|
||||
:height 16 ;; ivy/+childframe uses 16
|
||||
:respect-header-line t))
|
||||
|
||||
(defun +helm|posframe-cleanup ()
|
||||
(posframe-hide +helm--posframe-buffer))
|
||||
|
||||
(add-hook 'helm-cleanup-hook #'+helm|posframe-cleanup)
|
||||
(setq helm-display-function #'+helm-posframe-display))
|
||||
|
||||
|
||||
;;
|
||||
;; Evil integration
|
||||
;;
|
||||
|
|
|
@ -179,16 +179,21 @@ buffers.")
|
|||
;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise)
|
||||
(defvar +modeline-remap-face-cookie nil)
|
||||
|
||||
(defun +modeline|focus ()
|
||||
(defun +modeline|focus (&rest _)
|
||||
(when +modeline-remap-face-cookie
|
||||
(require 'face-remap)
|
||||
(face-remap-remove-relative +modeline-remap-face-cookie)))
|
||||
(add-hook 'focus-in-hook #'+modeline|focus)
|
||||
|
||||
(defun +modeline|unfocus ()
|
||||
(defun +modeline|unfocus (&rest _)
|
||||
(setq +modeline-remap-face-cookie (face-remap-add-relative 'mode-line 'mode-line-inactive)))
|
||||
(add-hook 'focus-out-hook #'+modeline|unfocus)
|
||||
|
||||
(add-hook 'helm-after-initialize-hook #'+modeline|unfocus)
|
||||
|
||||
(advice-add #'posframe-hide :after #'+modeline|focus)
|
||||
(advice-add #'posframe-delete :after #'+modeline|focus)
|
||||
|
||||
|
||||
;;
|
||||
;; Helpers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue