2009-11-24 70 views
1

我想将文本从一个缓冲区复制到另一个文本属性。所以我有设置文本属性

(with-current-buffer from-buffer 
    (setq text-to-copy (buffer-substring beg end))) 

如何插入文本到副本到所有文本属性的另一个缓冲区?我特别感兴趣的是'脸部'属性。

功能缓冲子返回一个列表,例如("substring" 42 51 (face font-lock-keyword-face) 52 59 (face font-lock-function-name-face))

如果我通过这个列表(insert text-to-copy)它似乎忽略文本属性

回答

2

如果font-lock-mode在插入的目标缓冲区被打开,一旦创建开始,面部特性将被重置。我认为您需要关闭font-lock-mode,或者在插入之前使用'font-lock-face'替换'face'的文本属性。

+0

是的,它是字体锁定模式。非常感谢! – 2009-11-24 15:22:19

0

的“insert”功能应该处理字符串文本的包括:属性,原样。由于buffer-substring默认情况下会返回带有文本属性的字符串(如果存在),因此应该只需'(insert text-to-copy)'。

如果在另一方面,你想提取字符串文本的属性,你会想使用buffer-substring-no-properties代替

+0

感谢您的回答。看起来(插入)不考虑文本属性。他们在(插入) – 2009-11-24 14:26:22

+0

的文档中也提到了这一点,我刚刚检查过,你是对的......但是我在回答的基础是elisp手册中对文本属性的评论(我之后记得只是在昨天阅读它,以处理我正在做的事情中的文本属性): “在字符串和缓冲区之间复制文本会保留属性以及字符;这包括诸如substring,insert和buffer-substring之类的各种函数。 “ 因此,奇怪的,冲突的信息... 我想剩下的唯一选择是用'get-text-property'和'set-text-property'迭代结果 - 虽然 – NikkiA 2009-11-24 16:12:07

0

这应该工作。这是Emacs的23.1.1:

buffer-substring is a built-in function in `C source code'. 

(buffer-substring start end) 

Return the contents of part of the current buffer as a string. 
The two arguments start and end are character positions; 
they can be in either order. 
The string returned is multibyte if the buffer is multibyte. 

This function copies the text properties of that part of the buffer 
into the result string; if you don't want the text properties, 
use `buffer-substring-no-properties' instead. 

您可以使用命令describe-text-properties交互,看看它是什么,你实际上得到:

describe-text-properties is an interactive compiled Lisp function in 
`descr-text.el'. 

It is bound to <C-down-mouse-2> <dp>, <menu-bar> <edit> <props> <dp>. 
(describe-text-properties pos &optional output-buffer) 

Describe widgets, buttons, overlays and text properties at pos. 
Interactively, describe them for the character after point. 
If optional second argument output-buffer is non-nil, 
insert the output into that buffer, and don't initialize or clear it 
otherwise. 
+0

我需要将从(buffer-substring)返回的文本属性应用于插入的文本 – 2009-11-24 14:23:54