overtone / emacs-live

M-x start-hacking
http://overtone.github.com/emacs-live/
Other
1.51k stars 242 forks source link

`set-window-buffer` does not work in dedicated window #201

Open rothmichaels opened 9 years ago

rothmichaels commented 9 years ago

When working on #198, I was able to come to a better understanding of the issues I brought up with monkey-patch.el in #153.

live-mp-new-basic-save-buffer calls set-window-buffer to move the buffer that is pending a save to the current window. According to the documentation for set-window-buffer, it will throw an error if called from a dedicated window:

This function throws an error when WINDOW is strongly dedicated to its buffer (that is `window-dedicated-p' returns t for WINDOW) and does not already display BUFFER-OR-NAME.

Some modes, such as ediff-mode, use a dedicated window as a control panel for enter commands to be run on buffers in other windows. In ediff-mode for example, the frame is divided into windows for the three buffers involved with the merge (base, current, and merged) and a fourth dedicated window for the *Ediff Control Panel*. When entering commands, including saving the merge, the *Ediff Control Panel* is the current selected window and a call to set-window-buffer will throw an error.

One solution is to replace the call to (set-window-buffer (frame-selected-window) (current-buffer)) with (switch-to-buffer (current-buffer)). If switch-to-buffer will not give you your desired behavior, then I would suggest replacing the call only when in a dedicated buffer:

(let ((the-window (frame-selected-window))
  (if (window-dedicated-p the-window)
    (switch-to-buffer (current-window))
    (set-window-buffer the-window)))

If you like one of these solutions, let me know and I'll make a pull request.

rothmichaels commented 9 years ago

Don't worry, that's everything I've found / could think of so that's the last issue/pull-request for now ;)

rothmichaels commented 9 years ago

My apologies, my suggestion above was incorrect (somehow must have pasted the wrong thing while working on debugging this). Here is what I meant to suggest.

(let ((the-window (frame-selected-window))
      (the-buffer (current-buffer)))
  (if (window-dedicated-p the-window)
      (switch-to-buffer the-buffer)
    (set-window-buffer the-window the-buffer)))