如何在组织模式下在普通列表项下缩进


12

尽管普通段落很高兴在普通列表项下缩进(使用[SPACE]栏将第一行缩进),但我注意到代码块不喜欢合作。有没有什么办法解决这一问题?

现在,这就是我所拥有的:

- [ ] My plain list item

  Nicely indented paragraph, blah blah blah blah blah blah blah blah
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah
  blah blah blah.

  #+BEGIN_SRC elisp
; Uncooperative code block -> notice that only the first line indents.
(lambda () (do-something-amazing))
(blah-blah-blah)
#+END_SRC

我想得到这个:

- [ ] My plain list item

  Nicely indented paragraph, blah blah blah blah blah blah blah blah
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah
  blah blah blah.

  #+BEGIN_SRC elisp
  ; Happily indented code block -> notice that all code follows with :)
  (lambda () (do-something-amazing))
  (blah-blah-blah)
  #+END_SRC

我强烈考虑使用org-indent-mode
wasamasa

谢谢。我正在使用org-indent-mode。它适用于除源代码块以外的所有内容...我可能做错了什么...您可以使用org-indent缩进源代码吗?
亚当

让我修改一下...源代码块缩进对我来说很好,但仅在标题下,而不在简单列表下……
Adam

(org-list-in-valid-context-p)在src块中会告诉您,默认情况下,组织不希望src块成为允许使用列表的上下文。改变org-list-forbidden-blocks可能会改变这一点,但这不是暂时的defcustom
mutbuerger'8

我的回答有帮助吗?我很高兴更新当前答案或添加新答案。感谢您提出问题!
Melioratus

Answers:


1

尝试这个

我使用以下方法来修复纯列表下src块的缩进。正确设置缩进后,请始终使用M-S-leftM-S-right维护列表缩进。

修复新代码块的格式

<s在普通列表下创建新的src块时,请先缩进光标,然后使用内置模板。

例如 tab <s tab language return

- [ ] My plain list item

  Nicely indented paragraph, blah blah blah blah blah blah blah blah
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah
  blah blah blah.

  <s

修复现有代码块的格式

步骤1-找出所需的缩进列号。对于以下示例,请使用2


- [ ] My plain list item

  Nicely indented paragraph, blah blah blah blah blah blah blah blah
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah
  blah blah blah.

  #+BEGIN_SRC elisp
; Uncooperative code block -> notice that only the first line indents.
(lambda () (do-something-amazing))
(blah-blah-blah)
#+END_SRC

步骤2-将光标放在#+END_SRC行首,然后执行M-xindent-to-column 2 return。之后,您应该看到以下内容:


- [ ] My plain list item

  Nicely indented paragraph, blah blah blah blah blah blah blah blah
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah
  blah blah blah.

  #+BEGIN_SRC elisp
; Uncooperative code block -> notice that only the first line indents.
(lambda () (do-something-amazing))
(blah-blah-blah)
  #+END_SRC

步骤3-通过将光标放在src块内并使用来打开和关闭src块C-' C-'


- [ ] My plain list item

  Nicely indented paragraph, blah blah blah blah blah blah blah blah
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah
  blah blah blah.

  #+BEGIN_SRC elisp
   ; Uncooperative code block -> notice that only the first line indents.
   (lambda () (do-something-amazing))
   (blah-blah-blah)
  #+END_SRC

感谢您提出问题。
希望能有所帮助!


使用以下命令测试了此答案:
GNU Emacs 25.3.1
组织模式:9.1.13


1
除了自己确定缩进之外,还可以选择:移至列表(项目)的开头,键入M-h以标记整个项目,然后C-M-` to reindent that region. That sorts out the position of the 键入END_SRC`标记,但是对于实际代码的缩进,您仍然需要做一些技巧。
安德鲁·斯旺

@AndrewSwann-不错的解决方法!谢谢!
Melioratus
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.