Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!caen!uakari.primate.wisc.edu!samsung!emory!gatech!udel!rochester!pt.cs.cmu.edu!o.gp.cs.cmu.edu!andrew.cmu.edu!jk3t+ From: jk3t+@andrew.cmu.edu (Jonathan King) Newsgroups: comp.sys.mac.hypercard Subject: Re: The cleanest way to index into fields w/ text cursor? Message-ID: Date: 30 Jan 91 16:22:32 GMT References: <2373@beguine.UUCP>, <29617@mimsy.umd.edu> Organization: Psychology, Carnegie Mellon, Pittsburgh, PA Lines: 69 In-Reply-To: <29617@mimsy.umd.edu> potter@tove.cs.umd.edu (Richard Potter) writes: > I needed a HyperCard script to delete characters before the cursor back to > but not including the first non-blank character. Here, I assume you mean "first non-blank character before the insertion point". I've tidied up you solution below by commenting out the bad lines putting a + in front of my lines. on functionKey fkeyv if fkeyv=5 then put the selectedchunk into cursorloc put (word 5 to 8 of cursorloc) into thefield -- put (word 2 of cursorloc) into cursorindex -- put (cursorindex-1) into cursorindex + put ((word 2 of cursorloc) -1) into startcursor + put startcursor into cursorindex repeat while " " = (the value of ("char " & cursorindex & thefield)) -- do "put " & quote & quote & " into " & "char " & cursorindex & thefield -- kill the previous line; no reason to have this in the loop... put (cursorindex-1) into cursorindex end repeat + delete ("char"&&cursorindex&&"to"&&startcursors&&thefield) + select ("char"&&cursorindex&&"to"&&(cursorindex-1)&&thefield) -- restores insertion point to the field if delete doesn't...I forget + else pass functionKey --don't lock out other function keys! end if end functionKey My changes should help by taking the space deletions out of your loop, using the command "delete" rather than the horrible kluge you used, and unblocking the other function keys. > This script works, but I am wondering if there is a more direct way > of doing this. This is my first script that manipulates fields. Text handling is still a bear in HC 2.0. I *think* the fixes I made use the correct level of quoting/evaluation, but I don't have time to check it right now. I haven't done this kind of thing in a couple months. I've written a number of fairly general text-handling commands that I'll give to the world as soon as I tidy them up a bit. > In particular, the line: > put the selectedchunk into cursorloc > seems a cludgy way to get the location of the cursor. Actually, it's even weirder than that, since the selectedchunk might actually not be just the insertion point location. But by subtracting 1 from (word 2 of the selectedchunk), you are guaranteed to get the location at the front of the selection, which is what I assumed you wanted in this case. > Also, the line: > do "put " & quote & quote & " into " & "char " & cursorindex & thefield > seems a very hard way just to delete the character at the position > designated by 'cursorindex'. Is there a way to avoid using 'do'? My solution was to use the 'delete' command. In my own stacks I use the home-rolled command deletebackwardchar, which in turn uses 'delete' Hope this helps... jking