unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to modify a function of a package
@ 2023-10-12 19:39 Maske
  2023-10-12 22:02 ` Philip Kaludercic
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Maske @ 2023-10-12 19:39 UTC (permalink / raw)
  To: help-gnu-emacs

Hi

I have installed a package and I want to modify a function of it, but 
not in the package itself, because if there is an update it would stop 
working, so I have added the function modified in my init file. But, it 
doesn't work. The package behavior is not altered.

What would be the correct way?

Best regards




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to modify a function of a package
  2023-10-12 19:39 How to modify a function of a package Maske
@ 2023-10-12 22:02 ` Philip Kaludercic
  2023-10-13  4:24   ` tomas
  2023-10-12 23:54 ` Emanuel Berg
  2023-10-28 13:18 ` Nikolay Kudryavtsev
  2 siblings, 1 reply; 6+ messages in thread
From: Philip Kaludercic @ 2023-10-12 22:02 UTC (permalink / raw)
  To: Maske; +Cc: help-gnu-emacs

Maske <maske1foro@gmail.com> writes:

> Hi
>
> I have installed a package and I want to modify a function of it, but
> not in the package itself, because if there is an update it would stop
> working, so I have added the function modified in my init file. But,
> it doesn't work. The package behavior is not altered.

If you know that it will only affect you and you can reasonably assume
that the feature will be stable in future versions, you can take a look
at `(elisp) Advising Functions'.  Specifically the function
`define-advice' could be of use, here is an example that pulses the
region evaluated using C-M-x:

(define-advice eval-region (:after (start end &rest _))
  (pulse-momentary-highlight-region start end))

The other option is always to share your contribution with the author
and all other users.  This might require some discussions and
generalising whatever you changed, and even if nothing is accepted you
probably stand learning something new, so it is always worth the try.
You can use package-vc-install to fetch the package sources (which btw.
doesn't loose local modifications on updating, but therefore might
require resolving a merge-conflict), and package-vc-submit-patch to send
the change to the maintainer.

> What would be the correct way?
>
> Best regards



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to modify a function of a package
  2023-10-12 19:39 How to modify a function of a package Maske
  2023-10-12 22:02 ` Philip Kaludercic
@ 2023-10-12 23:54 ` Emanuel Berg
  2023-10-28 13:18 ` Nikolay Kudryavtsev
  2 siblings, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2023-10-12 23:54 UTC (permalink / raw)
  To: help-gnu-emacs

Maske wrote:

> I have installed a package and I want to modify a function
> of it, but not in the package itself, because if there is an
> update it would stop working, so I have added the function
> modified in my init file. But, it doesn't work. The package
> behavior is not altered.

You can use `eval-defun' or `eval-last-sexp' and try whatever
the package does after that, if you use the same name as the
package for the function it should work.

But it should also work from the init file, maybe you load the
package at a later stage so the old definition gets used all
the same?

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to modify a function of a package
  2023-10-12 22:02 ` Philip Kaludercic
@ 2023-10-13  4:24   ` tomas
  0 siblings, 0 replies; 6+ messages in thread
From: tomas @ 2023-10-13  4:24 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]

On Thu, Oct 12, 2023 at 10:02:00PM +0000, Philip Kaludercic wrote:
> Maske <maske1foro@gmail.com> writes:
> 
> > Hi
> >
> > I have installed a package and I want to modify a function of it [...]
> > so I have added the function modified in my init file. But,
> > it doesn't work. The package behavior is not altered.

[...]

Apart from Philip's very valid points:

 - advice lets you change a function's behaviour, but still use the
  original function. This is usually what you want to do (this is
  *not*, however, what a packager should do, usually)
 - talk with the authors

> > What would be the correct way?

what is probably happening is that the package is loaded *after*
your function definition in the init file, thus overwriting your
definition.

Since packages are often loaded lazily, you haven't always control
of when it happens. To avoid that, you can either load the package
explicitly before you do your function definition or (much better)
look into `eval-after-load', which was made for such things.

You'll have to do that also if you go the advice route: the function
wants to exist before you attach some advice to it.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to modify a function of a package
  2023-10-12 19:39 How to modify a function of a package Maske
  2023-10-12 22:02 ` Philip Kaludercic
  2023-10-12 23:54 ` Emanuel Berg
@ 2023-10-28 13:18 ` Nikolay Kudryavtsev
  2023-10-28 23:55   ` Maske
  2 siblings, 1 reply; 6+ messages in thread
From: Nikolay Kudryavtsev @ 2023-10-28 13:18 UTC (permalink / raw)
  To: Maske, help-gnu-emacs

Since everyone gave you only the more advanced answers, here's also the 
simple ones:

1. You do (require 'package) before redefining a function in it. Won't 
always work, a package may do something really sneaky with it's 
functions, but should suffice for most cases.

2. If you use use-package, put your function redefinition into the 
:config form and that's it.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to modify a function of a package
  2023-10-28 13:18 ` Nikolay Kudryavtsev
@ 2023-10-28 23:55   ` Maske
  0 siblings, 0 replies; 6+ messages in thread
From: Maske @ 2023-10-28 23:55 UTC (permalink / raw)
  To: Nikolay Kudryavtsev; +Cc: help-gnu-emacs

I will try those solution as soon as I get some time (after updating the package I have problems again).

Thanks to all of you for your lessons :-)

Oct 28, 2023 15:19:04 Nikolay Kudryavtsev <nikolay.kudryavtsev@gmail.com>:

> Since everyone gave you only the more advanced answers, here's also the simple ones:
> 
> 1. You do (require 'package) before redefining a function in it. Won't always work, a package may do something really sneaky with it's functions, but should suffice for most cases.
> 
> 2. If you use use-package, put your function redefinition into the :config form and that's it.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-28 23:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 19:39 How to modify a function of a package Maske
2023-10-12 22:02 ` Philip Kaludercic
2023-10-13  4:24   ` tomas
2023-10-12 23:54 ` Emanuel Berg
2023-10-28 13:18 ` Nikolay Kudryavtsev
2023-10-28 23:55   ` Maske

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).