From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Luca Ferrari Newsgroups: gmane.emacs.help Subject: creating a function that works for active region or whole buffer Date: Tue, 22 Jan 2013 12:20:54 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1358853669 18483 80.91.229.3 (22 Jan 2013 11:21:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Jan 2013 11:21:09 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 22 12:21:28 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 1Txbux-0006ca-AJ for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Jan 2013 12:21:27 +0100 Original-Received: from localhost ([::1]:47410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Txbug-0002sc-3E for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Jan 2013 06:21:10 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:56343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Txbua-0002rf-LB for help-gnu-emacs@gnu.org; Tue, 22 Jan 2013 06:21:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TxbuY-00045d-Lq for help-gnu-emacs@gnu.org; Tue, 22 Jan 2013 06:21:04 -0500 Original-Received: from mail-wi0-f169.google.com ([209.85.212.169]:53469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxbuY-00045N-FA for help-gnu-emacs@gnu.org; Tue, 22 Jan 2013 06:21:02 -0500 Original-Received: by mail-wi0-f169.google.com with SMTP id hq12so3254527wib.4 for ; Tue, 22 Jan 2013 03:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:date:x-google-sender-auth:message-id :subject:from:to:content-type; bh=saY8GgTYcHZtyVA+iO8D5G0hn8y6ZiXH7tapJTAFgOs=; b=ZXyWUas622TXMZw6aX51dXk1SN9nFYVwfqlB4Kj4GsLMAW6k1mu6LaU67eLDZPJsUA BrQTHKuAvZaMqRQi+psS/NFbXvKvm41V79rZrr+Rnq8oGaGabdnrrKshkeqweva/fuEz lmwx1mTixG7zvZCnyJ+s16y0xlSSzGPbdxcTt3mqlzTAxs5AeOgsHQ/XoJIkO1FgNBEm cGPjRM0vhUqBMjaptmTaLagLt9aZST40KZvplR+Gh6/snxUB/0d3h4YWgRa4uP2MZ4PW WWTiW1UBTCsVsWeDVqXJKD3L2afILqBoMy9R98oRyIFLKRk9+Ir+/h14WRDBjUYhOGym kHOw== X-Received: by 10.194.58.175 with SMTP id s15mr31563929wjq.31.1358853654142; Tue, 22 Jan 2013 03:20:54 -0800 (PST) Original-Received: by 10.194.39.1 with HTTP; Tue, 22 Jan 2013 03:20:54 -0800 (PST) X-Google-Sender-Auth: S0_zbyGjUYGdwFQzuCm0W7HHxpQ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.212.169 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:88760 Archived-At: 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