当前位置:  开发笔记 > 后端 > 正文

仅打印文本丢弃文本属性

如何解决《仅打印文本丢弃文本属性》经验,为你挑选了2个好方法。

我有以下函数来打印指向*scratch*缓冲区的行,

(defun print-line ()
  (print (thing-at-point 'line) (get-buffer "*scratch*")))

但它甚至打印出像这样的精彩信息

#(" OFFICE
" 0 2 (fontified t org ...

如何丢弃已完成信息的打印.



1> phils..:

扩展Daimrod提到buffer-substring-no-properties......

M-x apropos RET no-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-: (info"(elisp)文字属性") RET



2> justinhj..:

在操作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*")))

推荐阅读
jerry613
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有