Say I copy the following codeblock from a .md handbook which incldes some information and a few codeblocks (hence it's not a script file):(Indented commands...)The Zsh preexec function could be used to remove all leading whitespaces (usually tabulations but maybe also spaces) from this original codeblock, and return a unindented version of it:(commands...)As far as I understand, the preexec action should include 's/^\s*//g'. Please share how you would achieve this goal with preexec.
Zsh preexec - How to trim all leading indentations from a codeblock?
sed;zsh;whitespace
Doing it in preexec would be too late. By that time, the code has already been parsed. If you modify it, it would need to be parsed again (and possibly, zsh would need to prompt for more lines to finish the code).Possibly here you can do it in the accept-line widget, that is just before the line editor feeds the line to the shell parser:accept-line() {  emulate -L zsh       # default zsh behaviour locally  set -o extendedglob  # with extendedglob for ## (= ERE +) below  BUFFER=${BUFFER##[[:blank:]]##} # remove leading blanks  # remove blanks after newlines in case a multiline buffer is accepted  # for instance after a safe-paste or a newline entered with <Alt+Ret>  BUFFER=${BUFFER//$'\n'[[:blank:]]##/$'\n'}  # call original accept-line  zle .$WIDGET}zle -N accept-line