a new eval variable to make good use of short-circuit evaluation
pascalpoitras opened this issue · comments
Feature description
${eval_cond:...}
and /eval -c
return 0 or 1 which is perfect, but it would be nice to have a variant which instead of returning 0 and 1, return the last evaluated value. For that we need short-circuit evaluation which seems to be already the case in WeeChat:
/trigger add test info test "" "" "/print -core test"
/eval -n -c 1 || ${info:test}
doesn't print 'test' because 1 is true so ${info:test} is not evaluated
/eval -n -c 0 || ${info:test}
now we see the output 'test'
So clearly it is short-circuit evaluation
So with this feature, one would be able to do something like
${last:${plugins.var.welcome_msg} || Welcome to #weechat}
which will be the content of plugins.var.welcome_msg if it have a value and this value is not 0. Otherwise it will be "Welcome to #weechat"
it is nicer than
${if:${plugins.var.welcome_msg}?${plugins.var.welcome_msg}:Welcome to #weechat}