progfolio / doct

DOCT: Declarative Org Capture Templates for Emacs
GNU General Public License v3.0
375 stars 8 forks source link

Doct with org-journal #34

Closed DarkBuffalo closed 2 years ago

DarkBuffalo commented 2 years ago

Hi, First of all thank you for the good work done on DOCT.

Context

I tried to adapt the capture provided by org-journal with DOCT but it does not work.

(defun org-journal-find-location ()
  ;; Open today's journal, but specify a non-nil prefix argument in order to
  ;; inhibit inserting the heading; org-capture will insert the heading.
  (org-journal-new-entry t)
  (unless (eq org-journal-file-type 'daily)
    (org-narrow-to-subtree))
  (goto-char (point-max)))

(setq org-capture-templates '(("j" "Journal entry" plain (function org-journal-find-location)
                               "** %(format-time-string org-journal-time-format)%^{Title}\n%i%?"
                               :jump-to-captured t :immediate-finish t)))

Errors

Does the problem come from my adaptation or is this a bug ?

DarkBuffalo commented 2 years ago

maybe that would also interest @bastibe

progfolio commented 2 years ago

Hi, First of all thank you for the good work done on DOCT.

Glad you're finding it useful. Thank you for the thorough bug report.

It looks like you have two separate issues here. Let's deal with them one at a time.

 When I leave the 2 ** in the template it shows me an error

When I wrote the validator, I likely copy pasted a check from just above where entries are checked for leading stars. Instead of string-prefix-p, the check needs to use string-match-p because we want to check via a regexp. I've fixed this on the "development" branch as demonstrated by these two tests:

Yodel Report (2022-07-13 12:45:51):

(yodel
  :user-dir "doct-master"
  :packages*
  doct
  :post*
  (doct
   '("test"
     :keys "t"
     :file ""
     :template "**")))
STDOUT: ```emacs-lisp Loading /tmp/doct-master/straight-bootstrap-snippet.el (source)... Bootstrapping straight.el... Bootstrapping straight.el...done Looking for gnu-elpa-mirror recipe → Cloning melpa... Looking for gnu-elpa-mirror recipe → Cloning melpa...done Looking for emacsmirror-mirror recipe → Cloning gnu-elpa-mirror... Looking for emacsmirror-mirror recipe → Cloning gnu-elpa-mirror...done Looking for emacsmirror-mirror recipe → Cloning el-get... Looking for emacsmirror-mirror recipe → Cloning el-get...done Looking for straight recipe → Cloning emacsmirror-mirror... Looking for straight recipe → Cloning emacsmirror-mirror...done Building straight... Building straight...done Cloning doct... Cloning doct...done Building doct... Building doct...done Warning (doct): expanded :template "**" in the "test" declaration is not a valid Org entry. Are you missing the leading ’*’? ```
Environment - **emacs version**: GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.17.6) of 2022-06-28 - **system type**: gnu/linux
Packages | Name | Branch | Commit | Date | Source | |-------------------------------------------|--------|-----------------------------------------------------------------------------------|------------|--------| | [doct](https://github.com/progfolio/doct) | master | https://github.com/progfolio/doct/commit/8464809754f3316d5a2fdcf3c01ce1e8736b323b | 2022-05-29 | melpa |

Yodel Report (2022-07-13 12:45:53):

(yodel
  :user-dir "doct-development"
  :packages*
  '(doct
    :branch "development")
  :post*
  (doct
   '("test"
     :keys "t"
     :file ""
     :template "**")))
STDOUT: ```emacs-lisp Loading /tmp/doct-development/straight-bootstrap-snippet.el (source)... Bootstrapping straight.el... Bootstrapping straight.el...done Looking for gnu-elpa-mirror recipe → Cloning melpa... Looking for gnu-elpa-mirror recipe → Cloning melpa...done Looking for emacsmirror-mirror recipe → Cloning gnu-elpa-mirror... Looking for emacsmirror-mirror recipe → Cloning gnu-elpa-mirror...done Looking for emacsmirror-mirror recipe → Cloning el-get... Looking for emacsmirror-mirror recipe → Cloning el-get...done Looking for straight recipe → Cloning emacsmirror-mirror... Looking for straight recipe → Cloning emacsmirror-mirror...done Building straight... Building straight...done Cloning doct... Cloning doct...done Building doct... Building doct...done ```
Environment - **emacs version**: GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.17.6) of 2022-06-28 - **system type**: gnu/linux
Packages | Name | Branch | Commit | Date | Source | |-------------------------------------------|-------------|-----------------------------------------------------------------------------------|------------|--------| | [doct](https://github.com/progfolio/doct) | development | https://github.com/progfolio/doct/commit/202f714b0076373ddd307ef1b2910d94099bbd5e | 2022-07-13 | melpa |

I'll merge that into the master branch in a few minutes and you can try it on either branch.

As for your second issue:

When I leave a single * it does not indent the hourly headline

My hunch is that everything is working as expected. The example utilizes a :function which is responsible for placing point. Then the template is inserted as is. So with a first-level heading template, I'd expect a first level heading.

Org capture will adjust the level of the heading in the template if you specify certain targets, such as file+heading, but not when a general point-placing function is used.

Does that help?

progfolio commented 2 years ago

I'm assuming this fixed the issue. If not, feel free to comment and we can reopen this issue.