【发布时间】:2012-11-28 22:58:52
【问题描述】:
我正在阅读 Robert J. Chassell 的“An Introduction to Programming in Emacs Lisp”。我有一个问题。在节点“fwd-para while”(forward-paragraph 的while 循环的解释)中,它说:
有趣的是,在我们离开段落之间的空间之前,循环计数不会减少,除非我们到达缓冲区的末尾或不再看到段落分隔符的本地值。
我看不懂,谁能给我解释一下?谢谢。
while 循环如下所示:
;; going forwards and not at the end of the buffer
(while (and (> arg 0) (not (eobp)))
;; between paragraphs
;; Move forward over separator lines...
(while (and (not (eobp))
(progn (move-to-left-margin) (not (eobp)))
(looking-at parsep))
(forward-line 1))
;; This decrements the loop
(unless (eobp) (setq arg (1- arg)))
;; ... and one more line.
(forward-line 1)
(if fill-prefix-regexp
;; There is a fill prefix; it overrides parstart;
;; we go forward line by line
(while (and (not (eobp))
(progn (move-to-left-margin) (not (eobp)))
(not (looking-at parsep))
(looking-at fill-prefix-regexp))
(forward-line 1))
;; There is no fill prefix;
;; we go forward character by character
(while (and (re-search-forward sp-parstart nil 1)
(progn (setq start (match-beginning 0))
(goto-char start)
(not (eobp)))
(progn (move-to-left-margin)
(not (looking-at parsep)))
(or (not (looking-at parstart))
(and use-hard-newlines
(not (get-text-property (1- start) 'hard)))))
(forward-char 1))
;; and if there is no fill prefix and if we are not at the end,
;; go to whatever was found in the regular expression search
;; for sp-parstart
(if (< (point) (point-max))
(goto-char start))))
感谢您的编辑和回答。关于前段,我还有另外三个问题:
(progn (move-to-left-margin) (not (eobp)))是什么意思?如果(not (eobp))为真,那么(progn (move-to-left-margin) (not (eobp)))不应该始终为真吗?-
关于这一行:
;; ... and one more line. (forward-line 1)为什么要多转发一行?
-
关于本段:
这个
while循环让我们向前搜索“sp-parstart”,即 可能的空格与本地值的组合 段落或段落分隔符的开头。为什么
the local value of the start of a paragraph or of a paragraph separator?就我而言,段落分隔符的条件已经在while的第一个while循环中处理过了。
【问题讨论】:
-
(move-to-left-margin)可能会向前移动点,所以(eobp)事先为假并不意味着它会再次为假。 -
你的意思是缓冲区局部变量
left-margin可以是(point-max)吗? -
嗯,它可以,但这不是我的意思。我的意思是,对于任何给定的文本行,当前点可能位于左边距列的左侧(也可以通过文本属性指定,因此变量不一定相关),因此在移动到左边距之前和之后测试
(eobp)并不是没有意义的。