2012-03-30 92 views

回答

2

你不能改變的mark-paragraph的行爲,但你可以很容易地綁定另一個命令到C-M-H按鍵(類似於原M-h):

(global-set-key (kbd "C-M-h") (lambda() 
        (interactive) 
        (mark-paragraph) 
        (next-line) 
        (beginning-of-line))) 

像這樣的東西應該做的伎倆。

+0

這有點太天真了,因爲它會失敗,例如,如果段落從文件的開始處開始。但基本方法是正確的。 – deong 2012-03-30 11:15:35

+0

你是正確的,當然,我可是第一個段落仍然可以按'M-h' :-) – 2012-03-30 11:25:09

+0

thnks我已經有工作代碼 – 2012-03-30 11:44:22

1

我不知道我看到一個方便的方式來做到這一點。 mark-paragraph電話forward-paragraphbackward-paragraph做大量的工作,併爲backward-paragraph文檔中,我們有「如果一個段落的第一個真正的線由一個空行之前,該段開始於那空行。」

要看的最相關的變量似乎是paragraph-startparagraph-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))) 
3

目前公認的答案有兩個缺點: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)))))