unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Giorgos Keramidas <keramida@ceid.upatras.gr>
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	[thread overview]
Message-ID: <86mzcewci2.fsf@gothmog.pc> (raw)
In-Reply-To: 1150390669.240766.213550@i40g2000cwc.googlegroups.com

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	other threads:[~2006-06-15 17:32 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 [this message]
2006-06-16 17:21   ` rayz

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=86mzcewci2.fsf@gothmog.pc \
    --to=keramida@ceid.upatras.gr \
    /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).