Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make el-patch-get use the only variant by default #67

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog].

## Unreleased
### Enhancements
* `el-patch-get` will try and return the only variant of a function
when you don't provide a specific `variant`. This makes it so that
you can call functions such as `el-patch-validate` non-interactively
without providing `variant`.

## 3.0 (released 2022-04-17)
### Breaking changes
* The arguments to `el-patch-feature` after the feature name are no
Expand Down
24 changes: 20 additions & 4 deletions el-patch.el
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,26 @@ and TYPE is a symbol `defun', `defmacro', etc. If the patch could
not be found, return nil.

If VARIANT is provided, select that variant of the patch. This is
useful only if patches were defined using `el-patch-variant'."
(condition-case nil
(gethash variant (gethash type (gethash name el-patch--patches)))
(error nil)))
useful only if patches were defined using `el-patch-variant'. If
VARIANT is not provided and more than one variant is present for
the patch, `wrong-type-argument' is signaled."
(let* ((types (gethash name el-patch--patches))
(variants (and types (gethash type types))))
(cond
((not variants)
nil)
(variant
(gethash variant variants))
(t
(let (only-value)
(maphash (lambda (_ value)
(when only-value
(error 'wrong-type-argument
"Must choose a variant for `%s' type %s."
name type))
(setq only-value value))
variants)
only-value)))))

(defun el-patch--select-patch ()
"Use `completing-read' to select a patched function.
Expand Down