如何删除orgmode headline下的所有内容
source link: https://www.lujun9972.win/blog/2018/09/26/%E5%A6%82%E4%BD%95%E5%88%A0%E9%99%A4orgmode-headline%E4%B8%8B%E7%9A%84%E6%89%80%E6%9C%89%E5%86%85%E5%AE%B9/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
如何删除orgmode headline下的所有内容
找到指定的headline
使用 (org-goto-local-search-headings STRING BOUND NOERROR)
可以将光标定位到指定的headline处。
但是要注意的是,这个函数的行为跟 isearch-forward
的值相关:
若 isearch-forward
的值为 t
, 则 org-goto-local-search-headlings
从前向后搜索,通常这时你会需要把光标移动到 (point-min)
处
(save-excursion (goto-char (point-min)) (org-goto-local-search-headings "Report" nil nil))
若 isearch-forward
的值为 nil
, 则 org-goto-local-search-headlings
从后向前搜索,通常这时你会需要把光标移动到 (point-max)
处
(save-excursion (goto-char (point-max)) (org-goto-local-search-headings "Report" (point-min) nil))
删除head下的所有内容
org-mode似乎没有提供专门的函数来清空head下的所有内容,但是它提供了一个 org-mark-subtree
函数用来mark整个subtree(包括headline),因此你可以很容易写出这么一个函数来:
(defun clear-subtree () (interactive) (org-mark-subtree) ;; mark 当前subtree,包括headline (forward-line) ;; 去掉headline (delete-region (region-beginning) (region-end)) ;; 删除剩下的内容 )
类似的,org-mode还提供了一个 org-mark-element
来mark某个元素,比如你像删除某个org-time-clock那么可以这么做
(when (search-forward-regexp "^\s*#\\+BEGIN:\s+clocktable" nil t) (org-mark-element) (delete-region (region-beginning) (region-end)))
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK