orgmode logbook drawer total time not calculated as expected - emacs

I use the logbook drawer in a headline like this:
* WIP My Project
:LOGBOOK:
CLOCK: [2020-01-15 mer. 10:18]--[2020-01-15 mer. 11:18] => 1:00
CLOCK: [2020-01-14 mar. 10:12]--[2020-01-14 mar. 11:12] => 1:00
CLOCK: [2019-11-13 mer. 14:20]--[2019-11-13 mer. 14:50] => 0:30
:END:
When I ask for the total time (pressing C-c C-x C-d) I have 2:00 and not 2:30 as expected. The CLOCK entry of 2019 is excluded. I wonder why...
Any idea? Thanks in advance!

Try C-u C-u C-c C-x C-d. By default, org-clock-display uses the range set in org-clock-display-default-range, which defaults to thisyear.

Related

org-habit shows no habits

I've posted before on using Brent Hansen's amazing org setup. This time around, I'm specifically having a problem with getting org-mode to display my habits.
I had to nuke my emacs and start from scratch recently, so debugging is hard.
I am quite certain that I have habit mode enabled since:
I have enabled in my .emacs (see below)
;; Enable habit tracking
(setq org-modules (quote (org-habit)))
; position the habit graph on the agenda to the right of the default
(setq org-habit-graph-column 50)
(run-at-time "06:00" 86400 '(lambda () (setq org-habit-show-habits t)))
My capture template for habits, seems to set up to include everything needed:
("h" "Habit" entry (file "~/Dropbox/org-new/refile.org")
"* NEXT %?\n%U\n%a\nSCHEDULED: %(format-time-string \"%<<%Y-%m-%d %a .+1d/3d>>\")\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\n")
I have an additional set of properties in my Top Level Header for habits that reads:
* Habits
:PROPERTIES:
:LOGGING: DONE(!)
:ARCHIVE: %s_archive::* Habits
:END:
When I run the agenda, I see (Org-Agenda Day Ddl Grid Habit Wrap) in the Mode line
Despite that, my habits do not show up, nor does a habit graph, when I run the agenda. I've trawled everything I can to try and solve this and I'm now at my wit's end. Any help would be greatly appreciated!
You need to add a :STYLE: property with the value habit to your habits:
** TODO Shave
SCHEDULED: <2009-10-17 Sat .+2d/4d>
- State "DONE" from "TODO" [2009-10-15 Thu]
- State "DONE" from "TODO" [2009-10-12 Mon]
- State "DONE" from "TODO" [2009-10-10 Sat]
- State "DONE" from "TODO" [2009-10-04 Sun]
- State "DONE" from "TODO" [2009-10-02 Fri]
- State "DONE" from "TODO" [2009-09-29 Tue]
- State "DONE" from "TODO" [2009-09-25 Fri]
- State "DONE" from "TODO" [2009-09-19 Sat]
- State "DONE" from "TODO" [2009-09-16 Wed]
- State "DONE" from "TODO" [2009-09-12 Sat]
:PROPERTIES:
:STYLE: habit
:LAST_REPEAT: [2009-10-19 Mon 00:36]
:END:
See Tracking your habits.
EDIT: While the STYLE:habit property is necessary, that isn't the problem in this case (as discussed in the comments). However, it might well be that the order of the elements in the headline is the problem. Running org-lint on the following example:
* NEXT Exercise
[2017-07-16 Sun 19:36]
[[file:~/Dropbox/org-new/todo.org::*Write][Write]]
SCHEDULED: <2017-07-16 Sun .+1d/2d>
:PROPERTIES:
:STYLE: habit
:REPEAT_TO_STATE: NEXT
:END:
I get
3 low Link to non-existent local file "~/Dropbox/org-new/todo.org"
4 low Misplaced planning info line
5 high Incorrect location for PROPERTIES drawer
If I reorg the file a bit to this:
* NEXT Exercise
SCHEDULED: <2017-07-16 Sun .+1d/2d>
:PROPERTIES:
:STYLE: habit
:REPEAT_TO_STATE: NEXT
:END:
[2017-07-16 Sun 19:36]
[[file:~/Dropbox/org-new/todo.org::*Write][Write]]
then the high priority warning disappears. I don't know whether that will make habits work, but I'm willing to bet that it would.
The manual states:
When they are associated with a single entry or with a tree they need to be inserted into a special drawer (see Drawers) with the name PROPERTIES, which has to be located right below a headline, and its planning line (see Deadlines and scheduling) when applicable.

emacs org-mode repeat task before deadline

I have some confusion on emacs org data and times.
For example:
** TODO study English
DEADLINE: <2013-05-17 Fri> SCHEDULED: <2013-05-14 Thu ++1d>
After 2013-05-17, I don't want to show this task again. but right now in agenda view, it shows:
Friday 17 May 2013
jtd: Deadline: TODO study English
Saturday 18 May 2013
jtd: Scheduled: TODO study English
Sunday 19 May 2013
jtd: Scheduled: TODO study English
How can I do this in org mode?

How to insert current time in the emacs org-mode

Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon 16:44]) in the org-mode? In the manual there is a lot of stuff (clocks, deadlines, schedules), but most of them require entering the time manually.
C-u C-c . will insert a timestamp at point, though Org will still prompt you for a time (with the default being the current time).
More: "Creating timestamps" in the Org Mode manual.
In my installation, which is org-mode version 9, the following enters the current date and time without prompting anything
C-u C-u C-c .
C-u C-c !
inserts an inactive timestamp with the current time such as:
[2018-05-08 Tue 00:30]
In emacs-lisp, you could use
(org-insert-time-stamp (current-time) t)
With default settings, it will generate a time stamp on the format
<2021-06-20 Sun 10:33>
If you want to access it from any emacs session, put
(defun insert-now-timestamp()
"Insert org mode timestamp at point with current date and time."
(interactive)
(org-insert-time-stamp (current-time) t))
in your .emacs file. You may then call the function with M-x insert-now-timestamp.
Emacs 27.2, org mode 9.4.4.
Edit: I now realise this does the same thing as #anachronic's solution. I however leave it here for reference.
On my installation
C-u C-c .
inserts a date-with-time stamp
Just give you some other options:
If you are using windows system, you can use AutoHotKey to achieve this.
If you can install YASnippet for emacs, it also have the shortcut to insert current date and time.
These two options are very powerful tools, not for just insert date and time.

