Emacs implements vim and textmate features...

Source: Internet
Author: User
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 ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.