summaryrefslogtreecommitdiff
path: root/lisp/yank-media.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2021-11-07 00:18:02 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-11-07 00:18:02 +0100
commitcadf325575b35bf630a3e5eefa6b6f60809f8589 (patch)
tree2e6a4a617a4e1bca6874ad231e5b453842db0684 /lisp/yank-media.el
parent465cb1fff12b26059896bf8e2057d06a61bc7339 (diff)
downloademacs-cadf325575b35bf630a3e5eefa6b6f60809f8589.tar.gz
emacs-cadf325575b35bf630a3e5eefa6b6f60809f8589.tar.bz2
emacs-cadf325575b35bf630a3e5eefa6b6f60809f8589.zip
Fix yank-media logic when there's several handlers
* lisp/yank-media.el (yank-media): Fix logic when there's several different handler functions.
Diffstat (limited to 'lisp/yank-media.el')
-rw-r--r--lisp/yank-media.el34
1 files changed, 18 insertions, 16 deletions
diff --git a/lisp/yank-media.el b/lisp/yank-media.el
index aba0fdc2bfb..cafc198be85 100644
--- a/lisp/yank-media.el
+++ b/lisp/yank-media.el
@@ -37,24 +37,26 @@ the `register-yank-media-handler' mechanism."
(interactive)
(unless yank-media--registered-handlers
(user-error "The `%s' mode hasn't registered any handlers" major-mode))
- (catch 'found
+ (let ((all-types nil))
(pcase-dolist (`(,handled-type . ,handler)
yank-media--registered-handlers)
- (when-let ((types (yank-media--find-matching-media handled-type)))
- ;; We have a handler in the current buffer; if there's just
- ;; matching type, just call the handler.
- (if (length= types 1)
- (funcall handler (car types)
- (yank-media--get-selection (car types)))
- ;; More than one type the user for what type to insert.
- (let ((type
- (intern
- (completing-read "Several types available, choose one: "
- types nil t))))
- (funcall handler type (yank-media--get-selection type))))
- (throw 'found nil)))
- (user-error
- "No handler in the current buffer for anything on the clipboard")))
+ (dolist (type (yank-media--find-matching-media handled-type))
+ (push (cons type handler) all-types)))
+ (unless all-types
+ (user-error
+ "No handler in the current buffer for anything on the clipboard"))
+ ;; We have a handler in the current buffer; if there's just
+ ;; matching type, just call the handler.
+ (if (length= all-types 1)
+ (funcall (cdar all-types)
+ (yank-media--get-selection (caar all-types)))
+ ;; More than one type the user for what type to insert.
+ (let ((type
+ (intern
+ (completing-read "Several types available, choose one: "
+ (mapcar #'car all-types) nil t))))
+ (funcall (alist-get type all-types)
+ type (yank-media--get-selection type))))))
(defun yank-media--find-matching-media (handled-type)
(seq-filter