unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: rayz@phonon.com
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	[thread overview]
Message-ID: <1150478500.067894.7710@h76g2000cwa.googlegroups.com> (raw)
In-Reply-To: 86mzcewci2.fsf@gothmog.pc

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	other threads:[~2006-06-16 17:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1150478500.067894.7710@h76g2000cwa.googlegroups.com \
    --to=rayz@phonon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).