Last active
March 29, 2018 05:41
-
-
Save fuxialexander/5ad46671689d96a29f9865c1c0b42d10 to your computer and use it in GitHub Desktop.
Override helm function to use child-frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun my-helm-display-child-frame (buffer &optional resume) | |
"Display `helm-buffer' in a separate frame. | |
Function suitable for `helm-display-function', | |
`helm-completion-in-region-display-function' | |
and/or `helm-show-completion-default-display-function'. | |
See `helm-display-buffer-height' and `helm-display-buffer-width' to | |
configure frame size." | |
(if (not (display-graphic-p)) | |
;; Fallback to default when frames are not usable. | |
(helm-default-display-buffer buffer) | |
(setq helm--buffer-in-new-frame-p t) | |
(let* ((pos (window-absolute-pixel-position)) | |
(half-screen-size (/ (display-pixel-height x-display-name) 2)) | |
(frame-info (frame-geometry)) | |
(prmt-size (length helm--prompt)) | |
(line-height (frame-char-height)) | |
(default-frame-alist | |
`((parent . ,(selected-frame)) | |
(width . ,helm-display-buffer-width) | |
(height . ,helm-display-buffer-height) | |
(undecorated . t) | |
(left-fringe . 0) | |
(right-fringe . 0) | |
(tool-bar-lines . 0) | |
(line-spacing . 0) | |
(desktop-dont-save . t) | |
(no-special-glyphs . t) | |
(inhibit-double-buffering . t) | |
(tool-bar-lines . 0) | |
(left . ,(- (car pos) | |
(* (frame-char-width) | |
(if (< (- (point) (point-at-bol)) prmt-size) | |
(- (point) (point-at-bol)) | |
prmt-size)))) | |
;; Try to put frame at the best possible place. | |
;; Frame should be below point if enough | |
;; place, otherwise above point and | |
;; current line should not be hidden | |
;; by helm frame. | |
(top . ,(if (> (cdr pos) half-screen-size) | |
;; Above point | |
(- (cdr pos) | |
;; add 2 lines to make sure there is always a gap | |
(* (+ helm-display-buffer-height 2) line-height) | |
;; account for title bar height too | |
(cddr (assq 'title-bar-size frame-info))) | |
;; Below point | |
(+ (cdr pos) line-height))) | |
(title . "Helm") | |
(vertical-scroll-bars . nil) | |
(menu-bar-lines . 0) | |
(fullscreen . nil) | |
(visible . ,(null helm-display-buffer-reuse-frame)) | |
(minibuffer . t))) | |
display-buffer-alist) | |
;; Add the hook inconditionally, if | |
;; helm-echo-input-in-header-line is nil helm-hide-minibuffer-maybe | |
;; will have anyway no effect so no need to remove the hook. | |
(add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe) | |
(with-helm-buffer | |
(setq-local helm-echo-input-in-header-line | |
(not (> (cdr pos) half-screen-size)))) | |
(helm-display-buffer-popup-frame buffer default-frame-alist)) | |
(helm-log-run-hook 'helm-window-configuration-hook))) | |
(setq ;; helm-display-function 'helm-display-buffer-in-own-frame | |
helm-display-function 'my-helm-display-child-frame | |
helm-display-buffer-reuse-frame t | |
helm-display-buffer-width 80) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment