Elilif / emacs-anki-helper

Manage your Anki cards in Emacs.
30 stars 2 forks source link

支持 org 9.7 #5

Closed colawithsauce closed 9 months ago

colawithsauce commented 9 months ago

我最近升级到了 org 9.7,发现 anki-helper 不可用。于是我花了点时间查了一下错,改了一下 anki-helper-fields-get-default 这个函数如下:

(defun anki-helper-fields-get-default ()
  "Default function for get filed info of the current entry."
  (let* ((elt (org-element-at-point))
         (front (org-element-property-2 elt :title))
         (contents-begin (org-element-property-2 elt :contents-begin))
         (robust-begin (or (org-element-property-2 elt :robust-begin)
                           contents-begin))
         (beg (if (or (= contents-begin robust-begin)
                      (= (+ 2 contents-begin) robust-begin))
                  contents-begin
                (1+ robust-begin)))
         (contents-end (org-element-property-2 elt :contents-end))
         (back (buffer-substring-no-properties
                beg (1- contents-end))))
    (list front back)))

由于我没有在 Org 9.6 及以前版本测试过,所以只提出了 issue

colawithsauce commented 9 months ago

报错原因是 Org-mode 9.7 会默认使用 org-element-deferred 来延迟解析。而原本使用的 plist-get 作用于延迟解析的内容的时候,会得到 nil。我把 plist-get 换成了 org-mode 自己的 org-element-property-2 API,就解决了这个问题。

~org-element-at-point~, ~org-element-context~, and
~org-element-at-point-no-context~ may now not calculate all the
property values at the call time.  Instead, the calculation will be
deferred until ~org-element-property~ or the equivalent getter
function is called.  The property names may not all be calculated as
well.

-- https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/etc/ORG-NEWS#n102

colawithsauce commented 9 months ago

把 org-element-property-2 全部改成了 org-element-property 应该没有问题,水个PR :)

Elilif commented 9 months ago

已合并,感谢。