Clocking: Capture clock in LOGBOOK drawer, abandon CLOCK drawer

Clock lines are now by default captured into the drawer LOGBOOK.  This
means that, if state notes are also captured into a drawer, they will
be mixed with notes.
This commit is contained in:
Carsten Dominik 2009-02-15 01:15:37 +01:00
parent b40671f31b
commit cac8788f35
4 changed files with 80 additions and 20 deletions

View File

@ -1,3 +1,26 @@
2009-02-15 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-add-log-setup): Fix positioning when
`org-log-states-order-reversed' is nil.
* org-clock.el (org-clock-in): Fix positioning when
`org-log-states-order-reversed' is nil.
(org-clock-find-position): Fix positioning when
`org-log-states-order-reversed' is nil.
2009-02-14 Carsten Dominik <carsten.dominik@gmail.com>
* org-clock.el (org-clock-into-drawer): Take default from
`org-log-into-drawer'.
(org-clock-find-position): Look for the correct drawer.
* org.el (org-log-into-drawer): Renamed from
`org-log-state-notes-into-drawer'.
(org-log-state-notes-into-drawer): New variable alias.
(org-add-log-setup): Make drawer name default to LOGBOOK, not
CLOCK.
(org-insert-property-drawer): Also skip LOGBOOK drawers.
2009-02-13 Carsten Dominik <carsten.dominik@gmail.com>
* org-agenda.el (org-agenda): Fix docstring.

View File

@ -41,19 +41,25 @@
:tag "Org Clock"
:group 'org-progress)
(defcustom org-clock-into-drawer 2
(defcustom org-clock-into-drawer org-log-into-drawer
"Should clocking info be wrapped into a drawer?
When t, clocking info will always be inserted into a :CLOCK: drawer.
When t, clocking info will always be inserted into a :LOGBOOK: drawer.
If necessary, the drawer will be created.
When nil, the drawer will not be created, but used when present.
When an integer and the number of clocking entries in an item
reaches or exceeds this number, a drawer will be created."
reaches or exceeds this number, a drawer will be created.
When a string, it names the drawer to be used.
The default for this variable is the value of `org-log-into-drawer',
which see."
:group 'org-todo
:group 'org-clock
:type '(choice
(const :tag "Always" t)
(const :tag "Only when drawer exists" nil)
(integer :tag "When at least N clock entries")))
(integer :tag "When at least N clock entries")
(const :tag "Into LOGBOOK drawer" "LOGBOOK")
(string :tag "Into Drawer named...")))
(defcustom org-clock-out-when-done t
"When non-nil, the clock will be stopped when the relevant entry is marked DONE.
@ -357,6 +363,11 @@ the clocking selection, associated with the letter `d'."
(insert-before-markers "\n")
(backward-char 1)
(org-indent-line-function)
(when (and (save-excursion
(end-of-line 0)
(org-in-item-p)))
(beginning-of-line 1)
(org-indent-line-to (- (org-get-indentation) 2)))
(insert org-clock-string " ")
(setq org-clock-start-time (current-time))
(setq ts (org-insert-time-stamp org-clock-start-time 'with-hm 'inactive))))
@ -381,12 +392,17 @@ the clocking selection, associated with the letter `d'."
(end (progn (outline-next-heading) (point)))
(re (concat "^[ \t]*" org-clock-string))
(cnt 0)
(drawer (if (stringp org-clock-into-drawer)
org-clock-into-drawer "LOGBOOK"))
first last ind-last)
(goto-char beg)
(when (eobp) (newline) (setq end (max (point) end)))
(when (re-search-forward "^[ \t]*:CLOCK:" end t)
(when (re-search-forward (concat "^[ \t]*:" drawer ":") end t)
;; we seem to have a CLOCK drawer, so go there.
(beginning-of-line 2)
(or org-log-states-order-reversed
(and (re-search-forward org-property-end-re nil t)
(goto-char (match-beginning 0))))
(throw 'exit t))
;; Lets count the CLOCK lines
(goto-char beg)
@ -408,11 +424,14 @@ the clocking selection, associated with the letter `d'."
(beginning-of-line 0)
(org-indent-line-to ind-last)
(goto-char first)
(insert ":CLOCK:\n")
(insert ":" drawer ":\n")
(beginning-of-line 0)
(org-indent-line-function)
(org-flag-drawer t)
(beginning-of-line 2)
(or org-log-states-order-reversed
(and (re-search-forward org-property-end-re nil t)
(goto-char (match-beginning 0))))
(throw 'exit nil))
(goto-char beg)
@ -422,15 +441,19 @@ the clocking selection, associated with the letter `d'."
(beginning-of-line 2)
(or (bolp) (newline)))
(when (or (eq org-clock-into-drawer t)
(stringp org-clock-into-drawer)
(and (integerp org-clock-into-drawer)
(< org-clock-into-drawer 2)))
(insert ":CLOCK:\n:END:\n")
(insert ":" drawer ":\n:END:\n")
(beginning-of-line 0)
(org-indent-line-function)
(beginning-of-line 0)
(org-flag-drawer t)
(org-indent-line-function)
(beginning-of-line 2)))))
(beginning-of-line 2)
(or org-log-states-order-reversed
(and (re-search-forward org-property-end-re nil t)
(goto-char (match-beginning 0))))))))
(defun org-clock-out (&optional fail-quietly)
"Stop the currently running clock.

View File

@ -1867,7 +1867,7 @@ from the buffer."
(replace-match ""))))))
(defun org-export-remove-clock-lines ()
"Remove timestamps and keywords for export."
"Remove clock lines for export."
(let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
(while (re-search-forward re nil t)
(org-if-unprotected

View File

@ -1795,24 +1795,29 @@ empty string.
(unless (assq 'note org-log-note-headings)
(push '(note . "%t") org-log-note-headings))
(defcustom org-log-state-notes-into-drawer nil
(defcustom org-log-into-drawer nil
"Non-nil means, insert state change notes and time stamps into a drawer.
When nil, state changes notes will be inserted after the headline and
any scheduling and clock lines, but not inside a drawer. When t,
notes
any scheduling and clock lines, but not inside a drawer.
The value of this variable should be the name of the drawer to use.
LOGBOOK is proposed at the default drawer for this purpose, you can
also set this to a string to define the drawer of your choice.
A value of t is also allowed, representing \"LOGBOOK\".
If this variable is set, `org-log-state-notes-insert-after-drawers'
will be ognored."
:group 'org-todo
:group 'org-progress
:type '(choice
(const :tag "Not into a drawer" nil)
(const :tag "LOGBOOK" "LOGBOOK")
(const :tag "LOGBOOK" t)
(string :tag "Other")))
(if (fboundp 'defvaralias)
(defvaralias 'org-log-state-notes-into-drawer 'org-log-into-drawer))
(defcustom org-log-state-notes-insert-after-drawers nil
"Non-nil means, insert state change notes after any drawers in entry.
Only the drawers that *immediately* follow the headline and the
@ -1820,7 +1825,7 @@ deadline/scheduled line are skipped.
When nil, insert notes right after the heading and perhaps the line
with deadline/scheduling if present.
This variable will have no effect if `org-log-state-notes-into-drawer' is
This variable will have no effect if `org-log-into-drawer' is
set."
:group 'org-todo
:group 'org-progress
@ -9212,9 +9217,9 @@ When FINDPOS is non-nil, find the correct position for the note in
the current entry. If not, assume that it can be inserted at point.
HOW is an indicator what kind of note should be created.
EXTRA is additional text that will be inserted into the notes buffer."
(let ((drawer (cond ((stringp org-log-state-notes-into-drawer)
org-log-state-notes-into-drawer)
(org-log-state-notes-into-drawer "LOGBOOK")
(let ((drawer (cond ((stringp org-log-into-drawer)
org-log-into-drawer)
(org-log-into-drawer "LOGBOOK")
(t nil))))
(save-restriction
(save-excursion
@ -9230,7 +9235,11 @@ EXTRA is additional text that will be inserted into the notes buffer."
(drawer
(if (re-search-forward (concat "^[ \t]*:" drawer ":[ \t]*$")
nil t)
(goto-char (match-end 0))
(progn
(goto-char (match-end 0))
(or org-log-states-order-reversed
(and (re-search-forward org-property-end-re nil t)
(goto-char (1- (match-beginning 0))))))
(insert "\n:" drawer ":\n:END:")
(beginning-of-line 0)
(org-indent-line-function)
@ -10986,8 +10995,13 @@ formats in the current buffer."
(setq hiddenp (org-invisible-p))
(end-of-line 1)
(and (equal (char-after) ?\n) (forward-char 1))
(while (looking-at "^[ \t]*\\(:CLOCK:\\|CLOCK\\|:END:\\)")
(beginning-of-line 2))
(while (looking-at "^[ \t]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\\)")
(if (member (match-string 1) '("CLOCK:" ":END:"))
;; just skip this line
(beginning-of-line 2)
;; Drawer start, find the end
(re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
(beginning-of-line 1)))
(org-skip-over-state-notes)
(skip-chars-backward " \t\n\r")
(if (eq (char-before) ?*) (forward-char 1))