I've included in my ~/.zshrc
the following code:
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
bg
zle redisplay
else
zle push-input
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
... which I found in an answer to the question Remember a half-typed command while I check something.
It works, but originally the code contained this statement:
emulate -LR zsh
I looked for the emulate
command inside man zshbuiltins
to understand the -L
and -R
options.
It seems that emulate -R zsh
resets all the options to their default values, which I checked with this command:
vimdiff <(setopt) <(emulate -R zsh; setopt)
However, if I execute emulate -R zsh
in an interactive shell, it resets the options definitively, so I suppose that's where the -L
flag is needed:
to make the new values of the options local to the current function (if any).
It also seems to imply that options can have a local value, in addition to a global one, and that in case of a conflict, the local one has priority.
So, emulate -LR zsh
is used to re-create a local environment with default and predictable values for the options, in which the author of a widget doesn't have to wonder what the options will be when its function is invoked, or to save (at the beginning of the function) then restore (at the end) all the options which may change the intended behavior of the widget.
I didn't copy the line because it seems to work without it. However, I would like to know if my understanding of this command is correct, and if someone could provide one or two simple examples, where emulate -LR zsh
is necessary to avoid side effects.
bindkey "^z" push-line-or-edit
– thrig Jun 22 '17 at 17:52