如何更改默认的emacs mark-paragraph函数行为以不选择第一个空行?
my emacs http://dl.dropbox.com/u/1019877/e2.PNG
我已经制作了Bohzidars升级版,它也适用于第一线。
(global-set-key (kbd "M-h") (lambda ()
(interactive)
(mark-paragraph)
(if (> (line-number-at-pos) 1)
(next-line))
(beginning-of-line)))
感谢大家的提示。
答案 0 :(得分:3)
目前接受的答案有两个缺点:1)不接受参数; 2)不允许通过重复调用标记更多段落(特别是这非常有用)。这是我的解决方案 - 它是原始的mark-paragraph,最后有一个下一行命令。条件确保它也适用于文件的第一个。
可能更经济的解决方案是使用建议,但我不知道如何使用它们:)。
(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)))))
答案 1 :(得分:2)
您无法更改mark-paragraph
的行为,但您可以轻松地将另一个命令绑定到 C-M-h 击键(以类似于原始M-h
):
(global-set-key (kbd "C-M-h") (lambda ()
(interactive)
(mark-paragraph)
(next-line)
(beginning-of-line)))
这样的事情应该可以解决问题。
答案 2 :(得分:2)
我不确定我是否看到了方便的方法。 mark-paragraph
调用forward-paragraph
和backward-paragraph
来完成大部分工作,在backward-paragraph
的文档中,我们有“如果段落的第一个实线在前面一个空行,该段从该空白行开始。“
要查看的最相关的变量似乎是paragraph-start
和paragraph-separate
,在paragraphs.el中使用了两个正则表达式来弄清楚这种事情。我会改变它们,因为它们会产生很多其他影响。
另一种选择是编写自己的函数,执行如下操作:
(defun dg-mark-paragraph ()
(interactive)
(mark-paragraph)
(goto-char (region-beginning))
(when (= (string-match paragraph-separate (thing-at-point 'line)) 0)
(forward-line)))