Emacs org mode: how to adjust previous clock if I forget to clock out

Using emacs org mode for about a month now to track all my projects and tasks.
I clock all activities throughout my day, not just work related ones.
My question is- I often forget to clock-in to a new activity (say, taking lunch). When I return and clock back in to a work activity, I need to first clock in to lunch and then adjust the starting time stamp for it. This is fine for the lunch activity, but it doesn't adjust the previous work work related task before I took lunch, so the net is that the previous task overlaps lunch and is inaccurate.
Is there a way to change the behavior so that it does adjust the previous task? I don't wish to use the idle feature to do this; I'd prefer to have the adjustment happen automatically.
ETA: This also came up again on the mailing list and there appears to be a recent commit to the code base that provides another [perhaps better] way to do this. See the mailing list discussion for Bastien's (org-mode maintainer) input:
S-M-[up/down] on a clock timestamp will try to update the previous/next
clock timestamp too.
(Actually, bzg's suggestion below is this exact thing... it just didn't have the shortcut above included, so I think his answer looks harder/less attractive than the above, which is really easy.)
You can also use org-resolve-clocks. See Resolving idle time.
Essentially, you have some headline and are clocked in:
* Work
:LOGBOOK:
CLOCK: [2012-07-25 Wed 8:26]
:END:
I come back from lunch and realize I forgot to clock out of work and into lunch.
I run M-x org-resolve-clocks and get this prompts:
Select a Clock Resolution Command:
i/q/C-g Ignore this question; the same as keeping all the idle time.
k/K Keep X minutes of the idle time (default is all). If this
amount is less than the default, you will be clocked out
that many minutes after the time that idling began, and then
clocked back in at the present time.
g/G Indicate that you "got back" X minutes ago. This is quite
different from 'k': it clocks you out from the beginning of
the idle period and clock you back in X minutes ago.
s/S Subtract the idle time from the current clock. This is the
same as keeping 0 minutes.
C Cancel the open timer altogether. It will be as though you
never clocked in.
j/J Jump to the current clock, to make manual adjustments.
For all these options, using uppercase makes your final state
to be CLOCKED OUT.
Since I want to Keep X minutes of Work, clock out, and then clock into Lunch, I press K, which prompts me with (it's ~1:30p right now):
Keep how many minutes? (default 303)
I can hit enter to keep all of them, but let's say I took lunch around 12p. That's about 3.5hrs of work, so I'll enter 210 RET.
Now, I clock into Lunch and get this prompt:
You stopped another clock 101 minutes ago; start this one from them? (y or n)
I enter y RET and Lunch gets clocked in at 11:56a. If you're back from lunch and working again (or started working and forgot), repeat the process:
M-x org-resolve-clocks
K
____ RET ;; for how many minutes you at lunch
C-c C-x C-i ;; to clock in on Work again
y RET ;; clock in at when you stopped lunch
The final result:
* Work
:LOGBOOK:
CLOCK: [2012-07-25 Wed 12:41]
CLOCK: [2012-07-25 Wed 8:26]--[2012-07-25 Wed 11:56] => 3:30
:END:
* Lunch
:LOGBOOK:
CLOCK: [2012-07-25 Wed 11:56]--[2012-07-25 Wed 12:41] => 0:45
:END:
Hope this helps. The org-mode clocking wizard, Bernt Hansen, explained this to me via an org-mode mailing list thread.
This is now implemented (check http://orgmode.org/w/?p=org-mode.git;a=commit;h=3528fc).
(setq org-clock-continuously t) in your .emacs.el and new clocks will start from the time when the last clock was closed.
C-u C-u C-u M-x org-clock-in RET and C-u C-u M-x org-clock-in-last RET will also do this, even when org-clock-continuously is set to nil.
If I understand your question correctly, you want to adjust the timestamp after clocking out. There is a command for this; you can check out the functions:
org-timestamp-up
org-timestamp-down
I thought these were bound by default, but it appears they are not, so you will want to bind them to a key sequence, maybe something like C-c T u and C-c T d, or whatever floats your boat. Usage is simple, just move the cursor over the field you want to adjust by, and run up or down. It only works on the timestamp itself, NOT the calculated duration that appears on the right.
You might also check out
org-timestamp-change
which the top two functions are wrappers for. You might also need to customize the variable
org-time-stamp-rounding-minutes
By default, it will round timestamps to +/- 5 minutes from the start of your original clock-in, and you might be puzzled when modifying the timestamp.
Personally, I prefer (setq org-time-stamp-rounding-minutes '(0 1)) which will start the timer on the exact minute I clock-in (the zero), and use a granularity of 1 minute(s) for timestamp changes. Also, you can use a prefixes like C-u 4 7 C-c T u on the minute part of timestamps, and org-mode will do the right thing - even rounding up the hour.
Summary:
(setq org-time-stamp-rounding-minutes '(0 1))
(add-hook 'org-mode-hook
'(lambda ()
(local-set-key (kbd "C-c T u") 'org-timestamp-up)
(local-set-key (kbd "C-c T d") 'org-timestamp-down)))

[org-mode]: repeating task in every Mon, Wed, Fri at 18:00, need help with sexp

As I had written in title, I need a little help with improvement of this sexp:
* TODO remeber about thingie.
SCHEDULED: <%%(or (= 1 (calendar-day-of-week date))
(= 3 (calendar-day-of-week date))
(= 5 (calendar-day-of-week date)))>
Now it shows itself in the following days, but I would like to change two things about it:
How can I also schedule on specific hours (i.e. 18:00 - 20:00) in the following days
How can I made this task repeat itself, just like it repeats itself with
<2010-05-13 Wed +1w>
(by repetition I mean something like it automatically logs the closing date and time and comes back to the TODO state).
I will be grateful for any help.
Thanks.
* TODO remeber about thingie.
SCHEDULED: <2012-05-07 Mon 18:00 +1w>
SCHEDULED: <2012-05-09 Wed 18:00 +1w>
SCHEDULED: <2012-05-11 Fri 18:00 +1w>
Unfortunately, you cannot use diary-sexps for repeating TODO items in org-mode like that.
The work-around is to create three repeating TODO items, and use the normal org-mode date expressions, not diary sexps.
If you don't need to mark task as DONE every day, you must simply write:
** remeber about thingie 1. 18:00-20:00
<%%(and (memq (calendar-day-of-week date) '(1 3 5))
(diary-block 03 26 2012 12 31 2012))>
In your case you have to use separated tasks:
** TODO remeber about thingie 2-1. 18:00-20:00
SCHEDULED: <2012-03-26 Mon +1w>
** TODO remeber about thingie 2-3. 18:00-20:00
SCHEDULED: <2012-03-28 Wed +1w>
** TODO remeber about thingie 2-5. 18:00-20:00
SCHEDULED: <2012-03-30 Fri +1w>
Marking task as DONE (C-c C-t) your task will be changed automatically to:
** TODO remeber about thingie 2-5. 18:00-20:00
SCHEDULED: <2012-04-06 Fri +1w>
- State "DONE" from "TODO" [2012-03-30 Fri 12:34]
:PROPERTIES:
:LAST_REPEAT: [2012-03-30 Fri 12:34]
:END: