diff options
author | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2017-12-20 11:14:35 +0100 |
---|---|---|
committer | Thierry Volpiatto <thierry.volpiatto@gmail.com> | 2017-12-20 11:14:35 +0100 |
commit | f7f2bd110a0e1d1513b188d86d74bbb8ac60b37d (patch) | |
tree | e4f74c3a021bc8fdfb0a5249563d36a84cd2fd80 /helm-ring.el | |
parent | a32a9645c33a8fc5dfbb6f7b5894e3565a15c76a (diff) |
Honor mark and point in yank-pop
* helm-ring.el (helm-kill-ring-action-yank): Do it.
Diffstat (limited to 'helm-ring.el')
-rw-r--r-- | helm-ring.el | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/helm-ring.el b/helm-ring.el index afa8b928..d3816ea0 100644 --- a/helm-ring.el +++ b/helm-ring.el @@ -147,53 +147,50 @@ When called with a prefix arg, point and mark are exchanged without activating region. If this action is executed just after `yank', replace with STR as yanked string." - (with-helm-current-buffer - (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)) - (progn - ;; Ensure mark is at beginning of inserted text. - (push-mark) - ;; When yanking in a helm minibuffer we need a small - ;; delay to detect the mark in previous minibuffer. [1] - (run-with-timer - 0.01 nil - (lambda () - (insert-for-yank str) - (when helm-current-prefix-arg - ;; Same as exchange-point-and-mark but without - ;; activating region. - (goto-char (prog1 (mark t) - (set-marker (mark-marker) - (point) - helm-current-buffer))))))) + (let ((yank-fn (lambda (&optional before yank-pop) + (with-helm-current-buffer + (insert-for-yank str) + ;; Set the window start back where it was in + ;; the yank command, if possible. + (when yank-pop + (set-window-start (selected-window) yank-window-start t)) + (when (or helm-current-prefix-arg before) + ;; Same as exchange-point-and-mark but without + ;; activating region. + (goto-char (prog1 (mark t) + (set-marker (mark-marker) + (point) + helm-current-buffer)))))))) + (with-helm-current-buffer + (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)) + (progn + ;; Ensure mark is at beginning of inserted text. + (push-mark) + ;; When yanking in a helm minibuffer we need a small + ;; delay to detect the mark in previous minibuffer. [1] + (run-with-timer 0.01 nil yank-fn)) ;; 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))) + (funcall (or yank-undo-function 'delete-region) (mark t) (point))) (setq yank-undo-function nil) (set-marker (mark-marker) (point) helm-current-buffer) - ;; Same as [1] - (run-with-timer 0.01 nil (lambda () (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)))) + ;; Same as [1] but use the same mark and point as in + ;; the initial yank according to BEFORE even if no + ;; prefix arg is given. + (run-with-timer 0.01 nil yank-fn before 'pop)))) + (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) |