计算组织标题

Numerate the org headings

我想计算 org-headings 来自:

* heading how
* heading are
* heading you

* 1.heading how
* 2.heading are
* 3.heading you

所以我写了一个 numerate-org-heading 作为:

(defun numerate-org-heading (args)
  "Numerate org headings"
  (interactive "s")
  (let ((count 0))
    (while (re-search-forward args nil t)
      (setq count (1+ count))
      (replace-match (concat "" (string count)
                             (forward-char 1))))))

不幸的是,当我以交互方式调用 numerate-org-heading 并为其提供字符串“^*”时,它报告 Wrong type argument: stringp, ^* 错误。

能否请您提供解决问题的提示?


修改了函数,它现在适用于特定情况:

(defun numerate-org-heading (args)
  "Numerate org headings"
  (interactive "s")
  (let ((count 0))
    (while (re-search-forward args nil t)
      (setq count (1+ count))
      (replace-match (concat "* " (number-to-string count) ".")
                     (forward-char 1))))))

如果您将 args 设置为匹配组并捕获任何尾随 space,您可以将其替换回第 1 组 ("\1"),然后是您的编号,例如1.

(defun numerate-org-heading (args)
  "Numerate org headings"
  (interactive "s")
  (let ((count 0))
    (while (re-search-forward (concat "\(" args "[ \t]*\)") nil t)
      (setq count (1+ count))
      (replace-match (concat "\1" (number-to-string count) ".")))))