我使用 emacs 进行创意写作。为了更好地分析句子的结构,我希望看到我的段落显示为每行一个句子。因此,我需要一个函数,可以接受正常的自动填充段落并执行以下操作:1)将所有句子拉伸(stretch)到一行,2)每行仅放置一个句子。
想象一下我写了以下段落(歌词来自 Suzanne Vega)
My name is Luka. I live on the second floor. I live upstairs from you. Yes I think you've seen me before. If you hear something late at night. Some kind of trouble. Some kind of fight.
使用该功能,我希望段落显示如下:
My name is Luka.
I live on the second floor.
I live upstairs from you.
Yes I think you've seen me before.
If you hear something late at night.
Some kind of trouble.
Some kind of fight.
由于我想在这样显示句子时进行一些写作,因此该功能除了拉伸(stretch)句子之外还应该关闭自动填充模式。
理想情况下,我想要一个功能,可以在所有句子换行的自动填充模式和关闭自动填充且所有句子拉伸(stretch)的新模式之间切换显示。
预先感谢各种建议或帮助来实现这样的功能!
@Drew:这是我无法与您的代码分开的文本:
有两种方法可以启用它:第一种是使用 M-x 视觉行模式(对于那些有真正菜单的人,显然是选项 -> 缓冲区中的换行 -> 自动换行),这将为您提供次要模式在模式行中“换行”。正如 C-h f Visual-line-mode 中所解释的,该命令的效果之一是巧妙地改变处理“行”的命令的效果:C-a、C-e 不再转到行尾(如\n ),但转到行尾(如显示行)。 M-a、M-e 仍然按其应有的方式工作。此外,垂直分割窗口保证不会被截断,并在宽度变化时适当调整大小。效果非常好,特别是如果您在版本控制中保留自由格式的文本(例如 Latex 中的论文),而硬包装效果不太好。它还使得垂直分割更加有用,尤其是对于巨大的 window 。根据我的经验,它会稍微减慢重绘速度,但这是值得的。
最佳答案
我想这就是您所要求的。
(defun split-para-at-sentence-ends ()
"Split current paragraph into lines with one sentence each.
Then turn off `auto-fill-mode'."
(interactive)
(let ((mode major-mode))
(unwind-protect
(progn (text-mode)
(save-excursion
(let ((emacs-lisp-docstring-fill-column t)
(fill-column (point-max)))
(fill-paragraph))
(let ((bop (copy-marker (progn (backward-paragraph) (point))))
(eop (copy-marker (progn (forward-paragraph) (point)))))
(goto-char bop)
(while (< (point) eop)
(forward-sentence)
(forward-whitespace 1)
(unless (>= (point) eop)
(delete-horizontal-space)
(insert "\n"))))))
(funcall mode)))
(auto-fill-mode -1))
(define-minor-mode split-para-mode
"Toggle between a filled paragraph and one split into sentences."
nil nil nil
(if (not split-para-mode)
(split-para-at-sentence-ends)
(auto-fill-mode 1)
(fill-paragraph)))
(global-set-key "\C-o" 'split-para-mode) ; Or some other key.
关于emacs - 如何制作一个让段落中的每个句子占一行的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41637313/