When patching a function, I think it might be better (from an Emacs compatibility point of view) to define an advice with :override instead of over-defining the function.
I realize this would only work with functions, and not with other types (?), but since functions are the most patched type this might be worth it.
At the very least, something like this could be suitable
(defmacro el-patch-function (func-name &rest args)
"Patches function FUNC-NAME.
Similar to `el-patch-defun' except the patch is applied as an
`:override' advice."
(let* ((patch-name (make-symbol
(concat (symbol-name func-name) "@el-patch")))
(new-args (cl-list* 'defun `(el-patch-swap ,func-name ,patch-name)
args)))
`(progn
(el-patch--definition ,new-args)
(advice-add (quote ,func-name) :override (quote ,patch-name))
',patch-name)))
(and a similarly defined el-patch-define-function-template).
When patching a function, I think it might be better (from an Emacs compatibility point of view) to define an advice with
:overrideinstead of over-defining the function.I realize this would only work with functions, and not with other types (?), but since functions are the most patched type this might be worth it.
At the very least, something like this could be suitable
(and a similarly defined
el-patch-define-function-template).