bastibe / org-journal

A simple org-mode based journaling mode
BSD 3-Clause "New" or "Revised" License
1.24k stars 123 forks source link

Integrate with org-capture #50

Closed cdlm closed 6 years ago

cdlm commented 9 years ago

Is it possible to make an org-capture template that matches the settings of org-journal?

There seems to be some feature overlap between both packages, but I'm not enough of an elisper to tackle that…

bastibe commented 9 years ago

I don't use org-capture, so I don't know.

cdlm commented 9 years ago

I now have a capture template that puts all entries in a single file, with headings by year/month/day, which is close enough:

("j" "Journal entry" entry
      (file+datetree
       (concat
        (file-name-as-directory org-journal-dir)
        "current.org"))
      "* %(format-time-string org-journal-time-format)%i%?")

Individual entries are formatted like in org-journal, but since everything is in a single file, I don't get the calendar integration (and thus I don't really use org-journal anymore). Dispatching captures in separate files for each day would require some more clever code and working around the orgmode API, e.g. I think the file+datetree doesn't have a way of passing an explicit date (I might remember incorrectly).

bastibe commented 9 years ago

Please keep me updated if you find a nice way of integrating the two. I'm sure there are many people who would be very interested in this.

ejmg commented 8 years ago

Any update on this? Would love to see that integration. Is there really no way to tell org-capture via a template to switch to org-mode when the journal shortcut is chosen?

bastibe commented 8 years ago

I'm sure there is a way. But I don't use org-capture, and I currently don't have the time to look into this.

Miciah commented 6 years ago

Try the following:

(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)
  ;; Position point on the journal's top-level heading so that org-capture
  ;; will add the new entry as a child entry.
  (goto-char (point-min)))

(setq org-capture-templates '(("j" "Journal entry" entry (function org-journal-find-location)
                               "* %(format-time-string org-journal-time-format)%^{Title}\n%i%?")))

Should I submit a pull request to add the above example under "Advanced Usage and Customization" in README.org?

bastibe commented 6 years ago

That is very cool! Thank you!

Should I submit a pull request to add the above example under "Advanced Usage and Customization" in README.org?

Yes, absolutely!

acheng26 commented 5 years ago

But in my practice, using Miciah's beautiful solution will make my org-agenda-files only contains today's entry file. Any thought?

bastibe commented 5 years ago

Could you elaborate on your issue? What is the connection between org-capture and org-agenda files?

acheng26 commented 5 years ago

HI Bastibe, I defined org-capture-templates to use org-journal-find-location:

    (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)
      ;; Position point on the journal's top-level heading so that org-capture
      ;; will add the new entry as a child entry.
      (goto-char (point-min)))

The org-capture-templates:

    (setq org-capture-templates
        '(("j" "Journal Entry"
           entry (function org-journal-find-location)
           "* %(format-time-string org-journal-time-format)%^{Title}\n  %?\n  %i"
           :empty-lines 1
           )
      ...
       )

For individual journal file, it works well. I just cannot use agenda search to get all I need in all journal files while only current day journal will be searched. Could it be an order issue? Should I change the order of those settings?

Here is my dot file https://github.com/acheng26/my-spacemacs-dot-files/blob/master/.spacemacs. The key settings in dotspacemacs-configuration-layers section:

     (org :variables
          org-enable-github-support t
          org-enable-org-journal-support t
          ;; org-journal-enable-agenda-integration t
          org-journal-file-format "%Y%m%d"
          org-journal-dir "~/Documents/org/journal"
          org-journal-date-prefix "#+TITLE: "
          org-journal-date-format "%A, %B %d %Y"
          org-journal-time-prefix "* "
          org-journal-time-format ""
          org-journal-carryover-items "TODO=\"TODO\"|TODO=\"In Progress\"|TODO=\"Paused\"|TODO=\"Waiting\"|TODO=\"Verifying\""
          org-projectile-file "~/Documents/org/gtd.org")

     (journal :variables
              org-journal-enable-agenda-integration t
              org-agenda-files '("~/Documents/org" "~/Documents/org/journal")
              org-agenda-file-regexp "\\`[^.].*\\.org\\'\\|\\`[0-9]+\\'")

And in (defun dotspacemacs/user-config ()) section:

