Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs, toggle a specific window

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.

like image 697
Andrew Spott Avatar asked Oct 19 '13 03:10

Andrew Spott


1 Answers

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)
like image 178
artscan Avatar answered Oct 16 '22 01:10

artscan