0

I am trying to re-define two functions in two-column.el.gz, namely 2C-split and 2C-merge. Both of those are declared with ;;;###autoload. I gathered I should use (eval-after-load "two-column" ...), because Linux (Ubuntu) won't let me change the original file.

I have this eval-after-load body in my .emacs file, more precisely in a settings.org file which I load from the .emacs. I have all my code here. When I do find-function after startup, I am shown this file (inside the eval-after-load bit). But then, when I do C-x 6 s, it's the original function which is called, not mine. And after that find-function sends me to the two-column.el.gz file.

I tried with-eval-after-load, I tried the full file path instead of "two-column", but nothing seems to work. after-load-alist doesn't even show my new functions, unless I specifically load the (eval-after-load ...) with C-x C-e - then there is an entry for it.

My questions are both how to load my functions without having to load the file explicitly (which also didn't quite work, but that's a different problem), and why this is happening. I simply do not understand.

2
  • "after-load-alist doesn't even show my new functions, unless I specifically load the (eval-after-load ...) with C-x C-e" - sounds like your settings.org code is not getting loaded correctly? – npostavs Dec 22 '19 at 17:06
  • @npostavs The problem is everything else seems to be working. I have a log of functions there inside BEGIN_SCR emacs lisp blocks and all work just fine. – Oscar Rosenwald Dec 24 '19 at 10:11
1

It's hard to give a precise answer because you don't show the actual shape of your code, but it's quite possible that the problem is that your code is simply not being evaluated.

I have a side-answer to provide, tho: you might prefer to use advice-add to modify existing functions. This can be done before the function is defined, so no need for eval-after-load or similar and it can still defer to the original definition, which is often very useful:

(advice-add '2C-split :around #'my-2C-split)
(defun my-2C-split (original-definition &optional arg)
  ...)
3
  • I read somewhere that adding advice is the most inefficient solution. Of course, these two functions are very small, so there should be no problems with loading time, but generally speaking, I thought I'd try the proper way. Looking into your suggestion now. Thanks. – Oscar Rosenwald Dec 24 '19 at 10:16
  • Blindly redefining some other package's function is not "the proper way". The only proper way is to change the package's code (upstream). Using an advice is the next best thing. It is a bit less efficient but it's very rarely an issue (and definitely not here). – Stefan Dec 24 '19 at 15:52
  • Thank you. The code works now with the advice, though there were some problems I had initially with having the original function loaded after the advice. – Oscar Rosenwald Dec 25 '19 at 16:29
0

In the end I ended up remapping the key for 2C-split instead. There was a problem with 2C-merge afterwards, as in the 2C-mode, 2C-merge is redefined again, so remapping keys didn't work. I used advice-add as per Stefan's answer to change the behaviour of the original function.

I still don't know what the original problem was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.