Helm: Add custom helm-split-window-preferred-function

master
Pierre Neidhardt 2017-10-19 14:56:08 +01:00
parent db4e203dfa
commit 6039e6003e
3 changed files with 46 additions and 2 deletions

View File

@ -24,6 +24,7 @@
(evil-leader/set-key
"p" 'emms-pause
"n" 'emms-next))
(with-eval-after-load 'init-helm
(evil-leader/set-key
"b" 'helm-mini

View File

@ -10,7 +10,7 @@
;;; TODO: Pressing "s-a" ('emms-smart-browse) loses the cursor.
;;; Sometimes waiting helps. Calling emms-smart-browse manually does not trigger the issue.
;;; TODO: Spawn select programs in floating mode. (E.g. mpv, mupen64plus, mplayer, qemu, steam, .exe (wine).)
;;; TODO: Spawn select programs in floating mode? (E.g. mpv, mupen64plus, mplayer, qemu, steam, .exe (wine).)
;;; TODO: Separate EXWM buffers and Emacs buffers in `helm-mini'?
;;; TODO: Rendering issue with Qutebrowser
@ -98,7 +98,7 @@
;;; Web browser
(with-eval-after-load 'helm
;; TODO: When follow-mode is one, multiselection is broken.
;; TODO: When follow-mode is on, multiselection is broken.
;; TODO: Default value should be last browser window.
;; TODO: kill-persistent is not persistent.
(defvar exwm/helm-browser-map

View File

@ -54,6 +54,49 @@
helm-window-show-buffers-function 'helm-window-mosaic-fn
helm-window-prefer-horizontal-split t)
;;; REVIEW: Windowing configuration is way complicated. See
;;; https://github.com/emacs-helm/helm/issues/1902.
(defun helm-custom-display-buffer (buffer)
"Custom function to display `helm-buffer' BUFFER."
(display-buffer
buffer `(nil . ((window-height . ,helm-display-buffer-default-height)
(window-width . ,helm-display-buffer-default-width))))
(helm-log-run-hook 'helm-window-configuration-hook))
(defun helm-split-window-combined-fn (window)
"Helm window splitting that combined most standard features.
- With C-u, split inside. With C-u C-u, use same window.
- Else use biggest other window when available.
- Else split horizontally if width>height, vertically otherwise."
(cond
((or (minibufferp helm-current-buffer)
(and
(not (one-window-p t))
(not (equal current-prefix-arg '(4)))
(not (equal current-prefix-arg '(16)))))
;; Find biggest window.
(let (biggest (maxarea 0))
(dolist (w (window-list))
(unless (eq w (selected-window))
(let ((area (* (window-pixel-width w) (window-pixel-height w))))
(when (> area maxarea)
(setq maxarea area
biggest w)))))
biggest))
((equal current-prefix-arg '(16))
;; Same window.
(selected-window))
(t
;; If split inside or if unique window.
(split-window (selected-window) nil
(if (> (window-pixel-width) (window-pixel-height))
'right
'below)))))
(setq helm-display-function 'helm-custom-display-buffer
helm-split-window-preferred-function 'helm-split-window-combined-fn)
;;; From https://github.com/emacs-helm/helm/issues/362.
;;; This is not perfect with evil mode as the cursor type is not right in the
;;; header line and the evil cursor remains in the minibuffer.