2009-10-02 36 views

Trả lời

7

Tôi không biết xấu hổ lấy trộm này từ Steve Yegge's .emacs

(defun swap-windows() 
    "If you have 2 windows, it swaps them." 
    (interactive) 
    (cond ((not (= (count-windows) 2)) (message "You need exactly 2 windows to do this.")) 
     (t 
     (let* ((w1 (first (window-list))) 
       (w2 (second (window-list))) 
       (b1 (window-buffer w1)) 
       (b2 (window-buffer w2)) 
       (s1 (window-start w1)) 
       (s2 (window-start w2))) 
      (set-window-buffer w1 b2) 
      (set-window-buffer w2 b1) 
      (set-window-start w1 s2) 
      (set-window-start w2 s1))))) 

Thử nghiệm trên Emacs 23.1.1 trên Gentoo. Điều này bảo toàn kích thước cửa sổ.

Tôi cũng tìm thấy thứ này sạch hơn một chút.

(defun transpose-windows() 
    (interactive) 
    (let ((this-buffer (window-buffer (selected-window))) 
     (other-buffer (prog2 
          (other-window +1) 
          (window-buffer (selected-window)) 
         (other-window -1)))) 
    (switch-to-buffer other-buffer) 
    (switch-to-buffer-other-window this-buffer) 
    (other-window -1))) 

Ngoài ra thử nghiệm trên Emacs 23.1.1

+0

Tôi vừa xem bài đăng của Stevey :) – chollida

4

Phiên bản sau đây làm việc với bất kỳ số lượng các cửa sổ. Khi có nhiều hơn hai cửa sổ, các lời gọi lặp đi lặp lại sẽ làm cho bộ đệm được chọn xuất hiện trong mỗi cửa sổ liên tiếp.

 
(defun swap-buffer() 
    (interactive) 
    (cond ((one-window-p) (display-buffer (other-buffer))) 
     ((let* ((buffer-a (current-buffer)) 
       (window-b (cadr (window-list))) 
       (buffer-b (window-buffer window-b))) 
      (set-window-buffer window-b buffer-a) 
      (switch-to-buffer buffer-b) 
      (other-window 1))))) 
2

Tôi thấy thư viện TransposeFrame hữu ích. Tôi chủ yếu là sử dụng nó để hoán đổi hai cửa sổ, theo câu hỏi này; nhưng nó cung cấp chức năng tổng quát hơn chỉ là vậy.

Theo liên kết để xem biểu đồ ascii của các phép biến đổi khác nhau.

Các vấn đề liên quan