emacs: Orgmode, how to make a list from a block of lines

谁都会走 提交于 2019-12-20 09:55:54

问题


Is there a way to covert such block of lines

line1  
line2 
linen

into

1. line1
2. line2
n. linen

Using Emacs org mode


回答1:


don't know if there is a direct way, haven't heard of it yet at least. But one approach would be to use string-rectangle (C-x r t) to prepand 1. to all lines and then hit C-c C-c to update the numbering.

For string-rectangle you would put point and mark the following way:

v---mark
line1 with some text
line2 with more text
<---point

After M-x: string-rectangle: 1. you will get:

1. line1 with some text
1. line2 with more text

Hitting C-c C-c will give you the correct numbering!

Easier because it gives you visual feedback is to enable CUA-mode and use C-return to create a rectangle selection, then you can start typing on all lines in parallel. See also this video on youtube.




回答2:


the shortest way I know of is: highlight the lines, including their newline character,

line1
line2
line3

Then execute M-x org-ctrl-c-minus (press C-c -) and you will get

- line1  
- line2 
- line3

Then run M-x org-shiftright (press <S-right>) twice and you get the desired

1. line1  
2. line2 
3. line3



回答3:


See also org-toggle-item to convert to plain-text list or numbered list.




回答4:


Found this on emacsworld.blogspot.com (I made some minor edits):

In Emacs 24.1, the NEWS file had this new addition to the rectangle commands.

** New command `C-x r N' (`rectangle-number-lines') numbers the lines in the current rectangle. With a prefix argument, this prompts for a number to count from and for a format string.

This allows you to now number lines or lists easily without using a macro or additional elisp functions. Mark a vertical region of text (using transient mark mode may help), 1 character wide, and then hit C-x r N and that's it. Emacs numbers the lines.

If you use the prefix command C-u (for example, C-u C-x r N), it will prompt you for a starting digit and the format string, so you can start at an arbitrary number and specify a period or paren or whatever to precede or follow the number.



来源:https://stackoverflow.com/questions/2250930/emacs-orgmode-how-to-make-a-list-from-a-block-of-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!