How to make the Cx b RET switch to the previous buffer, even if it is already shown in another window?

In short, the question is: in the window, how to quickly switch to the buffer previously visited in this window, even if it is already open in another window?

The following is a more detailed description.

Usually, to switch the window to the previous buffer, it is simply typed C-x b RET. That is, the default argument switch-to-buffer(or ido-switch-buffer) is the previous buffer.

This, however, is not the case when this (previous) buffer is already shown in another window. This is what bothers me.

Consider an example. Suppose I have three buffers ( A, Band C), and two windows showing buffers Aand B( Cnot visible at this point).

Then I also open the buffer Ain the second window. So now I have the buffer Ashown in both windows. Then I switch back ( C-x b RET) to B. After that, it C-x b RETwill lead me not to A, but to C, because it is Aalready displayed in another window.

How to make C-x b RETmore consistent?

Update

After this problem was solved, I realized that I needed more, namely: for a point position, I need to remember each window, not the buffer. Fortunately, there are ready-made solutions:

They are very similar; for a discussion of the differences see here .

+4
source share
2 answers

I found a fix for switch-to-buffer. In the end, he calls

(other-buffer (current-buffer))

:

(other-buffer (current-buffer) t)

. visible-ok t.

, t. , , other-buffer:

(defadvice other-buffer (around fix-switch-to-buffer 
                          (&optional buffer visible-ok frame) activate)
  (setq visible-ok t)
  ad-do-it)

, ido-switch-to-buffer , .

update: ido-switch-to-buffer

ido-make-buffer-list:

(defun ido-make-buffer-list (default)
  (let* ((ido-current-buffers (list (buffer-name (current-buffer))))
         (ido-temp-list (ido-make-buffer-list-1 (selected-frame) ido-current-buffers)))
    (if ido-temp-list
        (nconc ido-temp-list ido-current-buffers)
      (setq ido-temp-list ido-current-buffers))
    (if default
        (setq ido-temp-list
              (cons default (delete default ido-temp-list))))
    (if (bound-and-true-p ido-enable-virtual-buffers)
        (ido-add-virtual-buffers-to-list))
    (run-hooks 'ido-make-buffer-list-hook)
    ido-temp-list))

- , , .

update: other-buffer

, :

(defun other-buffer-advice (orig-fun &optional buffer visible-ok frame)
  (funcall orig-fun buffer t frame))
(advice-add 'other-buffer :around #'other-buffer-advice)
;; (advice-remove 'other-buffer :around #'other-buffer-advice) 
+3

Ido mode:

1 ,

"" "" (.. , ido-switch-buffer , ), ido-mode , ido-default-buffer-method raise-frame selected-window:

(setq ido-default-buffer-method 'selected-window)

Emacs , Ido, .

2 ,

, , ido-make-buffer-list-hook.

ido.el:

;; Changing the list of files
;; --------------------------

;; By default, the list of current files is most recent first,
;; oldest last, with the exception that the files visible in the
;; current frame are put at the end of the list.  A hook exists to
;; allow other functions to order the list.  For example, if you add:
;;
;; (add-hook 'ido-make-buffer-list-hook 'ido-summary-buffers-to-end)
;;
;; then all files matching "Summary" are moved to the end of the
;; list.  (I find this handy for keeping the INBOX Summary and so on
;; out of the way.)  It also moves files matching "output\*$" to the
;; end of the list (these are created by AUCTeX when compiling.)
;; Other functions could be made available which alter the list of
;; matching files (either deleting or rearranging elements.)
+1

Source: https://habr.com/ru/post/1569069/


All Articles