在 emacs lisp 中获取字符串类型的第一个元素

问题描述 投票:0回答:1

我正在尝试处理我的小 emacs 帮助程序检索的一些数据。

这就是数据结构的样子:

#("[[id:b6f64bd1-3bf8-4a15-ad50-46bc5d5d1c94][Subsub1]]" 43 50 (fontified nil line-prefix #("**" 0 2 (face org-indent)) wrap-prefix #("***** " 0 2 (face org-indent) 2 6 (face org-indent)) face org-level-1 org-category "dummy")))

我有兴趣获取第一个元素,即字符串

"[[...]]"

让某些函数调查数据,并不能真正揭示其中的技巧:

;; initiailize helper var
(setq dummy  #("[[id:b6f64bd1-3bf8-4a15-ad50-46bc5d5d1c94][Subsub1]]" 43 50 (fontified nil line-prefix #("**" 0 2 (face org-indent)) wrap-prefix #("***** " 0 2 (face org-indent) 2 6 (face org-indent)) face org-level-1 org-category "dummy")))

;; check type
(type-of dummy) ;; => string (for some reason unknown)

;; check length
 (length dummy) ;; => 52 (#o64, #x34, ?4)

;; get substring
(seq-subseq dummy 45 52) ;; => #("bsub1]]" 0 5 (fontified nil line-prefix #("**" 0 2 (face org-indent)) wrap-prefix #("***** " 0 2 (face org-indent) 2 6 (face org-indent)) face org-level-1 org-category "dummy"))

(seq-subseq dummy 50 52) ;; => "]]"

这一切对我来说真的没有意义。从文档中,我假设构造体 `#(..." 确定了一些向量。

但是

(seq-elt dummy 0)
不会返回我正在寻找的字符串。

有人可以提供一些有关此字符串数据类型的提示,甚至提供一些有关如何检索数据结构的第一个元素的指导吗?

谢谢!

emacs lisp elisp
1个回答
1
投票

与 Common Lisp 不同,Emacs Lisp 不使用

#(...)
表示向量,而是使用
[...]

在 Emacs Lisp 中,有一个

#(
字符串语法:

#("characters" property-data...)

看起来您正在检索的数据确实可能是这种形式。有一个关于使用具有文本属性的字符串的手册部分。

我看到有一个

propertize
函数可以将常规字符串转换为具有属性的字符串。

使用

substring-no-properties
函数从中提取纯字符串数据,不带属性。

© www.soinside.com 2019 - 2024. All rights reserved.