34

我经常发现自己在完成一些杀戮后反复拉动某些东西,它变成了一个过程,例如:

  1. 赛我
  2. 赛我我的
  3. 赛我我我的

每次我杀死一些文本时,它都会将第一个杀死推回到杀死环中,这样我就需要循环遍历所有的杀死来返回我想要拉出的文本。我想要做的是反复拉动相同的文本,同时在拉动之间杀死文本。这可能吗?

4

8 回答 8

21

不要使用杀戮戒指;而是将文本放入寄存器。 C-x r s a将区域的文本存储到(比如说)寄存器“a”中;然后C-x r i a将其插入其他地方。

于 2011-04-28T20:04:32.850 回答
20

这是一个奇怪的技巧,但可能会有所帮助。

第一次使用M-y时通常会出现错误(之前没有 yank)。所以这个想法是,这是你第一次得到最后一次猛拉而不是最后一次杀戮。

为了存储最后一个 yank,我在本例中使用了“Y”寄存器。

这两个函数将围绕 yank 和 yank-pop。你期待错误,我期待建议。

(defun jp/yank (&optional arg)
  "Yank and save text to register Y"
  (interactive)
  (set-register ?Y (current-kill 0 t))
  (yank arg))

(defun jp/yank-pop (&optional arg)
  "If yank-pop fails, then insert register Y"
  (interactive)
  (condition-case nil
      (yank-pop arg)
    (error (insert (get-register ?Y)))))

(global-set-key (kbd "M-y") (quote jp/yank-pop))
(global-set-key (kbd "C-y") (quote jp/yank))
于 2011-04-28T21:05:10.850 回答
5

您可以M-x delete-region改为使用来杀死文本,如果您想经常使用它,可能会将其绑定到一个键。

于 2011-04-28T18:50:08.373 回答
4
  1. 如果要重复拉动相同的文本,请使用辅助选择而不是区域或终止文本。

    vanilla Emacs 中缺少的是用于拉出二级选择的键绑定。我用C-M-y它(见图书馆second-sel.el)。

  2. 直接访问杀戮环中的任何杀戮,请M-yBrowse Kill RingIcicles一起使用。在这两种情况下,M-y在顶层都可以让您访问 kill ring 中的所有条目。

    如果你使用图书馆second-sel.el,那么除了杀戮戒指之外,你还可以访问你过去的次要选择的戒指。

    如果您使用库second-sel.el冰柱,则从M-y您上次从中拉出的环(杀死环或二级选择环)中拉出一个条目。

    如果您使用 library browse-kill-ring+.el,那么 kill-ring 浏览器还可以让您访问替代环(默认情况下,如果您使用 library ,它是辅助选择环second-sel.el)。

于 2014-07-27T17:46:19.923 回答
2

我会尝试更多地使用 delete-region,但我更了解 kill 命令。一个不需要编程或预先计划的技巧是在一个特别烦人的 My 字符串之后使用 Mw。这会将最终猛拉的更易于访问的副本放入杀伤环。

于 2013-11-27T18:14:58.213 回答
2

更好的 Yank-Pop 实现

这定义了一个更好的 yank-pop 实现,它试图解决不断增加的 yank-pop 问题。

它只覆盖函数“current-kill”。由于 yank、yank-pop 和 Emacs 中的 kill ring 变量和函数的模块化设计,事实证明覆盖“current-kill”是获得我们想要的行为所必需的。

期望的行为是 (1) 杀死某物仍将其放在杀伤环的前面,但现在 (2) 拉动或 yank-popping 某些东西也将它放在杀伤环的前面 (3) 我们保留了以下能力yank-pop 通过增加一个全局变量并使用它来将最后一个 yank-pop'ped 项目替换回原来的位置,从而呈现出穿过杀戮环的外观。这也意味着 (4) 过渡性 yank 的项目(即由 yank 或 yank-pop 命令放置的项目,其中下一个命令是 yank-pop)最终将停留在它们在 kill ring 中的位置。

