elisp help

Okay, I need to do a hacky #elisp thing. Yes, I know it's terrible.

Basically, I have an existing defun. Let's call it foo. I need to replace it with a new function that calls the old one and transforms its output before returning it.

I naïvely assumed I could do it like this:

(let ((oldfunc (function foo)))
  (defun foo ()
    (my-transform (funcall oldfunc))))

...but this doesn't actually copy the old function, just a reference to the symbol, so it ends up locking itself in a recursive loop.

I'm sure there's a way to do this.
#AskFedi

Edit: Got it. It's:

(let ((oldfunc (symbol-function 'foo)))
  (defun foo ()
    (my-transform (funcall oldfunc))))

𝚛𝚊𝚝 reshared this.

in reply to Jonathan Lamothe

elisp help

Okay, so I wrote this hacky nonsense in my ~/.emacs.d/init.el, but it doesn't seem to be having any effect. The function in question seems completely unaffected.

Perhaps this code is being evaluated before the original function is defined?

;; Mail hack
(defvar jrl-mail-hack nil
  "Flag to prevent from overloading the function a second time")
(let ((oldfunc (symbol-function 'message-unique-id)))
  (unless jrl-mail-hack
    (defun message-unique-id ()
      (secure-hash 'sha256 (funcall oldfunc)))
    (setq jrl-mail-hack t)))

The idea is to hash the Message-ID header in outgoing mail because Gmail seems to have decided the original format looks like spam.
#emacs #elisp #AskFedi

This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.