              patch-definition))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;; Applying patches
-
-(defun el-patch--advice-name (function-name)
-  "Translate a FUNCTION-NAME into an advice name.
-Return a symbol naming the `:override' advice el-patch will use
-to patch a function called FUNCTION-NAME."
-  (intern (format "el-patch--advice--%S" function-name)))
-
-(defun el-patch--function-to-advice (definition)
-  "Turn a function DEFINITION into an advice definition.
-DEFINITION is a list starting with `defun', `defmacro', etc.
-Return a new definition, a list starting with `defun', that can
-be used to define an `:override' advice."
-  `(defun ,(el-patch--advice-name (cadr definition))
-       ,@(cddr definition)))
-
-(defun el-patch--definition (patch-definition)
-  "Activate a PATCH-DEFINITION.
-PATCH-DEFINITION is a list starting with `defun', `defmacro',
-etc. Update `el-patch--patches', create the advice, and activate
-it."
-  (let* ((function-name (cadr patch-definition))
-         (advice-name (el-patch--advice-name function-name)))
-    (puthash function-name patch-definition el-patch--patches)
-    (eval (el-patch--function-to-advice
-           (el-patch--resolve-definition patch-definition t)))
-    (advice-add function-name :override advice-name)))
-
-;;;###autoload
-(defmacro el-patch-defun (&rest args)
-  "Patch a function. The ARGS are the same as for `defun'."
-  (declare (indent defun))
-  `(el-patch--definition ',(cons 'defun args)))
-
-;;;###autoload
-(defmacro el-patch-defmacro (&rest args)
-  "Patch a macro. The ARGS are the same as for `defmacro'."
-  (declare (indent defun))
-  `(el-patch--definition ',(cons 'defmacro args)))
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;;; Patch directives
-
-;;;###autoload
-(defmacro el-patch-add (&rest args)
-  "Patch directive for inserting forms.
-In the original definition, the ARGS and their containing form
-are removed. In the new definition, the ARGS are spliced into the
-containing s-expression."
-  (declare (indent 0))
-  `(error "Can't use `el-patch-add' outside of an `el-patch'"))
-
-;;;###autoload
-(defmacro el-patch-remove (&rest args)
-  "Patch directive for removing forms.
-In the original definition, the ARGS are spliced into the
-containing s-expression. In the new definition, the ARGS and
-their containing form are removed."
-  (declare (indent 0))
-  `(error "Can't use `el-patch-remove' outside of an `el-patch'"))
-
-;;;###autoload
-(defmacro el-patch-swap (old new)
-  "Patch directive for swapping forms.
-In the original definition, OLD is spliced into the containing
-s-expression. In the new definition, NEW is spliced instead."
-  (declare (indent 0))
-  `(error "Can't use `el-patch-swap' outside of an `el-patch'"))
-
-;;;###autoload
-(defmacro el-patch-wrap (&optional triml trimr args)
-  "Patch directive for wrapping forms.
-TRIML and TRIMR are optional arguments. If only one is provided,
-it is assumed to be TRIML. ARGS is required, and it must be a
-list.
-
-In the original definition, the ARGS are spliced into the
-containing s-expression. If TRIML is provided, the first TRIML of
-the ARGS are removed first. If TRIMR is provided, the last TRIMR
-are also removed. In the new definition, the ARGS and their
-containing list are spliced into the containing s-expression."
-  (declare (indent defun))
-  `(error "Can't use `el-patch-wrap' outside of an `el-patch'"))
-
-;;;###autoload
-(defmacro el-patch-splice (&optional triml trimr args)
-  "Patch directive for splicing forms.
-TRIML and TRIMR are optional arguments. If only one is provided,
-it is assumed to be TRIML. ARGS is required, and it must be a
-list.
-
-In the original definition, the ARGS and their containing list
-are spliced into the containing s-expression. In the new
-definition, the ARGS are spliced into the containing
-s-expression. If TRIML is provided, the first TRIML of the ARGS
-are removed first. If TRIMR is provided, the last TRIMR are also
-removed."
-  (declare (indent defun))
-  `(error "Can't use `el-patch-splice' outside of an `el-patch'"))
-
-;;;###autoload
-(defmacro el-patch-let (varlist arg)
-  "Patch directive for creating local el-patch bindings.
-Creates local bindings according to VARLIST, then resolves to ARG
-in both the original and new definitions. You may bind symbols
-that are also patch directives, but the bindings will not have
-effect if the symbols are used at the beginning of a list (they
-will act as patch directives)."
-  (declare (indent 1))
-  `(error "Can't use `el-patch-let' outside of an `el-patch'"))
-
-;;;###autoload
-(defmacro el-patch-literal (arg)
-  "Patch directive for treating patch directives literally.
-Resolves to ARG, which is not processed further by el-patch."
-  (declare (indent 0))
-  `(error "Can't use `el-patch-literal' outside of an `el-patch'"))
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; Validating patches
 
 (defun el-patch--find-function (name)

     (t
      (message "%d patches are valid, %d patches are invalid"
               (- patch-count warning-count) warning-count)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Viewing patches

             (read defun-buffer))))))

;;;###autoload
(defun el-patch-validate (name)
  "Validate the patch for the function NAME.
This means el-patch will attempt to find the original definition
for the function, and verify that it is the same as the original
function assumed by the patch. A warning will be signaled if the
original definition for a patched function cannot be found, or if
there is a difference between the actual and expected original
definitions.

Returns nil if the patch is not valid, and otherwise returns t.

See also `el-patch-validate-all'."
  (interactive (list (cadr (el-patch--select-patch))))
  (let* ((patch-definition (gethash name el-patch--patches))
         (old-definition (el-patch--resolve-definition
                          patch-definition nil))
         (actual-definition (el-patch--find-function name)))
    (cond
     ((not actual-definition)
      (display-warning
       'el-patch
       (format "Could not find definition of `%S'" name))
      nil)
     ((not (equal old-definition actual-definition))

      (display-warning
       'el-patch
       (format (concat "Definition of `%S' differs from what "
                       "is assumed by its patch")
               name)
       nil)))))

;;;###autoload
(defun el-patch-validate-all ()
  "Validate all currently defined patches.
See `el-patch-validate'."
  (interactive)
  (let ((patch-count 0)
        (warning-count 0))
    (maphash (lambda (name patch-definition)
               (setq patch-count (1+ patch-count))
               (unless (el-patch-validate name)
                 (setq warning-count (1+ warning-count))))
             el-patch--patches)
    (cond
     ((zerop patch-count)
