[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

managing windows in two frames

From: Stephen Leake
Subject: managing windows in two frames
Date: Tue, 03 Sep 2013 04:11:44 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (windows-nt)

I'd like to add the following functions to Emacs:

(defun display-buffer-reuse-frame (buffer alist)
  "Display BUFFER in an existing frame other than the current frame.
If successful, return the window used; otherwise return nil.

If ALIST has a non-nil `inhibit-switch-frame' entry, avoid
raising the frame.

If ALIST has a non-nil `pop-up-frame-parameters' entry, the
corresponding value is an alist of frame parameters to give the
new frame."
  (let* ((frame (car (filtered-frame-list
                      (lambda (frame)
                         (not (eq frame (selected-frame)))
                         (not (window-dedicated-p
                                (get-lru-window frame)
                                (frame-first-window frame)))))))))
          (and frame
                (get-lru-window frame)
                ;; lru-window can be nil if window was deleted, by ediff for 
                (frame-first-window frame-2))))
    (when window
      (prog1 (window--display-buffer
              buffer window 'frame alist display-buffer-mark-dedicated)
        (unless (cdr (assq 'inhibit-switch-frame alist))
          (window--maybe-raise-frame frame))))

(defun display-buffer-other-window-or-frame (buffer alist)
  "Depending on `current-prefix-arg', show BUFFER in another window or frame.
If current-prefix-arg is:
'(4) - from C-u; show buffer in another window in current frame, creating new 
if needed.
'(16) - from C-u C-u; show buffer in another frame, creating new if needed.
other - return nil."
    ((equal current-prefix-arg '(4)) ;; other window
     (or (display-buffer-use-some-window buffer '((inhibit-same-window . t)))
         (display-buffer-pop-up-window buffer nil)))

    ((equal current-prefix-arg '(16)) ;; other frame
     (or (display-buffer-reuse-frame buffer '((reusable-frames . visible)))   
;; reuse a window in other frame
         (display-buffer-pop-up-frame buffer nil)))

    (t nil)


(defun sal-move-to-other-frame ()
  "Move current buffer to a window in another frame."
  (let ((buffer (current-buffer)))
    (switch-to-prev-buffer nil 'bury)
    (let ((display-buffer-overriding-action
           '((display-buffer-reuse-frame buffer display-buffer-pop-up-frame)
             . '((reusable-frames . visible)))))   ;; reuse a window in other 
      (display-buffer buffer))))

The use case for these:

I use two Emacs frames, side by side, filling the screen. This allows
two things:

1) opening other applications next to an Emacs frame

2) navigating between frames for horizontal movement (using window
manager keys), and between windows for vertical movement (using Emacs

With one Emacs frame, split both horizontally and vertically, I find it
difficult to navigate among the windows.

`display-buffer-reuse-frame' allows displaying a buffer in the other
frame, without always creating a new frame.

`display-buffer-other-window-or-frame' gives the user flexible control
of all buffer display functions, via the prefix arg.

`sal-move-to-other-frame' is convenient for rearranging the buffers in
the display. (needs another name for inclusion in Emacs).

In my ~/.emacs, I set:

(setq display-buffer-base-action
        ((reusable-frames . visible))))


-- Stephe

reply via email to

[Prev in Thread] Current Thread [Next in Thread]