目前公認的答案有兩個缺點:1)不接受參數和2)不允許通過重複呼叫標記更多段落(特別是這非常有用)。這是我的解決方案 - 最後是帶有下一行命令的原始標記段。該條件確保它也可以在文件的第一個上運行。
可能是更經濟的解決方案是使用意見,但我不知道如何尚未使用它們:)。
(defun rs-mark-paragraph (&optional arg allow-extend)
"The original default mark-paragraph, but doesn't mark the first
empty line. Put point at beginning of this paragraph, mark at
end. The paragraph marked is the one that contains point or
follows point.
With argument ARG, puts mark at end of a following paragraph, so that
the number of paragraphs marked equals ARG.
If ARG is negative, point is put at end of this paragraph, mark is put
at beginning of this or a previous paragraph.
Interactively, if this command is repeated
or (in Transient Mark mode) if the mark is active,
it marks the next ARG paragraphs after the ones already marked."
(interactive "p\np")
(unless arg (setq arg 1))
(when (zerop arg)
(error "Cannot mark zero paragraphs"))
(cond ((and allow-extend
(or (and (eq last-command this-command) (mark t))
(and transient-mark-mode mark-active)))
(set-mark
(save-excursion
(goto-char (mark))
(forward-paragraph arg)
(point))))
(t
(forward-paragraph arg)
(push-mark nil t t)
(backward-paragraph arg)
(if (/= (line-number-at-pos) 1)
(next-line)))))
這有點太天真了,因爲它會失敗,例如,如果段落從文件的開始處開始。但基本方法是正確的。 – deong 2012-03-30 11:15:35
你是正確的,當然,我可是第一個段落仍然可以按'M-h' :-) – 2012-03-30 11:25:09
thnks我已經有工作代碼 – 2012-03-30 11:44:22