unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* managing windows in two frames
@ 2013-09-03  9:11 Stephen Leake
  2013-09-03 12:52 ` martin rudalics
  2013-09-03 13:59 ` Stefan Monnier
  0 siblings, 2 replies; 36+ messages in thread
From: Stephen Leake @ 2013-09-03  9:11 UTC (permalink / raw)
  To: emacs-devel

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)
			(and
			 (not (eq frame (selected-frame)))
			 (not (window-dedicated-p
			       (or
				(get-lru-window frame)
				(frame-first-window frame)))))))))
	 (window
	  (and frame
	       (or
		(get-lru-window frame)
		;; lru-window can be nil if window was deleted, by ediff for example
		(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."
  (or
   (cond
    ((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."
  (interactive)
  (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 frame
      (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
keys).

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
      '((display-buffer-reuse-window
	 display-buffer-other-window-or-frame)
	.
	((reusable-frames . visible))))

Thoughts?

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2013-09-09 14:05 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-03  9:11 managing windows in two frames Stephen Leake
2013-09-03 12:52 ` martin rudalics
2013-09-04 18:16   ` Stephen Leake
2013-09-04 18:24     ` Stephen Leake
2013-09-04 19:33     ` Stefan Monnier
2013-09-04 21:22       ` Stephen Leake
2013-09-06 10:53         ` martin rudalics
2013-09-07  8:49           ` Stephen Leake
2013-09-07  9:37             ` martin rudalics
2013-09-07 13:19               ` Stephen Leake
2013-09-08  7:56                 ` martin rudalics
2013-09-04 21:33       ` Drew Adams
2013-09-06 10:52       ` martin rudalics
2013-09-06 13:22         ` Stefan Monnier
2013-09-06 10:52     ` martin rudalics
2013-09-07  8:56       ` Stephen Leake
2013-09-07  9:37         ` martin rudalics
2013-09-07 13:29           ` Stephen Leake
2013-09-03 13:59 ` Stefan Monnier
2013-09-03 14:15   ` martin rudalics
2013-09-03 14:30     ` Stefan Monnier
2013-09-03 16:23       ` martin rudalics
2013-09-03 20:34         ` Stefan Monnier
2013-09-04  6:25           ` martin rudalics
2013-09-04 13:24             ` Stefan Monnier
2013-09-04 15:04               ` martin rudalics
2013-09-04 17:44                 ` Stefan Monnier
2013-09-06 10:53                   ` martin rudalics
2013-09-06 13:44                     ` Stefan Monnier
2013-09-06 17:14                       ` martin rudalics
2013-09-06 19:00                         ` Stefan Monnier
2013-09-07  9:37                           ` martin rudalics
2013-09-08 17:55                             ` Stefan Monnier
2013-09-09  8:10                               ` martin rudalics
2013-09-09 14:05                                 ` Stefan Monnier
2013-09-04 18:19   ` Stephen Leake

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).