From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark Skilbeck Newsgroups: gmane.emacs.help Subject: Re: creating a function that works for active region or whole buffer Date: Tue, 22 Jan 2013 14:37:39 +0000 Message-ID: <20130122143739.GB24801@iammark.us> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1358882638 19108 80.91.229.3 (22 Jan 2013 19:23:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Jan 2013 19:23:58 +0000 (UTC) Cc: help-gnu-emacs To: Luca Ferrari Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 22 20:24:15 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TxjSB-000430-0o for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Jan 2013 20:24:15 +0100 Original-Received: from localhost ([::1]:43060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxjRt-0003Qr-S0 for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Jan 2013 14:23:57 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:57178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxjRm-0003Qh-KS for help-gnu-emacs@gnu.org; Tue, 22 Jan 2013 14:23:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TxjRZ-0005sL-VV for help-gnu-emacs@gnu.org; Tue, 22 Jan 2013 14:23:50 -0500 Original-Received: from li357-97.members.linode.com ([178.79.188.97]:53295 helo=mail.iammark.us) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Txeyr-00036E-Dk for help-gnu-emacs@gnu.org; Tue, 22 Jan 2013 09:37:41 -0500 Original-Received: by mail.iammark.us (Postfix, from userid 1000) id 4F71BAED4; Tue, 22 Jan 2013 14:37:39 +0000 (GMT) Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 178.79.188.97 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:88769 Archived-At: Perhaps with-region-or-buffer[1] will be of help. -mgsk [1] http://irrealblog.blogspot.co.uk/2011/03/region-or-buffer-revisited-in-writing_02.html On Tue, Jan 22, 2013 at 12:20:54PM +0100, Luca Ferrari wrote: > Hi all, > I'd like to write a function that can be invoked when a region is > active, and therefore is limited to the region itself, or on the whole > buffer if not any region is active. Therefore in my function I placed > the following conditional to set the start-block and end-block lines > to the whole buffer or the whole region: > > > (if (not (null (region-beginning) ) ) > (progn > > (setq current-block-start-line (line-number-at-pos > (region-beginning) ) ) > (setq current-block-end-line (line-number-at-pos > (region-end) ) ) ) > > ; else mark the whole buffer > (progn > (setq current-block-start-line (line-number-at-pos (point-min) ) ) > (setq current-block-end-line (line-number-at-pos (point-max) ) ) ) ) > > It seems to work, but when I mark a region, that remove the region > (i.e., unmark) and call the function again it seems that the function > has still the region-beginning and region-end marks (i.e., it does not > work on the whole buffer). Is there a smarter way to see if a region > is currently active? > > Thanks, > Luca