(with-eval-after-load 'org

    (add-hook 'org-mode-hook 'auto-fill-mode)

    (add-hook 'org-mode-hook (lambda ()
                               (set-face-attribute 'org-level-1 nil :background nil)))

    (defun org-summary-todo (n-done n-not-done)
      "Switch entry to DONE when all subentries are done, to TODO otherwise."
      (let (org-log-done org-log-states)   ; turn off logging
        (org-todo (if (= n-not-done 0) "DONE" "TODO"))))

    (add-hook 'org-after-todo-statistics-hook 'org-summary-todo)

    (org-defkey org-mode-map [(meta return)] 'org-meta-return)  ;; The actual fix
    (setq org-todo-keywords
          '((sequence "TODO(t)" "In Progress(g)" "Paused(p)" "Waiting(w)" "Verifying(v)" "|" "DONE(d)" "Canceled(c)")))
    (setq org-todo-keyword-faces
          '(("TODO" . org-warning)
            ("In Progress" . (:foreground "spring green" : ackground "dark slate gray"))
            ("Paused" . (:foreground "gold" :background "dark slate gray"))
            ("Waiting" . (:foreground "silver" :background "dark slate gray"))
            ("Verifying" .  (:foreground "aqua" :background "dark slate gray"))
            ("DONE" . "green")
            ("Canceled" . (:foreground "grey" :background "dark slate gray" :weight bold))
            ))
    '(progn
       (add-to-list 'org-structure-template-alist
                    '("S" "src Emacs-lisp"))
       (add-to-list 'org-structure-template-alist
                    '("p" "src python")))
    (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)
      ;; Position point on the journal's top-level heading so that org-capture
      ;; will add the new entry as a child entry.
      (goto-char (point-min)))

    (setq org-capture-templates
        '(("j" "Journal Entry"
           entry (function org-journal-find-location)
           "* %(format-time-string org-journal-time-format)%^{Title}\n  %?\n  %i"
           :empty-lines 1
           )
          ("n" "Thought or Note"
           entry (file+headline "~/Documents/org/thought_note.org" "Thought Note")
           "* %U %?\n  %a\n  %i"
           :empty-lines 1)
          ("k" "Knowledge"
           entry (file+headline "~/Documents/org/study_note.org" "Knowledge")
           "* %U %?\n  %a\n  %i"
           :empty-lines 1)
          ;; ... other templates
          ("t" "Tasks"
           entry (file+headline "~/Documents/org/gtd.org" "Tasks")
           "* TODO %?\n  %U\n  %a\n  %i"
           :empty-lines 1)
          ))
    (setq org-html-validation-link nil)
    (eval-after-load 'org-list
      '(add-hook 'org-checkbox-statistics-hook (function ndk/checkbox-list-complete)))
    (defun ndk/checkbox-list-complete ()
      (save-excursion
        (org-back-to-heading t)
        (let ((beg (point)) end)
          (end-of-line)
          (setq end (point))
          (goto-char beg)
          (if (re-search-forward "\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" end t)
              (if (match-end 1)
                  (if (equal (match-string 1) "100%")
                      ;; all done - do the state change
                      (org-todo 'done)
                    (org-todo 'todo))
                (if (and (> (match-end 2) (match-beginning 2))
                         (equal (match-string 2) (match-string 3)))
                    (org-todo 'done)
                  (org-todo 'todo)))))))
    )
acheng26 commented 5 years ago

OK, I probably understood what happened. As mentioned in your README.org:

However, this can become very slow if you have many journal entries. As a compromize, you can set org-journal-enable-agenda-integration to t, which automatically adds the current and all future journal entries to the agenda. This is enough to get an overview over current and future tasks.

So when org-journal-enable-agenda-integration is t, org-agenda-files won't be able to set to include all the files in journal folder, and it is a "compromise". But you provide an alternative tool for researching in all files org-journal-search (C-c C-s in org-journal-mode).

bastibe commented 5 years ago

I think you are conflating two issues here. One are the capture templates, the other is the agenda integration. As far as I know, these issues are not connected.

But you got it right in your latest comment. Org is just not a particularly fast piece of software, and really struggles with opening many files quickly. If I add all my org-journal files to my agenda and do an agenda search, it can take a minute or so. An org-journal-search, instead, takes a second.