From bd175be9735f62a6eda73cb12b1f2b6a892b9d2a Mon Sep 17 00:00:00 2001 From: raslop <102158292+raslop@users.noreply.github.com> Date: Sun, 10 Sep 2023 15:08:46 +0200 Subject: [PATCH 1/2] 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. --- eval.go | 1 + 1 file changed, 1 insertion(+) diff --git a/eval.go b/eval.go index 3b3eab12..07356dd4 100644 --- a/eval.go +++ b/eval.go @@ -920,6 +920,7 @@ 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 + os.Setenv("lf_"+e.opt, e.val) } else { app.ui.echoerrf("unknown option: %s", e.opt) } From 77aebb061f11a80cf75ad5f81ce10f8f4155d7d6 Mon Sep 17 00:00:00 2001 From: raslop <102158292+raslop@users.noreply.github.com> Date: Mon, 11 Sep 2023 10:06:53 +0200 Subject: [PATCH 2/2] Fix: Add explaining comment --- eval.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eval.go b/eval.go index 07356dd4..ff04308e 100644 --- a/eval.go +++ b/eval.go @@ -920,6 +920,9 @@ 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)