在Org-mode中如何自动创建编号及带缩进的列表项?
How to Implement Auto-Numbered List Features in Org-mode
Hey there, let's tackle your two Org-mode list needs—these are super common workflows, and Org-mode has great built-in tools to handle them smoothly:
1. Auto-Generate Next Numbered Item on Click
Org-mode has native electric indentation that handles this out of the box, but if you want a click-triggered option (or just want to refine the workflow), here's how:
- First, confirm
org-indent-modeis enabled (it’s on by default, but you can toggle it withM-x org-indent-modeif needed). - For the simplest approach: When you’re at the end of a line like
1. some item, just pressRET(Enter)—Org-mode will automatically insert2.on the next line, ready for your input. - If you specifically want a click-based trigger, add this custom function to your Emacs config (
init.elor.emacs):
This binds the middle mouse button to insert the next numbered item. Adjust the mouse key (like(defun org-insert-next-numbered-item () (interactive) (end-of-line) (org-insert-heading-respect-content) (org-do-demote) (org-update-numbering)) (global-set-key (kbd "<mouse-2>") 'org-insert-next-numbered-item)<mouse-1>for left click) to your preference.
2. Auto-Create Indented Numbered List Items on Click
For nested/indented numbered items, Org-mode’s indentation system keeps things consistent, and you can add click triggers too:
- Keyboard shortcut first: When on a numbered item, press
TABto indent it into a sub-list—Org-mode will automatically renumber the entire list correctly. PressRETafter an indented item, and it’ll keep the indentation and numbering for the new entry. - For a click-based indented item, use this modified custom function (binds to right-click here):
(defun org-insert-indented-numbered-item () (interactive) (end-of-line) (org-insert-heading-respect-content) (org-do-demote) (org-do-demote) ; Add another line of this for deeper indentation (org-update-numbering)) (global-set-key (kbd "<mouse-3>") 'org-insert-indented-numbered-item) - Pro tip: Use built-in shortcuts like
M-RET(org-meta-return) to insert a new item at the same indent level, orM-S-RETto insert one above—these are reliable and require no custom config.
To keep lists looking clean, add these settings to your config:
(setq org-auto-align-tags t) (setq org-adapt-indentation t)
内容的提问来源于stack exchange,提问作者Jas
相关产品推荐
相关产品推荐

