7

Sometimes I want to add a clock entry for something I did after it was already done. For example I may want to add an entry CLOCK: [2017-01-28 Sa 09:35]--[2017-01-28 Sa 10:12] => 0:37 at 10:30.

There doesn't seem to be any easy way to do it. The two methods I can currently think of are:

  • Copy a previous entry and modify its time, then press C-c C-c

  • Invoke org-time-stamp-inactive twice, and then manually type in all the rest (CLOCK:, -- etc.), and then press C-c C-c.

Is there any way I can do it easier, or should I just try to define a custom function for this purpose?

  • Your first option is probably your best bet. I would suggest using org-clock-in or C-c C-x C-i, in combination with the C-u prefix argument SELECT , as well as the C-u C-u C-u prefix argument. Using these together and setting org-clock-continuously will allow you to "clock-in" using the last "clock-out" time as the start time - which "could" be convenient for editing the time estimates of multiple, sequential historical entries. – nyameko Jan 28 '17 at 9:58
6

I need to do what you describe quite often. My goal is to do everything from the agenda view, i.e. having to go to the org source files as few as possible.

In order to insert a colck interval for a specific task I use helm-org-agenda-files-headings (mapped to a keyboard shortcut) which allows me to find tasks very fast. I have defined an additional helm action for this:

;; extend helm for org headings with the clock in action
    (defun dfeich/helm-org-clock-in (marker)
      "Clock into the item at MARKER"
      (with-current-buffer (marker-buffer marker)
      (goto-char (marker-position marker))
      (org-clock-in)
      (org-clock-out)))

    (eval-after-load 'helm-org
      '(nconc helm-org-headings-actions
          (list
           (cons "Clock into task" #'dfeich/helm-org-clock-in))))

This inserts a clock interval with clock-in and clock-out times set to the present time. I then use my own module org-clock-convenience (also available from MELPA) to fast adjust the times directly from the agenda view screen (need to have log lines enabled):

This involves first moving the initial time somewhere into the range between the clock out of the previous task and the next task, then hitting g (this rebuilds the screen with the task now being correctly placed in the interval). Then using org-clock-convenience-fill-gap-both to have clock-in and clock-out expand to the full iterval.

Maybe have a look at the animated gif on the org-clock-convenience module page to get an idea how the clock modification from the agenda buffer works.

| improve this answer | |
  • Thanks. This looks like a comprehensive solution, though I normally just want to insert the clock manually on an individual file, for which I eventually decided to define a convenience function. – xji Jun 23 '18 at 11:16
5

I wanted to do this again recently and I just hacked together a simple function which asks for the beginning and the end of the desired clock entry

(defun jx/insert-custom-clock-entry ()
  (interactive)
  (insert "CLOCK: ")
  (org-time-stamp-inactive)
  (insert "--")
  ;; Inserts the current time by default.
  (let ((current-prefix-arg '(4))) (call-interactively 'org-time-stamp-inactive))
  (org-ctrl-c-ctrl-c))

; Shortcut
(define-key evil-normal-state-map (kbd "C-'") 'jx/insert-custom-clock-entry)
(define-key evil-insert-state-map (kbd "C-'") 'jx/insert-custom-clock-entry)
| improve this answer | |
  • There is a missing ) for (defun... which caused a parsing error for me. Please add that to the anwer. Couldn't edit since it's just one character to add. – scientific_explorer Mar 31 at 6:51
  • @scientific_explorer Thanks for pointing it out. Fixed. – xji Mar 31 at 21:47

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.