* How do I overload M-q to invoke fill-region only when mark is active?
@ 2006-06-15 16:57 rayz
2006-06-15 17:32 ` Giorgos Keramidas
0 siblings, 1 reply; 3+ messages in thread
From: rayz @ 2006-06-15 16:57 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How do I overload M-q to invoke fill-region only when mark is active?
2006-06-15 16:57 How do I overload M-q to invoke fill-region only when mark is active? rayz
@ 2006-06-15 17:32 ` Giorgos Keramidas
2006-06-16 17:21 ` rayz
0 siblings, 1 reply; 3+ messages in thread
From: Giorgos Keramidas @ 2006-06-15 17:32 UTC (permalink / raw)
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)
`----------------------------------------------------------------------
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How do I overload M-q to invoke fill-region only when mark is active?
2006-06-15 17:32 ` Giorgos Keramidas
@ 2006-06-16 17:21 ` rayz
0 siblings, 0 replies; 3+ messages in thread
From: rayz @ 2006-06-16 17:21 UTC (permalink / raw)
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)))))
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-06-16 17:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-15 16:57 How do I overload M-q to invoke fill-region only when mark is active? rayz
2006-06-15 17:32 ` Giorgos Keramidas
2006-06-16 17:21 ` rayz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).