如何在Emacs中进行复制粘贴而不使用源字体锁定?

5
当你从一个缓冲区复制文本到另一个缓冲区(M-w 和 C-y),它会将带有语法高亮的文本一并复制,当你粘贴时,它会在新的缓冲区中以原来缓冲区的颜色显示。是否可能更改此设置,使其使用新的缓冲区的字体显示?
3个回答

8

请查看用户选项yank-excluded-propertiesyank-handled-properties的文档。并从yank的文档开始:C-h f yank。它会告诉您:

When this command inserts text into the buffer, it honors the
`yank-handled-properties' and `yank-excluded-properties'
variables, and the `yank-handler' text property.  See
`insert-for-yank-1' for details.

只需要告诉 yank 不要粘贴属性,如facefont-lock-face

另请参阅Elisp手册,节点Yanking


我已经添加了(add-to-list 'yank-excluded-properties 'font)(add-to-list 'yank-excluded-properties 'font-lock-face),但是当我从某些源代码中粘贴到基本模式时,仍然有颜色。 - jcubic
另外,在Emacs 24.2中我没有“yank-handled-properties”的文档。 - jcubic

2

我发现(set-text-properties (point) (mark) nil)会删除所选区域的颜色。

我还想移除只读属性,但我不知道如何做。 (抱歉这是我的问题。)


-1

在你的设置中使用以下内容:

(global-set-key (kbd "C-x C-r") (lambda()(interactive)(revert-buffer nil t)))

你需要执行 C-x C-s C-x C-r


我觉得你把问题搞错了。我是在询问关于字体高亮的事情。 - jcubic
这是正确的答案。你试过了吗? - abo-abo
如果我不想保存文件怎么办?它会将文件恢复到之前的状态,所有我没有保存的更改都会消失。 - jcubic
这就是为什么你要保存并还原的原因。我从来没有见过保存会成为问题。你可以尝试使用 font-lock-fontify-buffer,也许那正是你想要的。 - abo-abo
在GNU Emacs 24.3.1中,还原缓冲区不会删除字体锁定 - 或者至少不会将文本颜色恢复为默认值。 - Jamborino

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接