在写一个工具的过程中遇到一个plist问题: 我解析了org headline的properties,把它存成一个list(plist),就像这样:
(NAME "hehe" AGE "df") ; 这样应该是一个地道的plist吧?
当然,它是直接被存入一个变量的,就像这样:
(setq a-plist (get-the-plist))
然后,神奇的事情来了:
(plist-get a-plist 'NAME) ; --> nil,竟然是nil。。。
我踩到了什么坑了吗?
以下是具体代码:
(require 'org-element)
(require 'json)
(require 'cl)
(require 'dash)
(defun oh/get-ast (file-path)
(with-temp-buffer
(insert-file-contents file-path)
(org-mode)
(org-element-parse-buffer)))
(defun mistkafka/habitica/get-headline-section-child (child-symbol headline-element)
"获取HEADLINE-ELEMENT的section的child. 合法的CHILD-SYMBOL有:
`planning' `property-drawer' `plain-list' `plain-list' `garagraph'等"
(let ((section-element (->> (org-element-contents headline-element)
(nth 0))))
(if section-element
(alist-get child-symbol section-element)
nil)))
(setq ast (oh/get-ast "./tmp.org"))
(setq a-heading (nth 3 ast))
(setq a-property-drawer (mistkafka/habitica/get-headline-section-child 'property-drawer a-headline))
(setq a-plist (cl-loop for x on a-property-drawer
for y = (car x)
for child-name = (car y)
for child-val = (nth 1 y)
when (equal child-name 'node-property)
collect (make-symbol (plist-get child-val :key))
when (equal child-name 'node-property)
collect (plist-get child-val :value)))
a-plist ; --> (HABITICATE-ID "12843" NAME "dfksd" AGE "323" ADDRESS "fsdf, resdf, rs" LAST_REPEAT "[2018-04-12 Thu 23:35]")
(plist-get a-plist 'NAME) ; --> nil
对应的tmp.org文件的内容是:
#+TITLE: Test
* NEXT learn xxx
DEADLINE: <2018-04-13 Fri +1d>
:PROPERTIES:
:HABITICATE-ID: 12843
:NAME: dfksd
:AGE: 323
:ADDRESS: fsdf, resdf, rs
:LAST_REPEAT: [2018-04-12 Thu 23:35]
:END:
- State "DONE" from "TODO" [2018-04-12 Thu 23:35]
- State "TODO" from "DONE" [2018-04-12 Thu 23:35]
- State "DONE" from "TODO" [2018-04-12 Thu 23:35]
need learn
** TODO learn x1
** TODO learn x2
* DONE use hehe [1/2]
DEADLINE: <2018-04-10 Tue>
:LOGBOOK:
- State "DONE" from "CANCELLED" [2018-03-28 Wed 21:22] \\
asdadf
- State "CANCELLED" from "DONE" [2018-03-28 Wed 21:22] \\
asdfad
- State "DONE" from "TODO" [2018-03-28 Wed 21:22]
:END:
jasd
asdfs
- [X] asdf
- [ ] asdfsdf
- head asdf
- ad asd
* TODO learn yyy
* TODO learn zzz