Skip to content

Commit

Permalink
Export user-options on change (#1418)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
raslop authored Sep 11, 2023
1 parent 9068801 commit ffc756c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ffc756c

Please sign in to comment.