外观
text-props.el
约 679 字大约 2 分钟
2025-10-09
内置函数介绍
下面所有函数参数中可选的 object
可以是 string 或 buffer,nil 表示当前 buffer。
(put-text-property start end prop value &optional object)
给 object 的 start 到 end 范围内的文本设置 prop 属性的值为 value。如果属性已经存在,会用当前值覆盖。
(add-text-properties start end props &optional object)
给 object 的 start 到 end 范围内的文本设置多个属性,props 是 property lists。如果属性已经存在,会用当前值覆盖。
(remove-text-properties start end props &optional object)
移除 object 的 start 到 end 范围内的文本的属性,props 是一个 property lists,但其中属性的值无效。
(remove-list-of-text-properties start end list-of-properties &optional object)
移除 object 的 start 到 end 范围内的文本的属性,list-of-properties 是属性名的列表
(set-text-properties start end props &optional object)
替换 object 的 start 到 end 范围内的文本的属性为 props,props 是一个 property lists。相当于清除掉该范围内的所有属性后重新设置为新的。
(add-face-text-property start end face &optional appendp object)
给 object 的 start 到 end 范围内的文本增加 face 属性,appendp 为 t 是表示追加在后面。该方法不会覆盖 face 中已有的属性,每次执行都会增加一个。
(propertize string &rest properties)
给 string 中每个字符设置 properties 属性,properties 是一个属性列表。已经存在的属性会被覆盖。返回一个设置了属性的新的字符串。
内置函数拓展
- add-face-text-property 有则更新,无则新增
The face property controls the appearance of the character (see Faces). The value of the property can be the following:
A face name (a symbol or string). An anonymous face: a property list of the form (keyword value …), where each keyword is a face attribute name and value is a value for that attribute. A list of faces. Each list element should be either a face name or an anonymous face. This specifies a face which is an aggregate of the attributes of each of the listed faces. Faces occurring earlier in the list have higher priority. A cons cell of the form (foreground-color . color-name) or (background-color . color-name). This specifies the foreground or background color, similar to (:foreground color-name) or (:background color-name). This form is supported for backward compatibility only, and should be avoided. A cons cell of the form (:filtered filter face-spec), that specifies the face given by face-spec, but only if filter matches when the face is used for display. The face-spec can use any of the forms mentioned above. The filter should be of the form (:window param value), which matches for windows whose parameter param is eq to value. If the variable face-filters-always-match is non-nil, all face filters are deemed to have matched. Font Lock mode (see Font Lock Mode) works in most buffers by dynamically updating the face property of characters based on the context.
The add-face-text-property function provides a convenient way to set this text property. See Changing Text Properties.