agzam / spacehammer

Hammerspoon config inspired by Spacemacs
MIT License
564 stars 70 forks source link

Update advice system to not require defining advisable functions #168

Open jaidetree opened 2 years ago

jaidetree commented 2 years ago

There was a fennel online meetup, and I gave an impromptu overview of spacehammer and hammerspoon and went over the advising system.

Technomancy suggested another approach: Apply the advice at a module level to replace the target functions. This means defadvice would take an extra arg for module location but it could update the module registry at runtime and it would not need any make-advisable or defn macros.

Grazfather commented 2 years ago

Trying to avoid reading all the code right now, but iirc the way we do it is we define the function as advisable, and it keeps a meta table that remembers if its advised, and if so, knows to invoke the advised functions when and where.

I like his suggestion, it's certainly simpler. Only thing I can think of as a trade-off is that if a handle to the function directly were held anywhere, then advising the function wouldn't 'apply' there.