使org-blank-before-new-entry区分TODO列表和文本大纲?


10

像我们许多人一样,我将org-mode用于两种不同的情况:

  1. 作为待办事项清单管理员
  2. 作为文字大纲

我希望我的空白行根据上下文而有所不同。

  1. 待办事项清单:无空白行
  2. 文字轮廓:非标题文字在标题之前自动插入1个空白行

换句话说,当我在待办事项列表中连续有多个标题时,我不希望它们之间出现断行。

TODO列表模式,无换行符:

* Organize Party [33%]
 ** TODO Call people [1/2]
 *** TODO Peter
 *** DONE Sarah
 ** TODO Buy food
 ** DONE Talk to neighbor 

但是,当我写文本时,我希望换行是为了视觉空白/易于阅读。

大纲模式,标题前为空行:

* Heading 
This is a document that has a heading, and a body. The body will consist of two paragraphs with sub-headings.

* Body  
This is an introduction to the body. The body has two sub-headings, each of which have their own paragraph.  

** The First Paragraph  
This is the first of two paragraphs. 

** The Second Paragraph
This is the second of two paragraphs.  

我已经将org-blank-before-new-entry设置为auto:

 ((heading . auto)
 (plain-list-item . auto))

但是我认为org-blank-before-new-entry通过检测该区域中的其他空行来工作。我希望它检测文本的前一行是标题还是非标题。

如何修改org-blank-before-new-entry,以便当我在仅包含标题的TODO列表org-meta-return中时不添加换行符?但是在一段文字之后,是吗?


您找到解决办法了吗?我试着在emacs subreddit上问同样的问题,但是没有结果。
MajorBriggs 2015年

是的,通过自定义功能。我会发表。
白炽灯

Answers:


5

这可以通过创建一个自定义函数来完成,该函数将检查它是否在组织标题上。

(setq org-blank-before-new-entry
      '((heading . always)
       (plain-list-item . nil)))

(defun call-rebinding-org-blank-behaviour (fn)
  (let ((org-blank-before-new-entry
         (copy-tree org-blank-before-new-entry)))
    (when (org-at-heading-p)
      (rplacd (assoc 'heading org-blank-before-new-entry) nil))
    (call-interactively fn)))

(defun smart-org-meta-return-dwim ()
  (interactive)
  (call-rebinding-org-blank-behaviour 'org-meta-return))

(defun smart-org-insert-todo-heading-dwim ()
  (interactive)
  (call-rebinding-org-blank-behaviour 'org-insert-todo-heading))

(define-key org-mode-map (kbd "M-<return>") 'smart-org-meta-return-dwim) 

1
我又如何才能通过其他三种插入标题的方式来工作:C-ret(org-insert-heading-respect-content),M-S-return(org-insert-todo-heading)和C-S-return(org-insert-todo-heading-respect -内容)?
MajorBriggs 2015年

需要说明的是:org-insert-todo-heading即使我将它绑定到这样的键上也无法正常工作:(define-key org-mode-map(kbd“ MS- <return>”)'smart-org-insert-todo-heading-dwim)
MajorBriggs 2015年
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.