Picking elements from the kill-ring with completing-read

The kill ring is a nice thing to have. Only the navigation is a bit to uncomfortable (I am refering to doing C-y again and again until the to desired element is found). So this is what I came up with to feel more ‚comfy‘:

(defun pre-process-kill-ring-element (element)
  (replace-regexp-in-string "^[[:space:]]+" ""
                            (replace-regexp-in-string "[[:space:]]+$" "" (substring-no-properties element))))
(defun preprocess-kill-ring ()
  (let ((result nil)
        (element nil))
    (dolist (element kill-ring)
        (setq element (pre-process-kill-ring-element element))
        (when (not (or
                    (eq 0 (length element))
                    (string-match-p "[\r\n]+" element)))
          (setq result (cons element result)))))
    (reverse result)))
(defun browse-kill-ring ()
  (insert (completing-read "Pick an element: "
(global-set-key (kbd "C-M-y") 'browse-kill-ring)

5 Kommentare

  1. Interesting idea. I assume that once an element was selected from the `kill-ring`, it would also be inserted, like:

    (defun browse-and-yank-kill-ring (contents)
    (ido-completing-read „Yank: “
    (insert contents))

    (global-set-key (kbd „C-M-y“) ‚browse-and-yank-kill-ring)

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.