help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I overload M-q to invoke fill-region only when mark is active


From: Giorgos Keramidas
Subject: Re: How do I overload M-q to invoke fill-region only when mark is active?
Date: Thu, 15 Jun 2006 20:32:37 +0300

On 15 Jun 2006 09:57:49 -0700, rayz@phonon.com wrote:

> I'd like to use M-q to invoke fill-region when mark is active.
> Otherwise I want it to invoke fill-paragraph.  How do I set this up?
>
> Please respond to the group -- the e-mail address is invalid.  TIA

You can bind M-q to a function of your own, i.e. with something like
this in your ~/.emacs file:

,----------------------------------------------------------------------
| (defun fill-region-or-paragraph (&optional justify)
|   "Fill the current region or paragraph (depending on `mark-active')
| 
| Fill paragraph at or after point when the mark is inactive or if
| the mark and the point are the same.  Fill each of the paragraphs
| in the region when the mark is active and is not equal to the
| current point.
| 
| The optional JUSTIFY argument specifies the paragraph
| justification that should be used.  Valid values are all those
| described in the help of the `fill-region' function."
| 
|   (interactive "p")
|   (let ((point (point))
|         (mark (and mark-active (mark))))
|     (message (format "justify is %s" justify))
|     (if (and mark (not (equal point mark)))
|         (fill-region (min point mark) (max point mark)
|                      (if (= justify 1)
|                          nil
|                        'full))
|       (fill-paragraph justify))))
| 
| ;;; Bind our own `fill-region-or-paragraph' to M-q.
| (global-set-key (kbd "M-q") 'fill-region-or-paragraph)
`----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]