blob: 0ac99a5565bd5554ee08cdc6b5b0f7bef36d6113 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
;;; -*- lexical-binding: t; -*-
;;; Window placement
;;; TODO: Test popper.el.
;; (global-set-key (kbd "C-`") #'window-toggle-side-windows)
;; (global-set-key (kbd "M-`") #'kj/popup-toggle-override)
;; (setq window-sides-slots '(0 0 2 2)) ; 2 right side windows
(setq switch-to-buffer-obey-display-actions t)
(setq switch-to-buffer-in-dedicated-window 'pop)
(setq even-window-sizes 'width-only)
(defvar kj/popup-override nil)
(defun kj/popup-clear-overrides ()
(interactive)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(kill-local-variable 'kj/popup-override))))
(defun kj/popup-toggle-override ()
(interactive)
(if (local-variable-p 'kj/popup-override)
(kill-local-variable 'kj/popup-override)
(setq-local kj/popup-override
(not (kj/popup-buffer-base (buffer-name)))))
(let ((buffer (buffer-name)))
(switch-to-prev-buffer)
(switch-to-buffer buffer)))
(defun kj/popup-buffer-base (buffer &optional condition)
(or
(s-matches-p
(rx (| "*Help*"
"*info*"
(seq "*Messages*")
(seq "*Warnings*")
(seq "*Backtrace*")
(seq "*eldoc " (* anything) "*")
(seq "*WoMan " (* anything) "*")
(seq "*man " (* anything) "*")
(seq "fig: " (* anything))
(seq "*htop*" (* anything))
(seq "*Proced*" (* anything))
(seq "*eshell" (* anything))
(seq "*shell" (* anything))
"*Occur*")) buffer)
(with-current-buffer buffer
(apply #'derived-mode-p
'(magit-mode
compilation-mode
shell-mode
comint-mode
Custom-mode ; For customization
fig-commit-mode)))))
(defun kj/popup-buffer (buffer &optional condition)
(with-current-buffer buffer
(if (local-variable-p 'kj/popup-override)
kj/popup-override
(kj/popup-buffer-base buffer condition))))
;; (setq transient-display-buffer-action
;; '(display-buffer-in-best-side
;; (slot . -1)
;; (inhibit-same-window . t)
;; (window-parameters
;; (no-other-window . t))))
(defun kj/display-new-popup (buffer alist)
(let ((popup-window
(display-buffer-in-direction
buffer
(append (if (> (frame-width) 160)
'((direction . rightmost)
(window-width . 80))
'((direction . bottom)))))))
(set-window-parameter popup-window 'kj/popup t)
popup-window))
(defun kj/find-popup-window ()
(seq-find
(lambda (w)
(window-parameter w 'kj/popup))
(window-list)))
(defun display-popup-buffer (buffer alist)
(let ((window (kj/find-popup-window)))
(if window
(window--display-buffer buffer window 'reuse alist)
(kj/display-new-popup buffer alist))))
;; (add-to-list 'display-buffer-alist
;; `(kj/popup-buffer
;; (display-popup-buffer)
;; (slot . 0)))
(provide 'kj-popup)
|