Skip to content

Suggestion: Use advice system for patching functions #60

@haji-ali

Description

@haji-ali

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions