yuchen-lea / org-media-note

Taking interactive notes when watching videos or listening to audios in org-mode.
GNU General Public License v3.0
232 stars 35 forks source link

Play video in ancestor heading (by property inheritance) #37

Closed smartepsh closed 2 years ago

smartepsh commented 2 years ago

环境

需求描述

现状

和 org-ref 配合使用时,当一个 heading 下有 Custom_ID property,org-media-note-mpv-smart-play 可以正确找到视频并自动播放。但如果光标在该 heading 下的子 headings 的时候,则无法自动播放,而是要手动输入视频地址。

期望

在子 headings 下有播放父级 heading 的 Custom_ID 对应的视频的能力。(针对一个视频做个多级笔记应该是个正常需求吧 :joy: )

可能的方案

通过 org-mode property 的继承机制实现。 用户可以通过对 org-use-property-inheritance 进行配置,来达到 property 继承的效果。

所以需要在 org-media-note--current-org-ref-key 中,允许 org-entry-get 查找继承下来的 property 。

(defun org-media-note--current-org-ref-key ()
  "Return the org-ref key of current org entry."
  (org-entry-get (point) org-media-note-ref-key-field 'selective))

问题

设想虽然感觉是 ok 的,但在试验的时候,还是遇到了一些问题…… (不太会 elisp ,见谅……)

我通过使用 # -*- org-use-property-inheritance: '("Custom_ID"); -*- 实现了变量的配置,然后在文件内运行如下代码(通过 source block):

org-use-property-inheritance
;; '("Custom_ID")

(equal '("Custom_ID") org-use-property-inheritance)
;; nil 。期待返回为 t 。

(member-ignore-case "Custom_ID" org-use-property-inheritance)
;; nil 。这里的 org-use-property-inheritance 是 nil 。

(org-entry-get (point) "Custom_ID" 'selective)
;; nil 。期待的方式,会利用用户设置的继承。

(org-entry-get (point) "Custom_ID" t)
;; video_key 。不期待的方式,会强制使用继承。

所以不知道为什么 org-use-property-inheritance 传进方法之后,值就不对了……

yuchen-lea commented 2 years ago

抱歉,最近工作繁忙,再加上整体功能比较稳定,所以好久没来看。

说实话,个人针对视频的多级笔记都是多级列表,没有多级大纲,所以一直没有这个需求😂

在org-entry-get中设置inheritance的思路没问题,但是我觉得不适合把CUSTOM_ID加入到org-use-property-inheritance。属性的继承多为CATEGORY、COLUMNS这样的,ID本身的性质应该是唯一标识,不应该继承。

我加了个新变量org-media-note-use-inheritance,启用后,会向上找到ref key。现在默认启用。更新之后你再试试,应该能满足你的需求。还有问题的话,你再reopen。