此函数:
(defun remove-newlines-in-region ()
"Removes all newlines in the region."
(interactive)
(save-restriction
(narrow-to-region (point) (mark))
(goto-char (point-min))
(while (search-forward "n" nil t) (replace-match "" nil t))))
将删除文本中的每个换行符。这在导入到组织创建换行文本时很有用。然后,我们希望解开每个段落的文本(不是在所有缓冲区中,这将创建一个完整的块,不区分段落(。
我们将如何添加条件,即 if 应该只应用于一个换行符,而不是 2 个连续的换行符?谢谢!
解决方案:使用UnfillRegion。它完成了这项工作!
搜索第一个换行符后,可以使用looking-at-p
来查看下一个字符是否为第二个换行符。所以代替你的
(while (search-forward "n" nil t) (replace-match "" nil t))
您可以使用
(while (search-forward "n" nil t)
(unless (looking-at-p "n") (replace-match "" nil t)))