Skip to content

Commit

Permalink
Remove el-patch-validation
Browse files Browse the repository at this point in the history
This is too hard to get right. If patches are lazy-loaded, or applied
dynamically, or several times...
  • Loading branch information
raxod502 committed Jan 3, 2017
1 parent 5ce04df commit 1ede6d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 61 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ Using `quelpa-use-package`:
(use-package el-patch
:ensure t
:demand t
:quelpa (el-patch :fetcher github :repo "raxod502/el-patch")
:config (el-patch-disable-validation-during-init))
:quelpa (el-patch :fetcher github :repo "raxod502/el-patch"))

Manually:

$ git clone https://github.com/raxod502/el-patch.git

(add-to-list 'load-path "/path/to/el-patch")
(require 'el-patch)
(el-patch-disable-validation-during-init)

`el-patch` is not yet hosted on MELPA. If you love `el-patch`, feel
free to open a pull request on MELPA to add it.
Expand Down Expand Up @@ -252,20 +250,6 @@ el-patch-ediff-conflict`.
You can validate all the patches that have been defined so far using
`M-x el-patch-validate-all`.

In addition to this, patches are validated automatically right after
they are defined if the variable `el-patch-validation` is non-nil. It
doesn't make a whole lot of sense to run validation all the time,
since it's only really necessary when you upgrade Emacs or your
packages, and it slows down Emacs startup.

It is therefore recommended that you call
`el-patch-disable-validation-during-init` before you define any
patches. This function disables `el-patch-validation` during Emacs
startup and then re-enables it once startup is complete.

If you have a function for reloading your init-file, you may want to
wrap the call to `load` in `(let ((el-patch-validation nil)) ...)`.

## Removing patches

Use `M-x el-patch-unpatch`.
Expand Down
59 changes: 15 additions & 44 deletions el-patch.el
Original file line number Diff line number Diff line change
Expand Up @@ -302,33 +302,6 @@ See `el-patch-validate'."
(message "%d patches are valid, %d patches are invalid"
(- patch-count warning-count) warning-count)))))

(defvar el-patch-validation t
"Whether or not to perform validation when a patch is defined.
If non-nil, then evaluating an `el-patch-defun' or
`el-patch-defmacro' form will automatically call
`el-patch-validate', and will only install the patch if it
is still valid.
Validation is slow and can generate messages, so it is
recommended that you set this variable to nil during Emacs
startup, and then set it back to t afterwards. This can be done
by calling the function `el-patch-disable-validation-during-init'
in your init-file.")

(defun el-patch--reenable-validation-after-init ()
"Enable `el-patch-validation'.
Also remove this function from `after-init-hook'."
(setq el-patch-validation t)
(remove-hook 'after-init-hook #'el-patch--reenable-validation-after-init))

;;;###autoload
(defun el-patch-disable-validation-during-init ()
"Disable `el-patch-validation' temporarily during Emacs startup.
Precisely, set it to nil and then set it to t when
`after-init-hook' runs."
(setq el-patch-validation nil)
(add-hook 'after-init-hook #'el-patch--reenable-validation-after-init))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Applying patches

Expand Down Expand Up @@ -379,23 +352,21 @@ 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)))
(when (or (not el-patch-validation)
(el-patch-validate patch-definition))
(puthash function-name patch-definition el-patch--patches)
(setq el-patch--feature nil)
(eval (el-patch--function-to-advice
(el-patch--resolve-definition patch-definition t)))
;; FIXME should not require `el-patch-feature' directive if the
;; function is autoloaded
(unless (and (fboundp function-name)
(not (autoloadp (symbol-function function-name))))
(unless el-patch--feature
(error "You must specify an `el-patch-feature' directive for `%S'"
function-name))
(el-patch--stealthy-defun
function-name
(el-patch--autoload-function function-name el-patch--feature)))
(advice-add function-name :override advice-name))))
(puthash function-name patch-definition el-patch--patches)
(setq el-patch--feature nil)
(eval (el-patch--function-to-advice
(el-patch--resolve-definition patch-definition t)))
;; FIXME should not require `el-patch-feature' directive if the
;; function is autoloaded
(unless (and (fboundp function-name)
(not (autoloadp (symbol-function function-name))))
(unless el-patch--feature
(error "You must specify an `el-patch-feature' directive for `%S'"
function-name))
(el-patch--stealthy-defun
function-name
(el-patch--autoload-function function-name el-patch--feature)))
(advice-add function-name :override advice-name)))

;;;###autoload
(defmacro el-patch-defun (&rest args)
Expand Down

0 comments on commit 1ede6d8

Please sign in to comment.