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

Accessing marked regions in ZMACS

    Date: Tue, 20 Jun 89 09:55 CDT
    From: ACKLEY@GUINEVERE.tamu.edu (Keith Ackley)

    I have a command in ZMACS where the user marks a region of text,
    and then types a single keystroke to invoke the command. The
    problem is how do I access that section of text in my command.
    Is there some easy way to open a stream on that interval?

    I have found the function OPEN-INTERVAL-STREAM which appears to
    be what I want. But how do you specify the region that has
    been marked by the user.

You can use the macro ZWEI:WITH-REGION-BPS to get "buffer pointers" to
the beginning and end of the marked region.

(zwei:with-region-bps (start-bp end-bp)
  (format t "~&Text in region is:~%~S"
	  (zwei:string-interval start-bp end-bp)))

As you have already discovered, the way to produce a character input
stream from the region (or any other "interval" between two BP's) is via
OPEN-INTERVAL-STREAM.  You can also convert the interval into a string
ZWEI:STRING-INTERVAL as shown above.  There are many other ZWEI
facilities that operate on intervals as well.

If your command is intended to act on Lisp code, you should probably use
ZWEI:DEFINITION-REGION-BPS instead.  This will do the same thing as
ZWEI:WITH-REGION-BPS when the user has explicitly marked a region in the
buffer.  However, if no region has been marked, the two BP's will
automatically specify the region enclosing the current Lisp definition.
This is how c-sh-C (Compile Region) works.