我有以下功能打印,其中一點是在*刮*緩衝區行,只打印文本丟棄文本屬性
(defun print-line()
(print (thing-at-point 'line) (get-buffer "*scratch*")))
但它打印即使這樣
#(" OFFICE
" 0 2 (fontified t org ...
的fontified信息
如何丟棄構建信息的打印。
我有以下功能打印,其中一點是在*刮*緩衝區行,只打印文本丟棄文本屬性
(defun print-line()
(print (thing-at-point 'line) (get-buffer "*scratch*")))
但它打印即使這樣
#(" OFFICE
" 0 2 (fontified t org ...
的fontified信息
如何丟棄構建信息的打印。
從org-table處理字符串時,我需要類似eredis的東西。顯示字符串時,您可以使用`set-text-properties'來擺脫它們。
(defun strip-text-properties(txt)
(set-text-properties 0 (length txt) nil txt)
txt)
(defun print-line()
(print (strip-text-properties
(thing-at-point 'line))
(get-buffer "*scratch*")))
我試過一些東西,但它很奇怪,我不太瞭解文本屬性是如何工作的。
例如:
(type-of (thing-at-point 'line)) => string
彷彿一個嘗試打印,性能都印好,但如果試圖將其插入到你說:
(insert (format "%s" (thing-at-point 'line)))
只有字符串被打印,而不是屬性。
所以,在我看來,這些屬性只是綁定到字符串,但您可以處理字符串和往常一樣:
(lenght (thing-at-point 'line))
(substring (thing-at-point 'line) 0 2)
但是,如果你想要的是行的,只有行即可使用buffer-substring-no-properties
:
(defun print-line()
(print (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
爲了擴展的buffer-substring-no-properties
Daimrod的提...
的Mxapropos
RETno-properties
RET
buffer-substring-no-properties
Function: Return the characters of part of the buffer, without the
text properties.
field-string-no-properties
Function: Return the contents of the field around POS, without text
properties.
insert-buffer-substring-no-properties
Function: Insert before point a substring of BUFFER, without text
properties.
match-string-no-properties
Function: Return string of text matched by last search, without text
properties.
minibuffer-contents-no-properties
Function: Return the user input in a minibuffer as a string, without
text-properties.
substring-no-properties
Function: Return a substring of STRING, without text properties.
您可以在手冊中讀到文本屬性:
M-:(信息 「(elisp的)文本屬性」)RET
即使緩衝區字符串打印未形成消息,buffer-substring-no-properties打印沒有形成消息。 –
@Talespin_Kit:哦,你是完全正確的。 – Daimrod