From: "Ludwig, Mark" <ludwig.mark@siemens.com>
To: Le Wang <l26wang@gmail.com>, Luca Ferrari <fluca1978@infinito.it>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: RE: creating a function that works for active region or whole buffer
Date: Tue, 22 Jan 2013 17:18:56 +0000 [thread overview]
Message-ID: <BC5672F8AD4C054BAF167C9801500D1ABCABC08D@USSLMMBX002.net.plm.eds.com> (raw)
In-Reply-To: <CAM=K+iraUN5+jPcny8cn4_m6njhD355rBMSfQPwRbzY5+N-w9Q@mail.gmail.com>
> 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
next prev parent reply other threads:[~2013-01-22 17:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-22 11:20 creating a function that works for active region or whole buffer Luca Ferrari
2013-01-22 14:37 ` Mark Skilbeck
2013-01-22 16:01 ` Le Wang
2013-01-22 17:18 ` Ludwig, Mark [this message]
[not found] ` <mailman.18089.1358876370.855.help-gnu-emacs@gnu.org>
2013-01-22 19:57 ` Barry Margolin
2013-01-23 7:41 ` Luca Ferrari
2013-01-23 7:43 ` Luca Ferrari
2013-01-28 14:02 ` Stefan Monnier
2013-02-01 10:36 ` Luca Ferrari
2013-02-01 13:55 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BC5672F8AD4C054BAF167C9801500D1ABCABC08D@USSLMMBX002.net.plm.eds.com \
--to=ludwig.mark@siemens.com \
--cc=fluca1978@infinito.it \
--cc=help-gnu-emacs@gnu.org \
--cc=l26wang@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.