No, I am not looking for one - this *is* such an example! :)
It worked so easily and cleanly (thanks to Scintilla having the right
functions) that I just had to share it... note that this is OCaml, but
the logic flow should be fairly obvious.
(* function def *)
let word_from_position editor pos =
if pos < 0 || pos >= editor#get_length then ""
else
let a = editor#word_start_position pos true in
let b = editor#word_end_position pos true in
editor#get_text_range {cpMin=a; cpMax=b}
(* called as *)
word_from_position editor (editor#position_from_point_close x y)
All of the "editor#..." calls correspond to existing builtin functions
in Scintilla; also, the "{cpMin=a; cpMax=b}" dynamically builds a
struct of the type expected by get_text_range.
Finally, note that even in the absence of declarations, this *is*
strongly typed (but inferred): since pos is used with integer
comparisons, it must be an int; editor is required to be an object
which has *at least* get_length, word_start_position,
word_end_position, get_text_range, and position_from_point_close as
methods... there is exactly one struct type that has cpMin and cpMax etc.
Anyway, this was sweet - and there was no bizarre mapping or
adjustment required with the x and y coordinates - it Just Worked(tm).
Robert Roessler
[EMAIL PROTECTED]
http://www.rftp.com
_______________________________________________
Scintilla-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scintilla-interest