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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

creating a function that works for active region or whole buffer


From: Luca Ferrari
Subject: creating a function that works for active region or whole buffer
Date: Tue, 22 Jan 2013 12:20:54 +0100

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



reply via email to

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