Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: accept-line question



[How did we end up back on -workers again?]

On Apr 2, 10:12am, Dave Yost wrote:
}
} Extra credit:
} 
} Is there a way to write a function x3 that calls x2, such that I can
} issue x3 from the command line get the result above instead of
}
} xxx:zle:3: widgets can only be called when ZLE is active
} xxx:zle:3: widgets can only be called when ZLE is active

Not as a stand-alone function, no.  There is no way to "queue up" an
accept-line (or any other widget action) from outside ZLE.  You can
put things on the LIFO buffer stack but they are treated as contents
of $BUFFER, not executed as keystrokes.

You can do it with some collusion from zle-line-init:

zle-line-init() {
  local -a queue
  while [[ -n "$BUFFER" ]]
  do
    queue=("$BUFFER" "${(@)queue}")
    BUFFER=
    zle get-line
  done
  for BUFFER in "${(@)queue}"
  do
    zle execute-now
  done
}

zle -N zle-line-init

xxx() {
  if zle
    BUFFER="$1"
    zle execute-now
  else
    print -z "$1"
  fi
}



Messages sorted by: Reverse Date, Date, Thread, Author