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: rayz
Subject: Re: How do I overload M-q to invoke fill-region only when mark is active?
Date: 16 Jun 2006 10:21:40 -0700
User-agent: G2/0.2

Giorgos Keramidas wrote:
> 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)
[removed nice documention for brevity]
> |   (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)
> `----------------------------------------------------------------------

Thanks so much!

I altered it slightly because fill-paragraph was always doing full
justification.  Then I figured I'd pass the justify parameter along to
fill-region, as well.

So, here's the body of the function I'm using, in case some one else
wants to use it (or, more likely, I mis-place the code and need it
again):

|  (interactive "P")
|  (let ((point (point))
|        (mark (and mark-active (mark))))
|    (message (format "justify is %s" justify))
|    (if (and mark (not (equal point mark)))
|       (if justify
|           (fill-region (min point mark) (max point mark) 'full)
|         (fill-region (min point mark) (max point mark)))
|      (if justify
|         (fill-paragraph 'full)
|       (fill-paragraph nil)))))



reply via email to

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