Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

el-patch convenience directives to emulate advice-add #37

Closed
Luis-Henriquez-Perez opened this issue Mar 7, 2019 · 9 comments
Closed

Comments

@Luis-Henriquez-Perez
Copy link

There are some functions that I can customize to my liking by either using around advice or overriding advice as opposed to copying the whole to my init file and using the el-patch directives. However, I'd still like the ability to track if any changes have occurred to the original definitions.

I know that if I wanted to emulate overriding, for example, I can do:
(el-patch-defun my-fun (args) (el-patch-swap (long original definition that I don't want to copy into my init file...) (new definition))

However I'd like to be able to do something like:
(el-patch-defun my-fun (args) (el-patch-override (new-definition)).

Where el-patch-override would be the same as el-patch-swap but using the whole definition.

I think what I'm asking boils down to:
Does el-patch provide a way to reference the definition original function definition without writing it out?
Does el-patch provide a way to define my own custom directives (so I could create el-patch-override)?

@raxod502
Copy link
Member

raxod502 commented Mar 7, 2019

Maybe this is a dumb question, but what's wrong with advice? M-x describe-function lists all the advice that has been added to a function, and lets you jump to the source code of each advice function.

@Luis-Henriquez-Perez
Copy link
Author

No, it's not a dumb question.

I was wondering this: if el-patch lets us check whether the original function has changed why use advice at all? Why not just not use el-patch for all advices? Sure functions in external emacs packages are more likely to change than built-in ones, but they can both change.

I get the feeling there's a reason why (in radian.el for example I see that you sometimes use el-patch and sometimes regular advice) but I'm not sure.

@raxod502
Copy link
Member

raxod502 commented Mar 9, 2019

Uh, how would el-patch know if the original function has changed, if you don't copy the definition into your init-file? Where would it be getting that information from?

The point of el-patch is that you should avoid it whenever you can, since advice is more lightweight, robust, and flexible.

@Luis-Henriquez-Perez
Copy link
Author

Thanks, your answer cleared up my misunderstanding.

I'm ready to close this issue but will wait one day until doing so unless you wanted to say anything else.

@hab25
Copy link

hab25 commented Jan 5, 2024

The point of el-patch is that you should avoid it whenever you can, since advice is more lightweight, robust, and flexible.

@raxod502 what makes advice more robust and flexible?

@raxod502
Copy link
Member

Because it doesn't need to be updated when the original code changes, unless it depends in some important functional way on the original function behavior. el-patch is for cases where you need to change a specific sub-part of a function, and can't express the change as one of the standard :override, :around, etc options.

@hab25
Copy link

hab25 commented Jan 12, 2024

Because it doesn't need to be updated when the original code changes

But , given that el-patch-define-template exists (n.b. its interaction with '...) this is true for el-patch as well, no? AFAICT by using templates, every single one of the :override, :around, etc can be expressed (i.e. in a way that matches requirements for updates identically in all cases).

To be clear; I'm not trying to cause annoyance by nitpicking correctness; I'm trying to clarify my understanding.

@raxod502
Copy link
Member

Yeah, I guess now that templates have been added, you could use them to achieve more or less the same thing as advice. I don't know that they would support stacking and ordering though. You can have arbitrarily many advices registered by different systems and they will all work together in a defined way. I don't think that would be the case with el-patch, which is really intended only for use in the end user's configuration.

@hab25
Copy link

hab25 commented Jan 25, 2024

Yeah, I guess now that templates have been added, you could use them to achieve more or less the same thing as advice. I don't know that they would support stacking and ordering though. You can have arbitrarily many advices registered by different systems and they will all work together in a defined way. I don't think that would be the case with el-patch, which is really intended only for use in the end user's configuration.

Makes sense, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants