Macro get_word()?
YT Lim
ytlim23 at yahoo.com.au
Mon Jan 22 18:36:20 CET 2007
Hi Tony,
Thanks for the explanation. Sorry for asking a rather
dumb question as I somehow only saw the first part of
your original answer before asking.
Regards,
/Y.T.
--- Tony Balinski <ajbj at free.fr> wrote:
> Quoting YT Lim <ytlim23 at yahoo.com.au>:
>
> > > > The following looks for word ends rather than
> > > delimiting spaces.
> > > ...
> > > Oops, sent too soon!
> > > ...
> > > > define get_word_at_pos
> > > > {
> > > > pos = $cursor
> > > > if ($n_args > 0)
> > > > pos = $1
> > > > string = ""
> > > > use_string = 0
> > > > if ($n_args > 1)
> > > > {
> > > > string = $1
> > > > use_string = 1
> > > > }
> > > ...
> > > string = $1
> > > should read
> > > string = $2
> >
> > Thanks for the response.
> >
> > You are too fast for me. Could you please explain
> a
> > little for me? I can't understand the purpose of
> > use_string. Is the "word" stored in string?
> The idea in the function is to be able to extract a
> word either from
> a string (if supplied) or from the document's text.
> If you supply
> no parameters or just a position (pos), use_string
> will be set to zero
> and the document's text will be used; if you supply
> a position (pos)
> and a string, use_text will be set to one and the
> attempt to find the
> word will use the position pos in the string
> instead. I had only ever
> used the function with the document's text, so I
> never noticed that it
> wouldn't work when supplying a string instead... So
> use_string is just
> an internal boolean, and string is ignored if
> use_string is zero
> (false).
>
> The calls are as follows:
> get_word_at_pos(): returns the word found under
> the cursor in the
> editor window (current
> document)
> get_word_at_pos(pos): returns the word found at
> position pos in the
> editor window (current
> document)
> get_word_at_pos(pos, str): returns the word found
> at position pos
> in the string str
>
> So these two calls have the same result:
> word = get_word_at_pos()
> word = get_word_at_pos($cursor, get_range(0,
> $text_length))
> except that the second copies your document into a
> string (returned
> from get_range()), and looks inside the string - so
> it's less efficient.
>
> HTH
>
> Tony
>
>
> --
> NEdit Discuss mailing list - Discuss at nedit.org
> http://www.nedit.org/mailman/listinfo/discuss
>
Send instant messages to your online friends http://au.messenger.yahoo.com
More information about the Discuss
mailing list