Discussion:
How to change definition of gnus-summary-exit?
Nikolaus Rath
2015-10-14 17:28:35 UTC
Permalink
Hello,

I would like to change the definition of the gnus-summary-exit function.

I have made a copy of gnus-sum.el, put it in a new directory, modified
it, and added this directory to my load path in ~/.emacs:

| (add-to-list 'load-path "/home/nikratio/dir-with-gnus-sum.el")


If I start gnus and do C-h f gnus-summary-exit, it tells me that the
function is defined in gnus-sum.el. If I click on gnus-sum.el, Emacs
opens my modified gnus-sum.el file.

*However*, the version of gnus-summary-exit that Gnus is actually using
is *not* my modified one, but the original.

In order to use my version, I have to explicitly eval the definition
using C-x C-e. After that, it is used by Gnus.


What is happening here? Why does the help refer me to the modified
version, but the version in memory is actually the original one? And how
do I tell emacs/gnus to use my version?

Thanks,
-Nikolaus
--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

»Time flies like an arrow, fruit flies like a Banana.«
Adam Sjøgren
2015-10-14 18:08:09 UTC
Permalink
Post by Nikolaus Rath
What is happening here? Why does the help refer me to the modified
version, but the version in memory is actually the original one? And how
do I tell emacs/gnus to use my version?
I'm sure somebody with more hardcore knowledge than me will jump in;
just a guess: could it be a byte compiled file (.elc) that is being
picked up?

There is some kind of command to see what shadows what, but I don't use
it enough to remember it...


Best regards,

Adam
--
"The world is short of delimiters," says Don. Adam Sjøgren
***@koldfront.dk
Tassilo Horn
2015-10-15 06:34:07 UTC
Permalink
Post by Adam Sjøgren
What is happening here? Why does the help refer me to the modified
version, but the version in memory is actually the original one? And
how do I tell emacs/gnus to use my version?
Why do you copy the complete gnus-sum.el when you just want to
change one function? As a result, you won't see any future changes of
gnus-sum.el (bugfixes and new features).

What do you want to change exactly? Oftentimes, a simple advice will do
without having to override the complete function.
Post by Adam Sjøgren
I'm sure somebody with more hardcore knowledge than me will jump in;
just a guess: could it be a byte compiled file (.elc) that is being
picked up?
Indeed, if Nikolaus copied both gnus-sum.el and gnus-sum.elc into his
other directory, then modified gnus-sum.el but didn't recompile it, and
additionally `load-prefer-newer' is nil, that would explain the issue.
Post by Adam Sjøgren
There is some kind of command to see what shadows what, but I don't use
it enough to remember it...
It's `list-load-path-shadows'.

Bye,
Tassilo
Nikolaus Rath
2015-10-15 17:47:22 UTC
Permalink
Post by Tassilo Horn
Post by Adam Sjøgren
What is happening here? Why does the help refer me to the modified
version, but the version in memory is actually the original one? And
how do I tell emacs/gnus to use my version?
Why do you copy the complete gnus-sum.el when you just want to
change one function? As a result, you won't see any future changes of
gnus-sum.el (bugfixes and new features).
Not quite, the 'modified version' is actually a clone of the gnus git
repo.
Post by Tassilo Horn
What do you want to change exactly? Oftentimes, a simple advice will do
without having to override the complete function.
What's an advice (in this context)? I am interested in fixing/working
around https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21071.
Post by Tassilo Horn
Post by Adam Sjøgren
I'm sure somebody with more hardcore knowledge than me will jump in;
just a guess: could it be a byte compiled file (.elc) that is being
picked up?
Indeed, if Nikolaus copied both gnus-sum.el and gnus-sum.elc into his
other directory, then modified gnus-sum.el but didn't recompile it, and
additionally `load-prefer-newer' is nil, that would explain the issue.
Thanks, that was it! I was assuming that Emacs would automatically
ignore the .elc file if the .el file was newer.

Best,
-Nikolaus
--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

»Time flies like an arrow, fruit flies like a Banana.«
Tassilo Horn
2015-10-15 19:16:38 UTC
Permalink
Post by Nikolaus Rath
Post by Tassilo Horn
What is happening here? Why does the help refer me to the modified
version, but the version in memory is actually the original one? And
how do I tell emacs/gnus to use my version?
Why do you copy the complete gnus-sum.el when you just want to
change one function? As a result, you won't see any future changes of
gnus-sum.el (bugfixes and new features).
Not quite, the 'modified version' is actually a clone of the gnus git
repo.
Ah, I see. Well, then I'd just use the complete git version if I were
you.
Post by Nikolaus Rath
Post by Tassilo Horn
What do you want to change exactly? Oftentimes, a simple advice will
do without having to override the complete function.
What's an advice (in this context)?
An advice is a function which is run before, after, instead of, or
"around" some other function. See (info "(elisp)Advising Functions").
Post by Nikolaus Rath
Post by Tassilo Horn
Indeed, if Nikolaus copied both gnus-sum.el and gnus-sum.elc into his
other directory, then modified gnus-sum.el but didn't recompile it, and
additionally `load-prefer-newer' is nil, that would explain the issue.
Thanks, that was it!
Wow, my crystal ball is working perfectly today! :-)
Post by Nikolaus Rath
I was assuming that Emacs would automatically ignore the .elc file if
the .el file was newer.
It doesn't do so probably for backwards compatibility reasons. But
there's the new variable `load-prefer-newer' for controlling that
behavior.

