Matt
Matt

Reputation: 754

Emacs: Is it possible to set one particular window to always be used as the "other window"?

There are many useful emacs commands that do things in the "other window" (like C-x C-b to see the buffer list, or C-h a to view available commands, or many others).

My problem: This does not seem to play well with using a number of carefully arranged windows in one frame, each showing specific content.

Anytime I use one of these "other window" commands, it replaces the content of some other window, which (1) might be too narrow to clearly show the information being displayed, and (2) might need to be manually "cleaned up" afterwards, by setting it back to its correct buffer. (And you'd better not check the buffer list when doing this, or you'll mess up yet another window!)

(Emacs does not even always use the same "other window", even when the commands are issued from the same window. For example, the C-x C-b output might go into one "other" window while C-h a shows its results in a different "other" window. Likewise, C-M-v sometimes scrolls a different "other" window from that in which output just appeared.)

I would like a way to solve or work around this problem, such as:

  1. I would really like to be able to specify a particular window to always be used as the "other window" for any window in that frame.

  2. Failing that, perhaps there is a way to rearrange the window order and/or use invisible windows (if such exist) to get the effect of solution 1 by doing a lot of behind-the-scenes window shuffling, perhaps requiring an extra command to be entered before or preferably after the command that writes into an "other window".

  3. Failing those, I would like a command that undoes the most recent buffer change in any window, so whatever window was used goes back to what it was showing just before it was used.

(Currently I use workgroups.el and I use a separate workgroup for checking the documentation, but this is clearly suboptimal. "Updating" the workgroup does not achieve solution 3, since it seems to only change the buffer back if it was a regular file.)

EDIT: I see this question is very similar to this similar question, but that question did not get the answer it was looking for. Since the ideal solution might not exist, I am explicitly interested in work-arounds as well.

Upvotes: 5

Views: 857

Answers (3)

Tak Kunihiro
Tak Kunihiro

Reputation: 1

A solution for #1 came to me last week. The idea is to dedicate all windows but your concern. By this way you can lock-on a window. It sounds a little opposite.

(defvar window-locked-p nil)
(defun lockon-window ()
  "Set a target window to be used when calls `other-window'.
To set the target window, first put point to the window, then
call this.  Technically this sets all window dedicated but the
target window.  Call again to free windows."
  (interactive)
  (walk-windows
   (lambda (win)
     (set-window-dedicated-p win (not window-locked-p))))
  (if window-locked-p
      (message "All windows are free")
    (set-window-dedicated-p (selected-window) nil)
    (message "Window is locked on"))
  (setq window-locked-p (not window-locked-p)))

A solution for #3 came to me when I was listening to Slide Thing by Stevie Ray Vaughan & Double Trouble. A popped up buffer is located one layer above other buffers.

(winner-mode 1)
(defun slide-window ()
  "This slides a buffer, in an unexpected window, to next-window.
Call this with point on the window.  This only works soon after a
buffer was popped by `other-window' to an unexpected window.
Technically this recalls previous buffer-set by (winner-undo)
then shows the buffer to next-window.  This is complementary to
`lockon-window'."
  (interactive)
  (let ((buf (buffer-name)))
    (winner-undo)
    (set-window-buffer (next-window) buf)
    (message "Window is slided")
    (other-window 1)))

Upvotes: 0

Kei Minagawa
Kei Minagawa

Reputation: 4521

All people will disagree my answer. But someone may think this is productive.

Do everything one window per frame.

;;Disable split-window
(defun split-window-below ()
  (interactive)
  ;;do nothing
)

(defun split-window-right ()
  (interactive)
  ;;do nothing
)

Then you can't split-window anymore. If you need to display another buffer, use another frame(C-x52).

Upvotes: 1

user2053036
user2053036

Reputation:

Failing those, I would like a command that undoes the most recent buffer change in any window, so whatever window was used goes back to what it was showing just before it was used.

A possible solution is to use winner-mode. Activate it by adding

(winner-mode 1)

It provides two command winner-undo and winner-redo that undo and redo window configurations respectively.

Also since you mention workgroups.el give a try to workgroups2, a fork of workgroups.el. It provides similar commands (wg-undo-wconfig-change and wg-redo-wconfig-change) for restoring window-configurations

Upvotes: 0

Related Questions