summaryrefslogtreecommitdiff
path: root/helm-ring.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thierry.volpiatto@gmail.com>2017-02-23 12:51:18 +0100
committerThierry Volpiatto <thierry.volpiatto@gmail.com>2017-02-23 12:51:18 +0100
commita7e01d435a188841eb52f9d9fa3ffb392572d965 (patch)
tree1245d2b1773a1c2ef3f77476252061dfc856d344 /helm-ring.el
parentc3f70affebfeb783110552c006fab433567e2f81 (diff)
Ensure we don't loose candidate when insertion fails with kill-ring.
* helm-ring.el (helm-kill-ring-action-yank): Do it.
Diffstat (limited to 'helm-ring.el')
-rw-r--r--helm-ring.el58
1 files changed, 30 insertions, 28 deletions
diff --git a/helm-ring.el b/helm-ring.el
index c60b1cd7..20a11fd7 100644
--- a/helm-ring.el
+++ b/helm-ring.el
@@ -142,34 +142,36 @@ Same as `helm-kill-selection-and-quit' called with a prefix arg."
If this action is executed just after `yank',
replace with STR as yanked string."
(with-helm-current-buffer
- (setq kill-ring (delete str kill-ring))
- ;; Adding a `delete-selection' property
- ;; to `helm-kill-ring-action' is not working
- ;; because `this-command' will be `helm-maybe-exit-minibuffer',
- ;; so use this workaround (Issue #1520).
- (when (and (region-active-p) delete-selection-mode)
- (delete-region (region-beginning) (region-end)))
- (if (not (eq (helm-attr 'last-command helm-source-kill-ring) 'yank))
- (insert-for-yank str)
- ;; from `yank-pop'
- (let ((inhibit-read-only t)
- (before (< (point) (mark t))))
- (if before
- (funcall (or yank-undo-function 'delete-region) (point) (mark t))
- (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
- (setq yank-undo-function nil)
- (set-marker (mark-marker) (point) helm-current-buffer)
- (insert-for-yank str)
- ;; Set the window start back where it was in the yank command,
- ;; if possible.
- (set-window-start (selected-window) yank-window-start t)
- (when before
- ;; This is like exchange-point-and-mark, but doesn't activate the mark.
- ;; It is cleaner to avoid activation, even though the command
- ;; loop would deactivate the mark because we inserted text.
- (goto-char (prog1 (mark t)
- (set-marker (mark-marker) (point) helm-current-buffer))))))
- (kill-new str)))
+ (unwind-protect
+ (progn
+ (setq kill-ring (delete str kill-ring))
+ ;; Adding a `delete-selection' property
+ ;; to `helm-kill-ring-action' is not working
+ ;; because `this-command' will be `helm-maybe-exit-minibuffer',
+ ;; so use this workaround (Issue #1520).
+ (when (and (region-active-p) delete-selection-mode)
+ (delete-region (region-beginning) (region-end)))
+ (if (not (eq (helm-attr 'last-command helm-source-kill-ring) 'yank))
+ (insert-for-yank str)
+ ;; from `yank-pop'
+ (let ((inhibit-read-only t)
+ (before (< (point) (mark t))))
+ (if before
+ (funcall (or yank-undo-function 'delete-region) (point) (mark t))
+ (funcall (or yank-undo-function 'delete-region) (mark t) (point)))
+ (setq yank-undo-function nil)
+ (set-marker (mark-marker) (point) helm-current-buffer)
+ (insert-for-yank str)
+ ;; Set the window start back where it was in the yank command,
+ ;; if possible.
+ (set-window-start (selected-window) yank-window-start t)
+ (when before
+ ;; This is like exchange-point-and-mark, but doesn't activate the mark.
+ ;; It is cleaner to avoid activation, even though the command
+ ;; loop would deactivate the mark because we inserted text.
+ (goto-char (prog1 (mark t)
+ (set-marker (mark-marker) (point) helm-current-buffer)))))))
+ (kill-new str))))
(define-obsolete-function-alias 'helm-kill-ring-action 'helm-kill-ring-action-yank "2.4.0")
(defun helm-kill-ring-action-delete (_candidate)