Iterate among all buffers that are displayed (i.e., have a window), widening each:
(defun foo ()
(dolist (buf (buffer-list))
(when (get-buffer-window buf 0)
(with-current-buffer buf (widen)))))
Or if you want to do it to all (live) buffers, even if they aren't displayed in a window, then this:
(defun foo ()
One way to do it is by comparing the current-time with the buffer-display-time. If the gap is small enough it means it was most likely a buffer change that ran the hook.
(defun my-test-scroll-or-buffer-change (window _window-start-after)
(if (> 0.001 (float-time (time-subtract (current-time) buffer-display-time)))
I took a look at the implementation of switch-to-prev-buffer (thanks Tobias! I didn't think to look there…), found the function window-prev-buffers and came up with this:
(defun previous-buffer-cycle ()
"Switch to the buffer previously displayed in the current
(pop-to-buffer-same-window (caar (window-prev-buffers))))
Doc-string of the command previous-buffer:
In selected window switch to ARGth previous buffer.
Call switch-to-prev-buffer unless the selected window is the
minibuffer window or is dedicated to its buffer.
It is bound to C-x C-left.
There is also the command mode-line-previous-buffer which does the same as previous-buffer but first selects the window from ...
C-x 5 2 does what you request: it opens the current buffer in a separate frame. But it does not delete the original window showing the buffer in the original frame.
Command tear-off-window does both: opens the buffer in a separate frame and deletes its window from the original frame.
Personally, I bind tear-off-window to C-x 5 1. (I don't use that key's ...
(defun switch-buffer-delete-other-windows ()
(defun find-file-delete-other-windows ()
and so on…?