From ffc756c5ff2e6c1552019a3b2df909783a26c12f Mon Sep 17 00:00:00 2001 From: raslop <102158292+raslop@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:17:42 +0200 Subject: [PATCH] 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 --- eval.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eval.go b/eval.go index 3b3eab12..ff04308e 100644 --- a/eval.go +++ b/eval.go @@ -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 if strings.HasPrefix(e.opt, "user_") { 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 { app.ui.echoerrf("unknown option: %s", e.opt) }