我只想要 Cw 和 Mw 来修改kill-ring,以及系统的剪贴板[ Cc (copy), Cx (cut)]。
我经常使用 Md 和 M-DEL ,但我不想每次都拉扯然后循环我的。
我在看the emacs manual,但它没有回答我的问题。
示例:我想将 M-d “kill-word”绑定到“delete-word”,但“delete-word”不存在。我怎么做到这一点?任何帮助将不胜感激。
答案 0 :(得分:1)
我认为您要使用delete-region
而不是kill-region
,因此文本不会保存在kill-ring中,例如。
(defun my-delete-word (start)
(interactive "d")
(backward-word)
(delete-region (point) start))
答案 1 :(得分:1)
来自EmacsWiki https://www.emacswiki.org/emacs/BackwardDeleteWord
(defun delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument, do this that many times."
(interactive "p")
(if (use-region-p)
(delete-region (region-beginning) (region-end))
(delete-region (point) (progn (forward-word arg) (point)))))
(defun backward-delete-word (arg)
"Delete characters backward until encountering the end of a word.
With argument, do this that many times."
(interactive "p")
(delete-word (- arg)))
(global-set-key (read-kbd-macro "<M-DEL>") 'backward-delete-word)
答案 2 :(得分:0)
我创建了一个宏来将任何kill命令更改为删除命令。
(defmacro delete-instead-of-kill (&rest body)
"Replaces `kill-region' with `delete-region' in BODY."
`(cl-letf (((symbol-function 'kill-region)
(lambda (beg end &optional region)
;; FIXME: account for region arg
(delete-region beg end))))
,@body))
(defun delete-word (&optional arg)
"Like `kill-word', but deletes instead of killing."
(interactive "p")
(delete-instead-of-kill (kill-word arg)))
我使用类似的宏进行复制。
(defmacro copy-instead-of-kill (&rest body)
"Replaces `kill-region' with `kill-ring-save' in BODY."
`(cl-letf (((symbol-function 'kill-region)
(lambda (beg end &optional region)
(kill-ring-save beg end region)
(setq this-command 'kill-region))))
,@body))