[Top][All Lists]

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

Re: region-active-p

From: Stephen J. Turnbull
Subject: Re: region-active-p
Date: Fri, 26 Oct 2007 14:38:48 +0900

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?


Specifically, the function that calls `region-active-p' does not.
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]