Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!purdue!gatech!prism!loligo!pepke From: pepke@loligo.cc.fsu.edu (Eric Pepke) Newsgroups: comp.sys.mac.programmer Subject: Re: How do I read a line? Message-ID: <751@loligo.cc.fsu.edu> Date: 7 Jun 89 14:42:03 GMT References: <10387@burdvax.PRC.Unisys.COM> Reply-To: pepke@loligo.UUCP (Eric Pepke) Organization: Supercomputer Computations Research Institute Lines: 34 This is not really that hard to do, but you have to rethink the problem a little bit. Instead of thinking in terms of the program stopping and reading input, where the program is in control, think in terms of the user deciding when to give information to the program. Have the program maintain an event loop and a TextEdit window, just as you are doing. Define a special key, perhaps the Enter key or Command-Return that, when pressed, sends either the selection range or the line that the insertion point is on to the program. The program then uses a switchboard kind of approach to determine what to do with the text; i.e. it asks itself "What question am I asking now?" and applies the text to the answer. Getting the selection range is easy, and to get the line that the insertion point is on you can, for example, search backward and forward for return characters and the beginning and end of text. I have done something like this in a C program which contains a subset of a Common LISP interpreter. One of the windows is a LISP listener and forms sort of an inside-out development system which is very handy. My problem is trickier, as LISP is not line-oriented, but the principle is the same. (Instead of getting the line that the insertion point is on, I look back and find where the last message from the program ended and read from there to the insertion point.) I am reluctant to give you all of the code, as it is quite a hack and I don't bother, for example, to implement the Edit menu. As David Dunham says, if it doesn't have Undo, it's not a Mac program. However, I will look at it to see if the relevant sections might be extracted and still be meaningful. Most of the rest is just TextEdit. Eric Pepke INTERNET: pepke@gw.scri.fsu.edu Supercomputer Computations Research Institute MFENET: pepke@fsu Florida State University SPAN: scri::pepke Tallahassee, FL 32306-4052 BITNET: pepke@fsu Disclaimer: My employers seldom even LISTEN to my opinions. Meta-disclaimer: Any society that needs disclaimers has too many lawyers.