From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: rayz@phonon.com Newsgroups: gmane.emacs.help 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 Organization: http://groups.google.com Message-ID: <1150478500.067894.7710@h76g2000cwa.googlegroups.com> References: <1150390669.240766.213550@i40g2000cwc.googlegroups.com> <86mzcewci2.fsf@gothmog.pc> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: sea.gmane.org 1150479628 6700 80.91.229.2 (16 Jun 2006 17:40:28 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 16 Jun 2006 17:40:28 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 16 19:40:26 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 1FrIIz-0003r6-PW for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Jun 2006 19:40:26 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FrIIz-0003JN-39 for geh-help-gnu-emacs@m.gmane.org; Fri, 16 Jun 2006 13:40:25 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!h76g2000cwa.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 51 Original-NNTP-Posting-Host: 63.148.37.134 Original-X-Trace: posting.google.com 1150478503 13369 127.0.0.1 (16 Jun 2006 17:21:43 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 16 Jun 2006 17:21:43 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: h76g2000cwa.googlegroups.com; posting-host=63.148.37.134; posting-account=xJwmbQwAAACSikPHPz84iSsX47_wCM1G Original-Xref: shelby.stanford.edu gnu.emacs.help:139882 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor 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:35506 Archived-At: 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)))))