summaryrefslogtreecommitdiff
path: root/common.el
diff options
context:
space:
mode:
Diffstat (limited to 'common.el')
-rw-r--r--common.el93
1 files changed, 93 insertions, 0 deletions
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))