Bye,
Tassilo
Nikolaus Rath
2015-10-15 23:27:47 UTC
Permalink
Post by Tassilo Horn
Post by Nikolaus Rath
Post by Tassilo Horn
What is happening here? Why does the help refer me to the modified
version, but the version in memory is actually the original one? And
how do I tell emacs/gnus to use my version?
Why do you copy the complete gnus-sum.el when you just want to
change one function? As a result, you won't see any future changes of
gnus-sum.el (bugfixes and new features).
Not quite, the 'modified version' is actually a clone of the gnus git
repo.
Ah, I see. Well, then I'd just use the complete git version if I were
you.
That's what I'm trying to do. Isn't putting the lisp/ directory from the
git clone sufficient to achieve that?
Post by Tassilo Horn
Post by Nikolaus Rath
Post by Tassilo Horn
What do you want to change exactly? Oftentimes, a simple advice will
do without having to override the complete function.
What's an advice (in this context)?
An advice is a function which is run before, after, instead of, or
"around" some other function. See (info "(elisp)Advising Functions").
Uh, that's pretty cool. It seems I need to do some reading.


Best,
-Nikolaus
--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

»Time flies like an arrow, fruit flies like a Banana.«
Tassilo Horn
2015-10-16 07:19:03 UTC
Permalink
Post by Nikolaus Rath
Post by Tassilo Horn
Ah, I see. Well, then I'd just use the complete git version if I
were you.
That's what I'm trying to do. Isn't putting the lisp/ directory from
the git clone sufficient to achieve that?
Ah, sorry, I had understood that you are trying to use the Gnus version
that comes with Emacs but with the gnus-sum.el that comes with Gnus' git
version.

I also run the Git version of Gnus, and that's what you need to do:

Once: clone the git repo && ./configure && make
Regularly: git pull && make

And in my ~/.emacs there is

(add-to-list 'load-path "~/Repos/el/gnus/lisp")
(add-to-list 'Info-directory-list "~/Repos/el/gnus/texi")
(require 'gnus-load)

which you have to adapt to your Gnus checkout directory accordingly.
Post by Nikolaus Rath
Post by Tassilo Horn
Post by Nikolaus Rath
Post by Tassilo Horn
What do you want to change exactly? Oftentimes, a simple advice
will do without having to override the complete function.
What's an advice (in this context)?
An advice is a function which is run before, after, instead of, or
"around" some other function. See (info "(elisp)Advising
Functions").
Uh, that's pretty cool. It seems I need to do some reading.
Yes, it is. However, in the current case you could only use

(advice-add 'gnus-summary-exit :override
#'your-version-of-gnus-summary-exit)

which would override the normal version with your patched version. I
guess in this situation, it is better to apply your patch to the git
version, run it for some time, and then report back to the bug report
that nothing breaks (if nothing breaks, of course). Then someone will
hopefully commit it to Gnus. If nobody reacts, feel free to ping me, I
have push access.

Bye,
Tassilo

Emanuel Berg
2015-10-15 20:17:12 UTC
Permalink
Post by Nikolaus Rath
What's an advice (in this context)?
An advice can be a lot of things, in the Emacs
context, but in the context of your issue, I suspect
the person who gave the piece of advice to use an
advice, he suspected that you want something to always
happen say, before or after the invocation of the
regular function.

This can be done with advices. Here is an example that
I use, which isn't complicated to figure out what
it does:

(advice-add 'gnus-summary-insert-old-articles :after
(lambda (dummy) (gnus-apply-kill-file)))

Typically, advices are used when you don't want any
major and complicated changes to a function. (But
there are many thing that can be done with them.)

However, just because they can be done doesn't mean
that is the best way, and always so. Indeed, sometimes
it is better to redefine the function as you did.

However, in my experience the *best* way to do it is
to write a brand new function - use the existing code
if need be, but do everything new - that way, no
collisions, the help is intact, etc. But the best
advantage to this method is security. Because say you
invoke function F at situation S. It doesn't do
exactly what you want. So you change F and all is well
- *at S*! But often F is used in other situations, and
even by other software which you are unaware of.
So instead, copy and edit F into F', and at S, change
the keybinding that previously invoked F, so that it
now invokes F'!
--
underground experts united
http://user.it.uu.se/~embe8573
Loading...