I have a buffer that I want to "toggle" opening in a window in emacs on a keypress.
For example:
________________ ________________ ________________
| | | | | | |
| | | | | | |
| | | | | | |
| W | -> | S | W | -> | W |
| | <f3> | | | <f3> | |
| | | | | | |
---------------- ---------------- ----------------
Where S
in the left hand side window is a specific buffer.
The problem arises that this should happen regardless of what the window structure of W
is. If W
has a couple of different windows in it, pressing <F3>
should still create a new window at the edge of the screen, and put the specific buffer in it, and then it should take it away.
I'm not really sure how to do this is emacs however.
Try this as the starting point, it needs package popwin
.
(require 'popwin)
(popwin-mode 1)
(generate-new-buffer "special-buffer")
(setq eab/special-buffer-displaedp nil)
(setq eab/special-buffer "special-buffer")
(add-to-list 'popwin:special-display-config
`(,eab/special-buffer :width 20 :position left :stick t))
(defun eab/special-buffer-toggle ()
(interactive)
(if eab/special-buffer-displaedp
(progn
(popwin:close-popup-window)
(setq eab/special-buffer-displaedp nil))
(progn
(ignore-errors (popwin:display-buffer eab/special-buffer))
(setq eab/special-buffer-displaedp 't))))
(global-set-key (kbd "<f3>") 'eab/special-buffer-toggle)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With