;; Example:
;; (setq kill-ring '("a" "b" "c" "d" "e"))
;;
;; keystroke        kill ring contents              value of kill-ring-yank-index
;; C-y              ("a" "b" "c" "d" "e")           0
;; M-y              ("b" "a" "c" "d" "e")           1
;; M-y              ("c" "a" "b" "d" "e")           2
;; M-y              ("d" "a" "b" "c" "e")           3

;; C-y              ("d" "a" "b" "c" "e")           0
;; M-y              ("a" "d" "b" "c" "e")           1

;; M-d              ("x" "a" "d" "b" "c" "e")
;; etc.

编码:

;; ----------------------------------------------------------------
;; helper functions

(defun list-insert-before (l n x)
  (if (<= n 0) (cons x l)
    (cons (car l) (list-insert-before (cdr l) (- n 1) x))))

(defun list-prepend-nth (l n)
  (if (<= n 0) l
    (let* ((lx (list-prepend-nth (cdr l) (- n 1))))
      (cons (car lx) (cons (car l) (cdr lx))))))

(defun list-insert-car-at (l n)
  (list-insert-before (cdr l) n (car l)))


;; ----------------------------------------------------------------
;; overriding current-kill

(defvar kill-ring-yank-index 0
  "Index into kill-ring of last yank-pop. The item yank-popped
  will be at the head of the kill ring, but if the next command
  is also yank-pop, it will be returned here first before this
  variable is incremented.")

(defun current-kill (n)
  "Replaces standard 'current-kill' function. This version tries
to fix the increasing yank-pop problem.

TODO:
- respect second argument of original function
- deal with 'interprogram-{cut,paste}-function'
"
  (if (eq 0 n) ;; looks like we're doing a yank; reset
               ;; kill-ring-yank-index to 0 to indicate that the
               ;; current head of the list is useful to the user
      (progn (setq kill-ring-yank-index 0)
             (car kill-ring))

    ;; otherwise put the head of kill-ring back where we had
    ;; previously found it, and fetch the next element
    (setq kill-ring
        (list-insert-car-at kill-ring kill-ring-yank-index))
    (setq kill-ring-yank-index (+ kill-ring-yank-index n))
    (when (>= kill-ring-yank-index (- (length kill-ring) 1))
      (setq kill-ring-yank-index (- (length kill-ring) 1))
      (message "Reached end of kill-ring"))
    (when (< kill-ring-yank-index 0)
      (setq kill-ring-yank-index 0)
      (message "Reached beginning of kill-ring"))
    (setq kill-ring (list-prepend-nth kill-ring kill-ring-yank-index))
    (car kill-ring)))

;; ----------------------------------------------------------------
;; new key binding

;; Here's an auxiliary function and key binding that makes it easy to
;; go back and forth in the kill-ring while we're yank-popping
(defun yank-pop-back () "" (interactive "*")
       (yank-pop -1))

(global-set-key "\C-\M-y" 'yank-pop-back)
于 2015-08-06T23:47:28.543 回答
1

我正在尝试使用次要模式进行破解。让我们称之为delete-mode. 一旦你进入删除模式,杀戮命令(kill-line, kill-paragraph, kill-word, ...)将改变它们的行为,这样它们的kill-region部分命令将被替换delete-region,并且新的材料不会被添加到杀戮环中。在此模式下,杀伤环将保持不变。当您退出此模式时,行为会恢复正常。

以下是尝试实现我上面写的内容的不完整代码。它在切换到删除模式时可以正常工作,但在切换回来(关闭次要模式)时出现问题。任何解决此问题的帮助将不胜感激。

(defvar delete-mode nil)

(defun delete-mode ()
    "delete minor-mode"
    (interactive)
    (setq delete-mode (not delete-mode))
    (if delete-mode
        (defalias 'kill-region 'delete-region)
        (defalias 'kill-region 'original-kill-region)
    )
)

(if (not (assq 'delete-mode minor-mode-alist))
    (setq minor-mode-alist
        (cons '(delete-mode "Delete mode on") minor-mode-alist)
    )
    (defalias 'original-kill-region 'kill-region)
)
于 2011-04-29T01:55:51.490 回答
0

我用

Mx 浏览杀死环

使用键绑定“我的”。还有掌舵支持。

https://www.emacswiki.org/emacs/BrowseKillRing

提供更多解决方案。

于 2017-12-27T14:58:41.457 回答