help-gnu-emacs
[Top][All Lists]
Advanced

[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: Ludwig, Mark
Subject: RE: creating a function that works for active region or whole buffer
Date: Tue, 22 Jan 2013 17:18:56 +0000

> 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.

Cheers,
Mark




reply via email to

[Prev in Thread] Current Thread [Next in Thread]