From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Giorgos Keramidas Newsgroups: gmane.emacs.help 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 Organization: SunSITE.dk - Supporting Open source Message-ID: <86mzcewci2.fsf@gothmog.pc> References: <1150390669.240766.213550@i40g2000cwc.googlegroups.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1150393375 3001 80.91.229.2 (15 Jun 2006 17:42:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 15 Jun 2006 17:42:55 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 15 19:42:53 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Fqvra-0003Ql-Px for geh-help-gnu-emacs@m.gmane.org; Thu, 15 Jun 2006 19:42:39 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fqvra-0004mU-8G for geh-help-gnu-emacs@m.gmane.org; Thu, 15 Jun 2006 13:42:38 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!feed118.news.tele.dk!dotsrc.org!news.dotsrc.org!not-for-mail Original-Newsgroups: gnu.emacs.help Cancel-Lock: sha1:/GHbnSrZOmVadQeGYWX5U9GVu8g= Original-Lines: 38 Original-NNTP-Posting-Host: 62.103.39.229 Original-X-Trace: news.sunsite.dk DXC=fhK9>eKe]79=M\fUi`VZVL^Mj72:ak; I7eU]7Gb30c[>DY7; cNEjVKi8 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:35488 Archived-At: 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) `----------------------------------------------------------------------