org-roam-dailies-goto-today 默认新建 capture

org-roam 2.2.1 版本增加了 org-roam-dailies-capture-today 的方法,增加了 keys 参数 ,具体如下:

;;;###autoload
(defun org-roam-dailies-capture-today (&optional goto keys)
  "Create an entry in the daily-note for today.
When GOTO is non-nil, go the note without creating an entry.

ELisp programs can set KEYS to a string associated with a template.
In this case, interactive selection will be bypassed."
  (interactive "P")
  (org-roam-dailies--capture (current-time) goto keys))

;;;###autoload
(defun org-roam-dailies-goto-today (&optional keys)
  "Find the daily-note for today, creating it if necessary.

ELisp programs can set KEYS to a string associated with a template.
In this case, interactive selection will be bypassed."
  (interactive)
  (org-roam-dailies-capture-today t keys))

我配置的打开的方法:

setq org-roam-dailies-capture-templates
        '(("d" "Daily" entry
           "* %?"
           :target (file+head "%<%Y-%m-%d>.org"
                              "#+title: %<%Y-%m-%d>\n"))
          ("w" "Weekly" entry
           "* TODO %^{Goal} %?"
           :target (file+head "%<%Y-W%W>.org"
                              "#+title: %<%Y-W%W>\n"))
           )

如果向 capture 中传入需要输入的模板,比如 weekly 的模板的时候 调用 org-roam-dailies-goto-today,会默认创建新的 capture ,输入之后,才会自动跳转到对应的 dailies 中,这个有办法关闭吗?

使用 Daily 的配置方式,可以正确的打开到对应的日期,但是增加 %^{Goal} 或者是 %^G 都会触发一次输入。

预期行为,具体请看 org-capture-templates 相关文档:

  %^g         Prompt for tags, with completion on tags in target file.
  %^G         Prompt for tags, with completion on all tags in all agenda files.
  %^t         Like %t, but prompt for date.  Similarly %^T, %^u, %^U.
              You may define a prompt like: %^{Please specify birthday}t.
              The default date is that of %t, see above.
  %^C         Interactive selection of which kill or clip to use.
  %^L         Like %^C, but insert as link.
  %^{prop}p   Prompt the user for a value for property `prop'.
              A default value can be specified like this:
              %^{prop|default}p.
  %^{prompt}  Prompt the user for a string and replace this sequence with it.
              A default value and a completion table can be specified like this:
              %^{prompt|default|completion2|completion3|...}.

恩,我没太明白您说的这个,我理解如果是调用 goto-today 的方法,应该跳过模板这一步,和预期行为无关?现在使用的时候,并没有跳过。

我是说这个是预期的,因为你这样写模板就需要输入

不是特别确定我理解的对不对,你现在有两个模板,在调用 org-roam-dailies-goto-today 并没有指定模板,自然需要选择

选择这步没错,目前配置能正确跳转到选择这一步,现在问题是,调用的 org-roam-dailies-goto-today 方法,必须要输入模板中定义的信息%^T或者是%^G这些,但是我理解,goto-today 的行为应该是跳过创建模板这步的,现在是没有跳过,有办法路过这一步吗?

貌似不太行(我没细看代码,也可以自己去 hack)。这个和 roam 无关,是 (org-capture GOTO KEY) 控制的,即使设置 (org-capture '(4) "KEY") 还是会需要输入模板中的 prompt

我发现我弄错了,可能是 org-roam 传错参数了,org-capture 需要 C-u 才会 gotoorg-roam-dailies-goto-today 传成 t 了。你改成这个试试:

(defun org-roam-dailies-goto-today (&optional keys)
  "Find the daily-note for today, creating it if necessary.

ELisp programs can set KEYS to a string associated with a template.
In this case, interactive selection will be bypassed."
  (interactive)
  (org-roam-dailies-capture-today '(4) keys))

我去测试了一下, org-capture 的内容,也是有相同的问题。

  (setq org-capture-templates
        '(
          ("r" "Reading" entry (file+headline "~/workspace/org/tasks.org" "Reading")
           "* TODO %^{book name}\n%t\n"
           :clock-in t
           :clock-resume t
           :empty-lines 1)
          ("j" "Journal" entry (file+olp+datetree "~/workspace/org/journal.org")
           "* %?\nEntered on %U\n %i\n"
           :empty-lines 1)
           ))

使用 C-u M-x org-capture 可以直接跳转到 Journal,使用 reading 的时候,就还是需要输入 book name 才能跳转过去,可能是我对配置的理解有问题,我把对应的配置再调整一下。

试了你的模板 (org-capture '(4) "r") 或者 C-u M-x org-capture r 可以直接跳转

org-capture 是可以跳转的,但在 org-roam-dailies-capture 不能正确的跳转。

那就说明 org-roam-capture- 处理可能有问题

我想看一下emacs 中使用 org-roam-dailies-goto-today 到 org-roam-capture–fill-template 的调用过程,要怎么踪您清楚吗?

我用 debug-on-entry org-roam-dailies-goto-today 看不到调用的过程。

(defun org-roam-dailies--capture (time &optional goto keys)
  "Capture an entry in a daily-note for TIME, creating it if necessary.
When GOTO is non-nil, go the note without creating an entry.

ELisp programs can set KEYS to a string associated with a template.
In this case, interactive selection will be bypassed."
  (let ((org-roam-directory (expand-file-name org-roam-dailies-directory org-roam-directory))
        (org-roam-dailies-directory "./"))
    (org-roam-capture- :goto (when goto '(4))
                       :keys keys
                       :node (org-roam-node-create)
                       :templates org-roam-dailies-capture-templates
                       :props (list :override-default-time time)))
  (when goto (run-hooks 'org-roam-dailies-find-file-hook)))

跟程序发现这里传入的是 '(4) 的变量,但是在后面调用 org-capture 的时候

(org-capture goto keys)

这里传到 org-capture 里判断的时候 ((equal goto '(4)) (org-capture-goto-target keys)) 结果是 nil 感觉问题就是出在这里,但是没太明白为什么判断的不一样。

我 Debug 比较丑,都是频繁 print

就是要传 '(4)

这两天研究了一下这个方法,是在下面处的问题,我注释掉这段代码就可以正确跳转了。

(defun org-roam-capture--prepare-buffer ()
  "Prepare the capture buffer for the current Org-roam based capture template.
This function will initialize and setup the capture buffer,
position the point to the current :target (and if necessary,
create it if it doesn't exist), and place the point for further
processing by `org-capture'.

Note: During the capture process this function is run by
`org-capture-set-target-location', as a (function ...) based
capture target."
  (let ((id (cond ((run-hook-with-args-until-success 'org-roam-capture-preface-hook))
                  (t (org-roam-capture--setup-target-location)))))
    (org-roam-capture--adjust-point-for-capture-type)
    ;; (let ((template (org-capture-get :template)))
    ;;   (when (stringp template)
    ;;     (org-capture-put
    ;;      :template
    ;;      (org-roam-capture--fill-template template))))
    (org-roam-capture--put :id id)
    (org-roam-capture--put :finalize (or (org-capture-get :finalize)
                                         (org-roam-capture--get :finalize)))))
1 个赞

你直接报个 issue 吧