【问题标题】:Function to Explode paragraph into org-bullets by sentences通过句子将段落分解为组织项目符号的功能
【发布时间】:2021-07-08 01:27:05
【问题描述】:

我正在尝试编写一个简单的 Elisp Emacs 函数,该函数接受一个段落(由[X] 指示的点)并将其扩展为一系列项目符号点,每个项目符号包含一个句子。

much more useful, especially with huge windows. In my experience, it slows down redraw a little bit, but it’s worth it.There are two ways to enable it: the first is with M-x visual-line-mode[X] (for those with real menus, apparently Options->Line Wrapping in this Buffer->Word Wrap), which will give you a minor mode “wrap” in the mode line.

然后返回

+ much more useful, especially with huge windows. 
+ In my experience, it slows down redraw a little bit, but it’s worth it.
+ There are two ways to enable it: the first is with M-x visual-line-mode[X] (for those with real menus, apparently Options->Line Wrapping in this Buffer->Word Wrap), which will give you a minor mode “wrap” in the mode line.

这是我目前所拥有的:

(defun jds/explode ()
  "explode paragraph, more documentation needed"
  (interactive)
  (save-excursion
    (let ((bop (copy-marker (progn (backward-paragraph) (point))))
          (eop (copy-marker (progn (forward-paragraph) (point)))))
          (goto-char bop)
          (back-to-indentation) ;; goto first non-whitespace character
          (if (re-search-forward "^[:blank:]*[+-x] " nil t) nil (insert "+ "))
          (while (< (point) eop)
            (forward-sentence)
            (forward-whitespace 1)
            (unless (>= (point) eop)
              (org-meta-return)))))))))

但这似乎只是运行但没有做任何事情。我认为问题可能在于backward-paragraph 函数可能没有将点放在第一个非黑色字符上(m 很多)。但话虽如此,我的 Elisp 很弱,我正在努力找出问题所在。

【问题讨论】:

    标签: emacs org-mode sentence


    【解决方案1】:

    事实证明这是可行的 - 只需将 +/-1 添加到点

    (defun jds/explode ()
      "explode paragraph, more documentation needed"
      (interactive)
      (save-excursion
        (let ((bop (copy-marker (progn (backward-paragraph) (+ (point) 1))))
              (eop (copy-marker (progn (forward-paragraph) (- (point) 1)))))
              (goto-char bop)
              (if (looking-at-p "^[:blank:]*[+-x] ") nil (insert "+ "))
              (while (< (point) eop)
                (forward-sentence)
                (forward-whitespace 1)
                (unless (>= (point) eop)
                  (org-meta-return))))))
    

    【讨论】:

      【解决方案2】:
        (defun explode-paragraph ()
          "Explode paragraph. If run twice it changes list marker."
          (interactive)
          (save-mark-and-excursion
            (let ((bop (copy-marker (progn (backward-paragraph) (1+ (point)))))
                  (eop (copy-marker (progn (forward-paragraph)  (point)))))
              (goto-char bop)
              (if (looking-at-p "^\s*[\-\+x] ") nil (insert "+ "))
              (while (< (point) eop)
                (forward-sentence)
                (forward-whitespace 1)
                (unless (>= (point) eop)
                  (org-meta-return))))))
      

      我扩展了您的实现以适用于我的用例。我改变了几件事:

      • 我将[:blank:] 更改为\s,因为它在标题下的行上匹配(如果有人知道这是为什么,我很乐意接受教育)。
      • 我使用了(+1 (point) 表示法并从eop 中删除了-1,因为我认为没有必要。
      • 我转义了 [...] 中的特殊符号,因为 -x 匹配以“A”开头的行。

      在我自己的这个函数版本中,我的第一行(摘要句)比其他句子高一级,但我认为这应该涵盖大多数情况,以达到最初的预期目的。

      【讨论】:

        猜你喜欢
        • 2013-08-13
        • 2014-06-01
        • 2012-05-16
        • 2013-05-21
        • 2019-11-26
        • 1970-01-01
        • 1970-01-01
        • 2011-01-10
        相关资源
        最近更新 更多