unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: creating a function that works for active region or whole buffer
Date: Tue, 22 Jan 2013 14:57:20 -0500	[thread overview]
Message-ID: <barmar-38F651.14572022012013@news.eternal-september.org> (raw)
In-Reply-To: mailman.18089.1358876370.855.help-gnu-emacs@gnu.org

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


  parent reply	other threads:[~2013-01-22 19:57 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
     [not found]   ` <mailman.18089.1358876370.855.help-gnu-emacs@gnu.org>
2013-01-22 19:57     ` Barry Margolin [this message]
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=barmar-38F651.14572022012013@news.eternal-september.org \
    --to=barmar@alum.mit.edu \
    --cc=help-gnu-emacs@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).