2009-11-24 71 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