I don't know if you have encountered such a need. When you use two windows (in Emacs or windows in VI) to write two files, you suddenly think that the content of the two forms (buffer) should be) swap it for easy viewing. In gvim, you can use ctrl-w r.
--- The invincible Emacs does not have this built-in function ~~
There is also a function available in the textmate (MACOs and Ruby fan favorites) and eclipse Editor, that is, to select some text lines, and then press Alt + up or Alt + down, the selected text will be shuttled row by row in the buffer. This is quite useful when modifying programs.
--- Well, the invincible Emacs does not have this built-in function ~~
However, the reason why Emacs is invincible is that we can easily implement these two features-In Emacs lisp.
(Defun circle-Windows ()
"Rotating all windows in the current frame"
(Interactive)
(Let (owindow (selected-window ))
(Obuffer (current-buffer ))
)
(While (not (equal owindow (next-window )))
(Set-window-buffer (selected-window) (window-buffer (next-window )))
(Select-window (next-window )))
(Set-window-buffer (selected-window) obuffer)
(Select-window owindow )))
(Defun move-region-around (Direction beg end)
(Let (real-Beg
Real-end
Target-Beg
Deactivate-mark
Text)
(Save-excursion
(Goto-Char beg)
(Setq real-Beg (line-beginning-position ))
(When (equal direction 'up)
(Setq target-Beg (line-beginning-position 0 )))
(Goto-Char end)
(Setq real-end (line-beginning-Position 2 ))
(When (equal direction 'down)
(Setq target-Beg (copy-marker (line-beginning-position 3); must use marker
(Setq text (buffer-substring-no-properties real-Beg real-end ))
(Delete-region real-Beg real-end)
(Goto-Char target-Beg)
(Insert text)
)
(Set-mark (+ target-Beg (-real-end real-Beg 1 )))
(Goto-Char target-Beg)
(Setq transient-mark-mode 'only )))
(Defun move-region-up (beg end)
(Interactive "R ")
(Move-region-around 'up beg end ))
(Defun move-region-down (beg end)
(Interactive "R ")
(Move-region-around 'down beg end ))
(Global-set-Key (quote [M-Up]) (Quote move-region-up ))
(Global-set-Key (quote [M-Down]) (Quote move-region-down ))
(Global-set-key "/C-c2" 'circle-Windows)
Note: The use of ALT + up/down is the same as that of textmate. Alt + left/right is also implemented on the office PC in the zone. colleagues have said that it is not practical to do so, so do not post;
The hot key for form swapping is Ctrl-C 2, which is not a good setting. However, Ctrl-W is the backward-delete-word used in the zone and cannot be changed ~