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: Le Wang
Subject: Re: creating a function that works for active region or whole buffer
Date: Wed, 23 Jan 2013 00:01:57 +0800

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.

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

When you have this function written, if you post the whole thing here,
I'm sure people will give you some ideas on improving your code.


-- 
Le



reply via email to

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