[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: creating a function that works for active region or whole buffer
From: |
Mark Skilbeck |
Subject: |
Re: creating a function that works for active region or whole buffer |
Date: |
Tue, 22 Jan 2013 14:37:39 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
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
Re: creating a function that works for active region or whole buffer,
Mark Skilbeck <=