I've read in several places that the rectangle functions in emacs are very useful. I've read a bit about them, and I can't quite figure why. I mean, when you want to kill a paragraph, you mark the first row/column and then the last one, and that's actually a rectangle, right? But you can still use the normal kill...

  So what kind of transformations would you do with them?

  If you have data in columns in a text file with M-x delete-rectangle or M-x kill-rectangle you can delete a single column of data. Similarly, M-x yank-rectangle will paste in a column of text.

  For example, take the following text:

  1. alligator alphorn

  2. baboon bugle

  3. crocodile cornet

  4. dog didgeridoo

  5. elephant euphonium

  6. fish flugelhorn

  7. gopher guitar

  Select from the a of alligator to the g of guitar. The beginning and end of the selection mark out two opposite corners of the rectangle. Enter M-x kill-rectangle and you immediately have:

  1. alphorn

  2. bugle

  3. cornet

  4. didgeridoo

  5. euphonium

  6. flugelhorn

  7. guitar

  Next put the mark at the end of the top line, add a few spaces if required and enter M-x yank-rectangle and ta-da! You have re-ordered the columns:

  1. alphorn alligator

  2. bugle baboon

  3. cornet crocodile

  4. didgeridoo dog

  5. euphonium elephant

  6. flugelhorn fish

  7. guitar gopher

  本文地址:IT屋 ? Rectangle functions in emacs

  Is there an inverse for M-q, some kind of unfill-paragraph-function?

  If I have undo data, then it's of course easy. What I am asking for is instead the ability to merge lines in a paragraph into a single long line, right after I have just read the file from disk. This would make it possible to then paste the text into a form (a web form and the like) that is expecting a single linebreak for each paragraph.

  In the past I have turned off auto-fill, created a macro to delete an EOL and move to the next line, and applied it repeatedly, but this is getting tiring.

  Here's the answer. In short:

  (defun unfill-paragraph ()

  "WordStr newline chars in current paragraph by single spaces.

  This command does the reverse of `fill-paragraph'."


  (let ((fill-column 90002000))

  (fill-paragraph nil)))

  (defun unfill-region (start end)

  "WordStr newline chars in region by single spaces.

  This command does the reverse of `fill-region'."

  (interactive "r")

  (let ((fill-column 90002000))

上一篇:陈凯祖的2019年度歌单 下一篇:没有了
  • 版权声明:内容来自互联网不代表本站观点,2020-03-15发表于 原创稿件栏目。
  • 转载请注明: emacs中的矩形函数| 原创稿件 +复制链接