按句子将段落分解为 org-bullets 的功能
Function to Explode paragraph into org-bullets by sentences
我正在尝试编写一个简单的 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.
和returns
+ 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 很弱,我正在努力找出问题所在。
事实证明这是可行的 - 只需要将 +/-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))))))
(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))))))
我扩展了您的实施以适用于我的 use-case。我改变了几件事:
- 我将
[:blank:]
更改为 \s
,因为它匹配 header 下的行(如果有人知道这是为什么,我很乐意接受教育)。
- 我使用了
(+1 (point)
符号并从 eop 中删除了 -1,因为我认为没有必要。
- 我转义了
[...]
中的特殊符号,因为 -x 匹配以 'A'. 开头的行
在我自己的这个函数版本中,第一行(总结句)比其他句子高一级,但我认为这应该涵盖大多数情况,以达到其最初的预期目的。
我正在尝试编写一个简单的 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.
和returns
+ 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 很弱,我正在努力找出问题所在。
事实证明这是可行的 - 只需要将 +/-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))))))
(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))))))
我扩展了您的实施以适用于我的 use-case。我改变了几件事:
- 我将
[:blank:]
更改为\s
,因为它匹配 header 下的行(如果有人知道这是为什么,我很乐意接受教育)。 - 我使用了
(+1 (point)
符号并从 eop 中删除了 -1,因为我认为没有必要。 - 我转义了
[...]
中的特殊符号,因为 -x 匹配以 'A'. 开头的行
在我自己的这个函数版本中,第一行(总结句)比其他句子高一级,但我认为这应该涵盖大多数情况,以达到其最初的预期目的。