summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basic.el5
-rw-r--r--common.el93
2 files changed, 98 insertions, 0 deletions
diff --git a/basic.el b/basic.el
index 84c358c..0715aea 100644
--- a/basic.el
+++ b/basic.el
@@ -202,6 +202,11 @@ window, then also delete the selected window."
(define-key global-map (vector (logior (ash 1 27) #x5a)) #'zap-up-to-char)
+;;; Completion enhanced yank
+
+(define-key global-map (vector ?\M-y) #'yank-pop)
+(define-key global-map (vector ?\C-\M-y) #'yank-complete)
+
;;; Repeating pops
;;;###autoload
diff --git a/common.el b/common.el
index 3271da1..ba2c534 100644
--- a/common.el
+++ b/common.el
@@ -153,6 +153,53 @@ ARG means do this command ARG times."
(interactive "p")
(durand-completion-scroll-down-or-go-to-minibuffer (- arg)))
+;;; Use completion to select text that was killed before.
+
+;;;###autoload
+(defun yank-complete-rotated-kill-ring ()
+ "Return the rotated kill ring so that the current kill is at the top."
+ (let* ((tail kill-ring-yank-pointer)
+ (len-tail (length tail))
+ (len (length kill-ring))
+ (copied (copy-tree kill-ring))
+ (head (progn (setcdr (nthcdr (mod (- -1 len-tail)
+ len)
+ copied)
+ nil)
+ copied))
+ ;; Judged from `current-kill', this can be a list for some
+ ;; reason.
+ (interprogram-paste (and interprogram-paste-function
+ (funcall interprogram-paste-function))))
+ (append (cond ((listp interprogram-paste) interprogram-paste)
+ ((stringp interprogram-paste) (list interprogram-paste)))
+ tail head)))
+
+;;;###autoload
+(defvar yank-complete-history nil
+ "The history of `yank-complete'.")
+
+;;;###autoload
+(defun yank-complete (&optional arg)
+ "Use completion to select text that was killed before.
+If ARG is a cons cell, then put the point at the beginning, the
+mark at the end for the first yank."
+ ;; This is largely copied from `yank'.
+ (interactive)
+ (let* ((inhibit-read-only t)
+ (kills (yank-complete-rotated-kill-ring))
+ (choice (completing-read "Yank: " kills nil
+ t nil 'yank-complete-history)))
+ (setq yank-window-start (window-start))
+ (setq this-command t)
+ (push-mark)
+ (insert-for-yank choice)
+ (cond ((consp arg)
+ (goto-char (prog1 (mark t)
+ (set-marker (mark-marker) (point) (current-buffer)))))))
+ (cond ((eq this-command t)
+ (setq this-command 'yank))))
+
;;; Don't ask me if I want to visit the file again.
(require 'register)
@@ -206,3 +253,49 @@ completely hiding it."
+;;; Archives
+
+;; ;;;###autoload
+;; (defvar yank-pop-completion-index 0
+;; "The index of the current kill.")
+
+;; ;;;###autoload
+;; (defun yank-pop-cycle-candidate (&optional arg)
+;; "Cycle the candidates by the offset ARG.
+;; This is intended to be bound in the minibuffer-local-completion-map."
+;; (interactive "p")
+;; (cond ((minibufferp))
+;; ((listp minibuffer-completion-table))
+;; ((error "Function `yank-pop-cycle-candidate' called in a weird place")))
+;; (delete-minibuffer-contents)
+;; (let ((len (length minibuffer-completion-table)))
+;; (setq yank-pop-completion-index (+ arg yank-pop-completion-index))
+;; (insert (nth (mod yank-pop-completion-index len)
+;; minibuffer-completion-table))))
+
+;; ;;;###autoload
+;; (defun yank-pop-completion-previous-candidate (&optional arg)
+;; "Go to the previous ARG candidate.
+;; This is intended to be bound in the minibuffer-local-completion-map."
+;; (interactive "p")
+;; (yank-pop-cycle-candidate (- arg)))
+
+;; ;;;###autoload
+;; (defun yank-pop-completion-set-minibuffer ()
+;; "Set up minibuffer for use of `yank-pop-complete'."
+;; (setq yank-pop-completion-index 0)
+;; (define-key minibuffer-local-completion-map
+;; (vector ?\M-p) #'yank-pop-completion-previous-candidate)
+;; (define-key minibuffer-local-completion-map
+;; (vector ?\M-n) #'yank-pop-cycle-candidate)
+;; (add-hook 'minibuffer-exit-hook #'yank-pop-completion-clear))
+
+;; ;;;###autoload
+;; (defun yank-pop-completion-clear ()
+;; "Clear the traces of `yank-pop-complete'."
+;; (setq yank-pop-completion-index 0)
+;; (define-key minibuffer-local-completion-map
+;; (vector ?\M-p) #'previous-history-element)
+;; (define-key minibuffer-local-completion-map
+;; (vector ?\M-n) #'next-history-element)
+;; (remove-hook 'minibuffer-exit-hook #'yank-pop-completion-clear))