[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: |
Barry Margolin |
Subject: |
Re: creating a function that works for active region or whole buffer |
Date: |
Tue, 22 Jan 2013 14:57:20 -0500 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article <mailman.18089.1358876370.855.help-gnu-emacs@gnu.org>,
"Ludwig, Mark" <ludwig.mark@siemens.com> wrote:
> > From: Le Wang
> > Sent: Tuesday, January 22, 2013 10:02 AM
> > To: Luca Ferrari
> > Cc: help-gnu-emacs
> > Subject: Re: creating a function that works for active region or whole
> > buffer
> >
> > On Tue, Jan 22, 2013 at 7:20 PM, Luca Ferrari <fluca1978@infinito.it>
> > 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)
> > > ) ) ) )
> >
> > Don't focus on line numbers, focus on buffer positions.
>
> Right!
>
> > > 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?
> >
> > See mark-active-p, use-region-p documentation.
>
> I recommend just using (point-min) and (point-max) as these work
> appropriately in and out of a narrowed-region.
Who said anything about narrowing?
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Re: creating a function that works for active region or whole buffer, Mark Skilbeck, 2013/01/22