Skip to content

Functions not listening to events before the first load #845

Closed

Description

@wojtekerbetowski

Here's my case - I've a function myfunc in ~/.config/fish/functions

$ functions myfunc 
function myfunc --on-event doneevent
    echo done
end
$ 

If I enter new fish shell, the function is not 'activated' (not reacting to event).

$ emit doneevent
$ 

Although is I 'touch it' (call myfunc, or call functions myfunc) then it starts listening.

$ functions myfunc 
function myfunc --on-event doneevent
    echo done
end
$ emit doneevent
done
$ 

It seems that event listeners are not activated by default. The workaround is to manually activate it in config.fish (lame).

Activity

  1. dag commented on May 30, 2013

    @dag
    Contributor

    Quite so; I ran into this with an --on-variable handler. Fixing this without breaking on-demand loading of functions could be hard though.

  2. ridiculousfish commented on Jun 2, 2013

    @ridiculousfish
    Member

    Yes, not sure how this could be fixed.

  3. wojtekerbetowski commented on Jun 3, 2013

    @wojtekerbetowski
    Author

    Too bad. What's the best workaround? To link function creation file in
    config.fish then?

  4. terlar commented on Jun 3, 2013

    @terlar
    Contributor

    For these kind of things I currently define the functions in the config.fish or a file sourced by it.

  5. wojtekerbetowski commented on Jun 3, 2013

    @wojtekerbetowski
    Author

    Ok, thanks.

  6. smidm commented on Sep 16, 2014

    @smidm

    This issue really confused me for a while. It should be mentioned in the funcsave or function command documentation.

  7. lilyball commented on Sep 20, 2014

    @lilyball
    Contributor

    Noting this in the documentation of funcsave seems reasonable.

  8. added
    docs
    on Sep 20, 2014
  9. languitar commented on Jan 12, 2015

    @languitar

    I also just stumbled across this. Some kind of fix or at least explanations in the doc would be great.

  10. zanchey commented on Jan 12, 2015

    @zanchey
    Member

    What wording would be helpful?

  11. added a commit that references this issue on Aug 10, 2015
    60eafff
  12. faho commented on Aug 17, 2015

    @faho
    Member

    So now since #1382 has shown up, there seems to be a need to allow event handlers to be added from the outside.

    How should that look? Asking people to add something to config.fish is obviously not great, but the best I've come up with is adding an additional directory (called "events" or "hooks" or similar) that essentially contains functions that will either always be sourced or sourced on every event, but even that isn't exactly beautiful. funcsave could be modified to use this directory if the function has been defined as an event handler.

    Another solution (which would also be useful for e.g. function descriptions) is to, on start, peak at the function definition part of any .fish file, but that's very specialized.

    Or add special files named after the event (i.e. "fish_postexec.fish") that will be looked up when the event fires.

  13. faho commented on Aug 17, 2015

    @faho
    Member

    For example in Wahoo, we source any $WAHOO_CUSTOM/init.fish file during session start. This could easily be augmented to also source any $WAHOO_CUSTOM/events.fish file

    Really, files are nicer to outsiders wishing to add event listeners. E.g. pantheon-terminal could just drop-in a file (that can be properly managed by the package manager) to do the notification stuff. Of course that also implies override-logic like for completions.

  14. zanchey commented on Aug 27, 2015

    @zanchey
    Member

    A good solution to #1956 should enable this.

  15. zanchey commented on Aug 28, 2015

    @zanchey
    Member

    How do you mean, userland territory?

  16. faho commented on Aug 28, 2015

    @faho
    Member

    See e.g. #1382 - so that outside packages can drop in event handlers to enable additional features.

  17. modified the milestones: , fish-future on Oct 15, 2015
  18. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions