대문 최근에 바뀐 글 새소식 찾기 하우투 문제 제안

BrowseKillRing

최근 편집

요약: Potential problem

추가됨:

> [new]
> The problem with browse-kill-ring is that when my frame is split into two windows, a and b, it will open in b if my focus is on a. When I close it (by pressing ‘q’) b is closed and what I had there is buried (I can select that it won’t close the window it creates, but that’s also not good; I might have just one window initially and I don’t want to end up with two). The ideal behaviour would be similar to bs-mode (open in it’s own small window and close when I press ‘q’ or once I select an entry).
> --user19865


This page is about ways to browse the kill ring, choosing a kill to yank.

Browsing the Kill Ring

In both cases you can clean up the ring selectively during completion, deleting entries on the fly. And you can sort completions in various ways. All Icicles completion features are available, including progressive completion.
       (global-set-key "\C-cy" '(lambda ()
                                 (interactive)
                                 (popup-menu 'yank-menu)))
 (defun konix/kill-ring-insert ()
   (interactive)
   (let (
        (to_insert (completing-read "Yank : "
                                    (delete-duplicates kill-ring :test #'equal)
                                    )
                   )
        )
    (when (and to_insert
               (region-active-p)
               )
      ;; the currently highlighted section is to be replaced by the yank
      (delete-region (region-beginning) (region-end))
      )
    (insert to_insert)
    )
   )

Discussion

I can’t praise browse-kill-ring enough – I don’t use it all that much, but when I need it there’s no replacing it. – Anonymous

Someone once said “The easiest way to invoke kill-ring browsing is just to use ‘M-y’ without first using ‘C-y’”. But when I try that (with Emacs 22) I just get “Previous command was not a yank”.

To get the “M-y immediately pulls up the kill ring” behavior, you need to run M-x browse-kill-ring-default-keybindings. Or, to put this in .emacs

 (require 'browse-kill-ring)
 (browse-kill-ring-default-keybindings)

Not that anyone here will believe me, but I am the NickHurley? referenced above. I can safely say that I have abandoned browse-kill-ring.el (which is now hosted on GitHub: https://github.com/todesschaf/browse-kill-ring for those who are interested). Enjoy.

Here’s a “poor man’s kill-ring-browser”:

    (defun yank-browse (string)
      "Browse the `kill-ring' to choose which entry to yank."
      (interactive
       (minibuffer-with-setup-hook #'minibuffer-completion-help
         (let* ((kills (delete-dups (append kill-ring-yank-pointer kill-ring nil)))
                (entries
                 (mapcar (lambda (string)
                           (let ((pos 0))
                             ;; FIXME: Maybe we should start by removing
                             ;; all properties.
                             (setq string (copy-sequence string))
                             (while (string-match "\n" string pos)
                               ;; FIXME: Maybe completion--insert-strings should
                               ;; do that for us.
                               (put-text-property
                                (match-beginning 0) (match-end 0)
                                'display (eval-when-compile
                                           (propertize "\\n" 'face 'escape-glyph))
                                string)
                               (setq pos (match-end 0)))
                             ;; FIXME: We may use the window-width of the
                             ;; wrong window.
                             (when (>= (* 3 (string-width string))
                                       (* 2 (window-width)))
                               (let ((half (- (/ (window-width) 3) 1)))
                                 ;; FIXME: We're using char-counts rather than
                                 ;; width-count.
                                 (put-text-property
                                  half (- (length string) half)
                                  'display (eval-when-compile
                                             (propertize "……" 'face 'escape-glyph))
                                  string)))
                             string))
                         kills))
                (table (lambda (string pred action)
                         (cond
                          ((eq action 'metadata)
                           '(metadata (category . kill-ring)))
                          (t
                           (complete-with-action action entries string pred))))))
           ;; FIXME: We should return the entry from the kill-ring rather than
           ;; the entry from the completion-table.
           ;; FIXME: substring completion doesn't work well because it only matches
           ;; subtrings before the first \n.
           ;; FIXME: completion--insert-strings assumes that boundaries of
           ;; candidates are obvious enough, but with kill-ring entries this is not
           ;; true, so we'd probably want to display them with «...» around them.
           (list (completing-read "Yank: " table nil t)))))
      (setq this-command 'yank)
      (insert-for-yank string))

I adapted popup-kill-ring to replace a potential previous yank like the default M-y does (yank-pop).

diff --git a/libs/popup-kill-ring.el b/libs/popup-kill-ring.el
--- a/libs/popup-kill-ring.el
+++ b/libs/popup-kill-ring.el
@@ -280,6 +280,8 @@ and `pos-tip.el'"
                                            :scroll-bar t
                                            :isearch popup-kill-ring-isearch))
                    (when item
+                     (when (or (eq last-command 'cua--paste-rectangle) (eq last-command 'yank))
+                       (undo))
                      (setq num (popup-kill-ring-get-index item))
                      (when num
                        (let ((kill-ring-item (nth num kill-ring)))

ArneBab

The problem with browse-kill-ring is that when my frame is split into two windows, a and b, it will open in b if my focus is on a. When I close it (by pressing ‘q’) b is closed and what I had there is buried (I can select that it won’t close the window it creates, but that’s also not good; I might have just one window initially and I don’t want to end up with two). The ideal behaviour would be similar to bs-mode (open in it’s own small window and close when I press ‘q’ or once I select an entry).

--user19865


CategoryEditing