Export user-options on change (#1418)

* Export user-options when they are evaluated

If one has an external previewer that uses an lf user-option (e.g.
"preview-mode") and some key-kindings that change this user-option (e.g.
to "hex", "simple", "fancy") and send a "reload" command to lf, then the
expectation after pressing the keys is, that the prewiever is called
with an updated value of the user-option. Though this did not happen
since #1354, as this caused random crashes.

This change exports user-defined options immediately when they are
evaluated.

* Fix: Add explaining comment
This commit is contained in:
raslop authored and GitHub committed 2023-09-11 16:17:42 +03:00
1 parent 9068801831
commit ffc756c5ff
1 file changed
+4
+4
View File
@@ -920,6 +920,10 @@ func (e *setExpr) eval(app *app, args []string) {
// any key with the prefix user_ is accepted as a user defined option // any key with the prefix user_ is accepted as a user defined option
if strings.HasPrefix(e.opt, "user_") { if strings.HasPrefix(e.opt, "user_") {
gOpts.user[e.opt[5:]] = e.val gOpts.user[e.opt[5:]] = e.val
// Export user defined options immediately, so that the current values
// are available for some external previewer, which is started in a
// different thread and thus cannot export (as `setenv` is not thread-safe).
os.Setenv("lf_"+e.opt, e.val)
} else { } else {
app.ui.echoerrf("unknown option: %s", e.opt) app.ui.echoerrf("unknown option: %s", e.opt)
} }