Text Emacs:填充除指定区域外的所有文本

Text Emacs:填充除指定区域外的所有文本,text,emacs,elisp,fill,Text,Emacs,Elisp,Fill,在gnuemacs中使用elisp,我希望能够填充缓冲区中的所有文本,除了用特殊标识符表示的文本。标识符可以是任何东西,但是为了解决这个问题,让我们假设它是介于[nofill]和[/nofill]标记之间的任何文本 例如,假设我的缓冲区如下所示: Now is the time for all good men to come to the aid of their party. Now is the time for all good men to come to the ai

在gnuemacs中使用elisp,我希望能够填充缓冲区中的所有文本,除了用特殊标识符表示的文本。标识符可以是任何东西,但是为了解决这个问题,让我们假设它是介于[nofill]和[/nofill]标记之间的任何文本

例如,假设我的缓冲区如下所示:

Now is the time
for all good
   men to come to the aid
    of their party. Now is
the time for all good
 men to come to the aid
of their party.

[nofill]
The quick
brown fox
jumped over the
lazy sleeping dog
[/nofill]

When in the course of 
    human events, it becomes 
  it becomes necessary for one
     people to dissolve the
  political bands

[nofill]
    baa-baa
      black sheep,
   have you
    any wool
[/nofill]
在我寻找的填充类型之后,我希望缓冲区显示如下:

Now is the time for all good men to come to the aid of their
party. Now is the time for all good me to come to the aid of
their party

[nofill]
The quick
brown fox
jumped over the
lazy sleeping dog
[/nofill]

When in the course of human events, it becomes it becomes
necessary for one people to dissolve the political bands

[nofill]
    baa-baa
      black sheep,
   have you
    any wool
[/nofill]
我知道elisp,我可以写一些这样的东西。然而,在我尝试“重新发明轮子”之前,我想知道是否有人知道可能已经提供此功能的任何现有elisp模块


提前谢谢。

您可以证明
[/nofill]
[nofill]
之间的所有内容(或者可能是缓冲区的开始/结束)

(取消特殊填充()“特殊填充”
(互动)
(转到字符(最小点))
(同时(<(点)(最大点))
(让((开始(点)))
(如果(向前搜索“[nofill]”无1)
(前线-1))
(填充区域起点(点)'左侧)
(如果(向前搜索“[/nofill]”无1)
(前线1(()))

您可以证明
[/nofill]
[nofill]
之间的所有内容(或者可能是缓冲区的开始/结束)

(取消特殊填充()“特殊填充”
(互动)
(转到字符(最小点))
(同时(<(点)(最大点))
(让((开始(点)))
(如果(向前搜索“[nofill]”无1)
(前线-1))
(填充区域起点(点)'左侧)
(如果(向前搜索“[/nofill]”无1)
(前线1(()))

与其他答案相比,这似乎过于复杂,但基本上,我标记当前点,向前搜索标签(可以参数化),然后填充区域。然后,我递归调用
fill region ignore tags helper
,使用起始点后的第一个字符作为区域的开始,然后使用下一个
[nofill]
标记作为区域的结束。这将一直持续到整个缓冲区被填满。它似乎适用于一些随机的琐碎情况,尽管可能有一些边缘情况没有涵盖

(defun fill-region-ignore-tags ()
  (interactive)
  (save-excursion
    (fill-region-ignore-tags-helper (point-min) (search-forward "[nofill]"))))

(defun fill-region-ignore-tags-helper (begin end)
  (let ((cur-point begin)
        (next-point end))
    (if (eq next-point nil)
        nil
      (progn
        (fill-region cur-point next-point)
        (fill-region-ignore-tags-helper (progn
                                          (search-forward "[/nofill]")
                                          (re-search-forward "\\S-")
                                          (point))
                                 (progn
                                   (search-forward "[nofill]")
                                   (previous-line)
                                   (point)))))))

与其他答案相比,这似乎过于复杂,但基本上,我标记当前点,向前搜索标签(可以参数化),然后填充区域。然后,我递归调用
fill region ignore tags helper
,使用起始点后的第一个字符作为区域的开始,然后使用下一个
[nofill]
标记作为区域的结束。这将一直持续到整个缓冲区被填满。它似乎适用于一些随机的琐碎情况,尽管可能有一些边缘情况没有涵盖

(defun fill-region-ignore-tags ()
  (interactive)
  (save-excursion
    (fill-region-ignore-tags-helper (point-min) (search-forward "[nofill]"))))

(defun fill-region-ignore-tags-helper (begin end)
  (let ((cur-point begin)
        (next-point end))
    (if (eq next-point nil)
        nil
      (progn
        (fill-region cur-point next-point)
        (fill-region-ignore-tags-helper (progn
                                          (search-forward "[/nofill]")
                                          (re-search-forward "\\S-")
                                          (point))
                                 (progn
                                   (search-forward "[nofill]")
                                   (previous-line)
                                   (point)))))))

嗯,这比我想象的容易多了。谢谢你的回答!嗯,这比我想象的容易多了。谢谢你的回答!是的,对我也有用。可以使用“(当下一点…”作为比“(如果(eq下一点为零)nil(progn…)更短的形式。是的,也适用于我。可以使用“(当下一点为…”作为比“(如果(eq下一点为零)nil(progn…)更短的形式。”