Well, to get the last N lines of a window, you can use $lines and $line. Example, gett eh last 10 lines:
alias last10 {
var %window = $active, %l = $line(%window, 0), %a = 0
/window @last10
/echo @last10 Last 10 lines in %window
while (%a < 10) {
/echo @last10 $line(%window, %l)
/inc %a
/dec %l
}
}
Save those last lines in a var or two, and relate what your trying to complete, with what is found. I'd probably add unique words to an array, then use something lik e$var to match prefixes.