emacs-devel
[Top][All Lists]
Advanced

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

Re: region-active-p


From: Andreas Röhler
Subject: Re: region-active-p
Date: Fri, 26 Oct 2007 10:17:31 +0200
User-agent: KMail/1.9.5

Am Freitag, 26. Oktober 2007 07:38 schrieben Sie:
> Richard Stallman writes:
>  >      > When commands in XEmacs call [region-active-p], do they also test
>  >      > for a nonempty region?  Or do they operate on the region
>  >      > when it is empty?
>  >
>  >     Core commands defined in Lisp don't test (at least not within 3
>  > lines, checked with grep -3), but they're generally wrappers for
>  > functions defined in C that do test (eg, the casefilling commands).
>  >
>  > I don't entirely understand the answer.  Maybe I did not state the
>  > question clearly.  When you say they "don't test", what precisely
>  > don't they test?
>
> They don't test "for a nonempty region".
>
>  > Are you sayimg that they call `region-active-p' but do not test
>  > whether the region is nonempty?
>
> Yes.
>
> Specifically, the function that calls `region-active-p' does not.


So my understanding ceased to exist... :)

 `region-active-p' reads and depends with `and' from variable

`zmacs-region-extent'.

(and  ... zmacs-region-extent

If there is no extension, just the mark set,
`zmacs-region-extent' is nil and `region-active-p'
returns nil therefor.

I would qualify this behaviour as including a check.

BTW quite other thing with `region-exist-p'.

Maybe I miss the point?

Cheers

Andreas Röhler

> However, in the cases I looked at, that function simply dispatches to
> a more primitive function that acts on the region.  The more primitive
> function checks for non-empty in those cases.  The typical idiom is
>
> (defun fill-paragraph-or-region (arg)
>   "Fill the current region, if it's active; otherwise, fill the paragraph.
> See `fill-paragraph' and `fill-region' for more information."
>   (interactive "*P")
>   (if (region-active-p)
>       (call-interactively 'fill-region)
>     (call-interactively 'fill-paragraph)))
>
> `fill-region' *does* check that the region is nonempty before doing
> any work.




reply via email to

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