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))))

Edit 2: It turns out there's a cleaner way still.
See: aus.social/@carlozancanaro/116…

Also, there's still something Gmail isn't liking. Looking at the differences in the headers between emacs and my other clients (whose mail does get through), the next most obvious difference is that the Content-Type header doesn't specify an encoding. Whether this is the actual problem or not, I should probably fix that. I'm just working on how.


The usual way to do this would be to "advise" the function with an "around" advice. gnu.org/software/emacs/manual/…

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
in reply to Jonathan Lamothe

elisp help

Sensitive content

in reply to Jonathan Lamothe

No, you can't do that, especially not in elisp.

However there's defadvice sitting just around the corner waiting to help you solve your problem.

See also:

lispworks.com/documentation/lw…
emacsninja.com/posts/a-piece-o…
stackoverflow.com/questions/15…

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