9

Is there a way to make a logbook-like note without it always being stuck in a :LOGBOOK drawer? For example:

- [2015-09-02 Wed 18:03] \\
    * 12.3 Export settings             :om:htmlexport:
      - Up: Exporting
      - [[http://orgmode.org/manual/Export-settings.html][Export settings]]

I like being able to just stick a timestamped observation anywhere with C-c C-z. Is there any way to turn off the automatic :LOGBOOK drawer?

14

Where org-add-note sticks the note is controlled by org-log-into-drawer. If it's nil your notes go into the body instead of the logbook drawer. If you set org-log-into-drawer to nil you may also want to set org-log-state-notes-insert-after-drawers which will ensure that the notes go after LOGBOOK and PROPERTIES.

I've been using this bit of advice to let me pick where notes go. With a C-u prefix they go in the body, otherwise they go into LOGBOOK

(defun with-no-drawer (func &rest args)
  (interactive "P")
  (let ((org-log-into-drawer (not (car args))))
    (funcall func)))

(advice-add 'org-add-note :around #'with-no-drawer)
5

New here with no-reputation, otherwise I would simply have added a comment to erikstokes answer.

Using org-mode version 8.3.4 the advise above was not sufficient as org-add-note() had completed before org-store-log-note() callback function had been called.

So I took his example and made it two pronged:

(defun sjm/org-add-note (func &rest args)
  "Set sjm/org-log-into-drawer to value of args (c-u), its value is read by sjm/org-store-log-note."
  (interactive "P")
  (setq sjm/org-log-into-drawer (car args))
  (funcall func))

(defun sjm/org-store-log-note (func)
  "calls org-store-log-note momentarily setting
org-log-into-drawer to nil if sjm/org-log-into-drawer is nil. As set by sjm/org-add-note."
  (if (not sjm/org-log-into-drawer)
      (funcall func)
    (let ((org-log-into-drawer nil))
      (funcall func))))

(advice-add 'org-add-note :around #'sjm/org-add-note)
(advice-add 'org-store-log-note :around #'sjm/org-store-log-note)

As it stands sjm/org-log-into-drawer is a global switch, but then so is the buffer *Org Note*; meaning you can only take one note at a time anyway!


org-version 9.4 (9.4.4) needs to have advice around org-log-into-drawer() rather than org-store-log-note(). I now have the following instead of the above (corrected to reset).

  (defun sjm/org-add-note (func &rest args)
    "Advisor function to go around `org-add-note'.  Takes optional
  count (c-u) and sets sjm/org-log-into-drawer to be used by
  `sjm/org-store-log-note'.

  The usage is thus:

  (advice-add 'org-log-into-drawer :around #'sjm/org-log-into-drawer)
  (advice-add 'org-add-note :around #'sjm/org-add-note)

  When you do not want to log note into a draw use C-u C-c C-z.
  Otherwise use C-c C-z as normal and it should log note as per
  standard `org-log-into-drawer'.
  "
    (interactive "P")
    (setq sjm/org-log-into-drawer (car args))
    (funcall func))

  (defun sjm/org-log-into-drawer (func)
    "Advisor function to go around `org-log-into-drawer'.
  Reads value of sjm/org-log-into-drawer, as set by
  `sjm/org-add-note', and if set returns nil meaning do not log
  into drawer.  Otherwise returns value from call to
  `org-log-into-draw'.  Before returning resets
  sjm/org-log-into-drawer for subsequent calls."
    (let ((ret
    (if (not sjm/org-log-into-drawer)
        (funcall func)
      nil)))
      (setq sjm/org-log-into-drawer nil)
      ret))
  (setq sjm/org-log-into-drawer nil)
  (advice-add 'org-log-into-drawer :around #'sjm/org-log-into-drawer)
  (advice-add 'org-add-note :around #'sjm/org-add-note)
3
  • 1
    After upgrade to Org 9 (9.3) this is no longer working. I presume something changed. @narendraj9 answer below has it working again for me. – alls0rts May 27 '20 at 17:59
  • Could you post your revised solution that accepts C-u and works for Org 9 ? Many thanks ! – SOUser Feb 25 at 6:10
  • @SOUser Added changes for org-version 9.4. – alls0rts Mar 17 at 9:51
4

This is what worked for:

(defun with-no-drawer (func &rest args)
    (interactive "P")
    (if (eq org-log-note-purpose 'note)
        (let ((org-log-state-notes-insert-after-drawers t))
          (flet ((org-log-into-drawer (&rest args) nil))
            (apply func args)))
      (apply func args)))
(advice-add 'org-log-beginning :around #'with-no-drawer)

org-log-beginning needs to be advised because org-add-note simply sets up post-command hook and advice operates only during that setup.

2
  • Agreed, this works for me on Org 9.3. While my answer above stopped working. Thanks. – alls0rts May 27 '20 at 17:58
  • Org 9.4 needed additional work, see my new workaround above. – alls0rts Mar 26 at 22:12
2

You can also change it by emacs' graphic interface:

m-x customize-variable org-log-into-drawer

then click in Value Menu menu and choose an option.

Note that if you change it this way, it automatically added an entry in your emacs config file such as:

(custom-set-variables
 '(org-log-into-drawer t))
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.