How to find the zsh function associated with a zle widget

zlezsh

I'm messing around with the accept-line widget and not getting the results I want.
I want to inspect (and log) what is happening to accept-line by finding the underlying zsh function.

My understanding is that zle widgets exist in their own separate namespace with the operation zle -N mapping keys to value in this namespace and the operation zle -A duplicating mappings.

I had quite a detailed search of of the zshzle manual page and did some googling but the best I could come up with is the following that makes use the zle -l operation.

zle -l  | grep '^accept-line ' | grep -Eo '\(.*\)' | tr -d '()'

Is there anything that doesn't depend so directly on the format of the output of zle -l.

Best Answer

There is a special array called widgets which holds names of all widgets and functions associated to them, so try

echo $widgets[accept-line]

Be aware however that some widgets are defined internally and all you will get is a word builtin, but judging from your grep command some script sourced in .zshrc overwrote that widget, so you should get meaningful result.

BTW, if you want to list all available widgets and their functions use (kv) flag:

echo ${(kv)widgets}