1

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

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

如何将要复制的文本插入具有所有文本属性的另一个缓冲区?我对“面子”属性特别感兴趣。

函数 buffer-substring 返回一个列表,例如("substring" 42 51 (face font-lock-keyword-face) 52 59 (face font-lock-function-name-face))

如果我将此列表传递给(insert text-to-copy)它似乎会忽略文本属性

4

3 回答 3

2

如果font-lock-mode在插入的目标缓冲区中打开,则一旦字体化启动,face 属性将被重置。我认为您需要关闭font-lock-mode或调整文本属性以将 'face' 替换为 'font-lock-插入前面对'。

于 2009-11-24T14:58:37.727 回答
0

' insert' 函数应按原样处理包含文本属性的字符串。由于buffer-substring默认情况下将返回一个带有文本属性的字符串(如果存在),(insert text-to-copy)因此您需要做的就是 ' '。

另一方面,如果你想提取没有文本属性的字符串,你会想buffer-substring-no-properties改用

于 2009-11-24T14:07:32.087 回答
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.
于 2009-11-24T14:08:09.417 回答