gpt4 book ai didi

emacs - 在组织模式下对标题的混合列表进行排序

转载 作者:行者123 更新时间:2023-12-04 03:15:45 26 4
gpt4 key购买 nike

我在org-mode中有很长的标题列表:

* Tasks [/]
** TODO Foo
** TODO Bar
** DONE World
** DONE Abba

我想排序如下:
* Tasks [/]
** TODO Bar
** TODO Foo
** DONE Abba
** DONE World

使用 org-sort-entries我可以获取
* Tasks [/]
** DONE Abba
** TODO Bar
** TODO Foo
** DONE World

(即字母顺序),或
* Tasks [/]
** TODO Foo
** TODO Bar
** DONE World
** DONE Abba

(即根据状态分组)。

换句话说,我想按字母顺序对 TODODONE项进行排序,但将它们分成两个块。我怎么能做到呢?我想将整个标题保留在同一子树中!

编辑:

我没有设法利用以下建议。因此,我尝试使用下面提供的技巧来提出所需的解决方案。这是我的代码:

(defun drorata-sort-TODO-DONE-headings ()
(interactive)
(save-excursion
;; Sort according to the TODO/DONE keywords
(org-sort-entries t ?o)
;; Now there is a block of TODO's and a block of DONE's
;; Mark the TODO's
(next-line)
(beginning-of-line)
(set-mark-command nil)
(search-forward-regexp "[*].* DONE" nil t)
(beginning-of-line)
;; Sort the marked region (of TODO's) alphabetically
(org-sort-entries t ?a)
;; Now its time to sort the DONE's
(search-forward "[*].* DONE" nil t)
(beginning-of-line)
(set-mark-command nil)
;; How can I find all headings labeled with DONE in the current level?
)
)

我的想法是标记由 TODO标记的标题,并按字母顺序对它们进行排序,然后对 DONE标题进行相同的处理。到目前为止,我只适用于 TODO的...

最佳答案

简短答案

  • 步骤#1 :将光标放在父对象上。
  • 步骤#2 :M-x org-sort-entries RET a RET
  • 步骤#3 :M-x org-sort-entries RET o RET
  • 步骤#4 :打开您最喜欢的饮料并喝一杯。


  • 千篇一律的答案

    为了扩展@pmr的答案(即,对选定的区域进行排序),可能还需要考虑对主要标题采取行动以组织子标题。例如,我喜欢执行多种排序-首先按字母顺序排列,其次按待办事项顺序排列,按优先级排列第三,按时间排列第四。对于不包含截止日期且仅包含一种待办事项状态的子标题,仅需按字母顺序排序就足够了。下面列出的是一个示例函数,我使用它对包含各种主要标题和子标题的整个缓冲区进行排序。这是 org-sort-entries的备忘单:
    Sort: [a]lpha  [n]umeric  [p]riority  p[r]operty  todo[o]rder  [f]unc
    [t]ime [s]cheduled [d]eadline [c]reated
    A/N/P/R/O/F/T/S/D/C means reversed.

    注意:如果条目不包含时间戳,则 org-sort-entries在根据时间戳对条目进行排序时使用 current-time。使用 current-time的结果是,当使用选项 tcsd进行排序时,未日期的条目将在包含时间戳的将来任务之前进行排序。要对未注明日期的条目进行加权,以使它们在带日期的条目之后进行排序,可以使用比 current-time更高的日期。相关的让界变量定义为 (now (current-time)),其在函数中的用法表示为 (org-float-time now)。这可以通过许多不同的方式来处理-例如,使用包含距离将来很远的人造日期的东西来修改包含 (org-float-time now)的代码-例如 (org-time-string-to-seconds "<2030-12-31 Tue>")

    (defun lawlist-sort ()
    (when
    (save-excursion
    (goto-char (point-max))
    (re-search-backward "^\\* CONTACTS" nil t)
    (re-search-forward "^\\*\\* \\(Planning\\)" nil t))
    (goto-char (point-max))
    (re-search-backward "^\\* CONTACTS" nil t)
    (org-sort-entries t ?a) )
    (when
    (save-excursion
    (goto-char (point-max))
    (re-search-backward "^\\* DONE" nil t)
    (re-search-forward "^\\*\\* \\(None\\)" nil t))
    (goto-char (point-max))
    (re-search-backward "^\\* DONE" nil t)
    (org-sort-entries t ?a) )
    (when
    (save-excursion
    (goto-char (point-max))
    (re-search-backward "^\\* UNDATED" nil t)
    (re-search-forward "^\\*\\* \\(Someday\\)" nil t))
    (goto-char (point-max))
    (re-search-backward "^\\* UNDATED" nil t)
    (org-sort-entries t ?a) )
    (when
    (save-excursion
    (goto-char (point-max))
    (re-search-backward "^\\* EVENTS" nil t)
    (re-search-forward "^\\*\\* \\(Reference\\|Delegated\\|Postponed\\|Waiting\\)" nil t))
    (goto-char (point-max))
    (re-search-backward "^\\* EVENTS" nil t)
    (org-sort-entries t ?a)
    (org-sort-entries t ?o)
    (org-sort-entries t ?p)
    (org-sort-entries t ?t) )
    (when
    (save-excursion
    (goto-char (point-max))
    (re-search-backward "^\\* TASKS" nil t)
    (re-search-forward "^\\*\\* \\(Active\\|Next Action\\|Hold\\|Canceled\\)" nil t))
    (goto-char (point-max))
    (re-search-backward "^\\* TASKS" nil t)
    (org-sort-entries t ?a)
    (org-sort-entries t ?o)
    (org-sort-entries t ?p)
    (org-sort-entries t ?t) ) )

    这是一个示例,说明如何对包含主标题和副标题的整个缓冲区进行排序和重组。如果用户希望使用 org-toodledo库与Toodledo服务器同步,这将特别有用: https://github.com/christopherjwhite/org-toodledo为了在重组包含数百个子标题的缓冲区时加快处理速度,用户可能希望考虑通过修改负责的函数来抑制消息-但是,这超出了此答案的范围。

    (setq org-todo-keywords '(
    (sequence
    "Active(a)"
    "Next Action(n)"
    "Canceled(c)"
    "Hold(h)"
    "Reference(r)"
    "Delegated(d)"
    "Waiting(w)"
    "Postponed(P)"
    "Someday(s)"
    "Planning(p)"
    "|"
    "None(N)") ))

    (defun lawlist-reorganize ()
    (interactive)
    (with-current-buffer (get-buffer "test.org")
    (setq buffer-read-only nil)
    (lawlist-refile-tasks)
    (lawlist-refile-events)
    (lawlist-refile-undated)
    (lawlist-refile-contacts)
    (lawlist-refile-done)
    (lawlist-sort)
    (goto-char (point-min))
    (save-buffer)
    (setq buffer-read-only t)))

    (defun lawlist-refile-tasks ()
    (interactive)
    (let* (
    (org-archive-location "/Users/HOME/Desktop/test.org::* TASKS")
    (org-archive-save-context-info nil))
    (goto-char (point-min))
    (unless (re-search-forward "^\\* TASKS" nil t)
    (goto-char (point-max))
    (insert "* TASKS\n\n"))
    (goto-char (point-max))
    (while
    (re-search-backward
    "^\\*\\* \\(Active\\|Next Action\\|Hold\\|Canceled\\)" nil t)
    (org-archive-subtree))))

    (defun lawlist-refile-events ()
    (let* (
    (org-archive-location "/Users/HOME/Desktop/test.org::* EVENTS")
    (org-archive-save-context-info nil))
    (goto-char (point-min))
    (unless (re-search-forward "^\\* EVENTS" nil t)
    (goto-char (point-max))
    (insert "* EVENTS\n\n"))
    (goto-char (point-max))
    (while
    (re-search-backward
    "^\\*\\* \\(Reference\\|Delegated\\|Postponed\\|Waiting\\)" nil t)
    (org-archive-subtree))))

    (defun lawlist-refile-undated ()
    (let* (
    (org-archive-location "/Users/HOME/Desktop/test.org::* UNDATED")
    (org-archive-save-context-info nil))
    (goto-char (point-min))
    (unless (re-search-forward "^\\* UNDATED" nil t)
    (goto-char (point-max))
    (insert "* UNDATED\n\n"))
    (goto-char (point-max))
    (while
    (re-search-backward
    "^\\*\\* \\(Someday\\)" nil t)
    (org-archive-subtree))))

    (defun lawlist-refile-done ()
    (let* (
    (org-archive-location "/Users/HOME/Desktop/test.org::* DONE")
    (org-archive-save-context-info nil))
    (goto-char (point-min))
    (unless (re-search-forward "^\\* DONE" nil t)
    (goto-char (point-max))
    (insert "* DONE\n\n"))
    (goto-char (point-max))
    (while
    (re-search-backward
    "^\\*\\* \\(None\\)" nil t)
    (org-archive-subtree))))

    (defun lawlist-refile-contacts ()
    (let* (
    (org-archive-location "/Users/HOME/Desktop/test.org::* CONTACTS")
    (org-archive-save-context-info nil))
    (goto-char (point-min))
    (unless (re-search-forward "^\\* CONTACTS" nil t)
    (goto-char (point-max))
    (insert "* CONTACTS\n\n"))
    (goto-char (point-max))
    (while
    (re-search-backward
    "^\\*\\* \\(Planning\\)" nil t)
    (org-archive-subtree))))

    这是一个清理函数的示例,用于在条目之间放置适当的间距并删除缓冲区末尾的任何空行-regexp假定标题和子标题都向左对齐:

    (defun lawlist-cleanup ()
    (interactive)
    (let ((query-replace-lazy-highlight nil))
    (replace-regexp "\n+\\*\\* " "\n\n** " nil (point-min) (point-max))
    (replace-regexp "\n+\\* " "\n\n\n* " nil (point-min) (point-max))
    (goto-char (point-max))
    (delete-blank-lines)
    (let ((trailnewlines (abs (skip-chars-backward "\n\t"))))
    (if (> trailnewlines 0)
    (delete-char trailnewlines))) ))

    此解决方案不依赖于选择区域,而是作用于每个主标题并组织该主标题下的所有内容-即,所有子标题都是有组织的。此答案中的代码将通过在正确的主标题下重新引用条目来对它们进行重新组合。例如-如果任务已完成,则完成的子标题将为 ** None-代码将查找所有带有 ** None的子标题,并将其移至 * DONE的主标题,然后按字母顺序对它们进行排序。

    主要标题是: * TASKS* EVENTS; * SOMEDAY; * CONTACTS; * DONE

    选择以下子标题是因为它们是完成事情的方法,并且Toodledo服务器使用相同的方法: ** Active; ** Next Action; ** Hold; ** Canceled; ** Reference; ** Delegated; ** Postponed; ** Waiting; ** Someday; ** Planning; ** None
    * TASKS

    ** Active

    ** Next Action

    ** Hold

    ** Canceled

    * EVENTS

    ** Reference

    ** Delegated

    ** Postponed

    ** Waiting

    * SOMEDAY

    ** Someday

    * CONTACTS

    ** Planning

    * DONE

    ** None

    关于emacs - 在组织模式下对标题的混合列表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22231431/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com