Org-mode: Limit number of entries in a LOGBOOK drawer - emacs

I have a number of repeating tasks set up in my org-mode file. I also have org-log-into-drawer set to t (see here). This works nicely so that after a while I have something like this:
* TODO My repeating task
SCHEDULED: <2016-06-27 Mon .+1d>
:LOGBOOK:
- State "DONE" from "TODO" [2016-06-26 Mon 16:34]
- State "DONE" from "TODO" [2016-06-25 Mon 16:32]
- State "DONE" from "TODO" [2016-06-24 Mon 15:34]
- State "DONE" from "TODO" [2016-06-23 Mon 12:34]
:END:
However, the :LOGBOOK: drawer continues to be filled with new entries ad infinitum. Eventually this becomes unwieldy and I have to manually prune out the older entries.
Is it possible to limit the maximum number of entries in a :LOGBOOK: drawer so that older entries are discarded when new ones are added?

Related

Hide org todo state changes in drawer or properties

How do I setup my org tree to store the TODO state changes into a drawer. The Logbook drawer works fine. The problem is that when i do a repeating entry each day it logs that. Making a huge tree under the tasks. Anyone know how to store this in :PROPERTIES: or another such drawer so that I still have this data, but it is not visible automatically?
Here is an example of it in my org file.
** TODO Weekly Review/Inbox Review (Planning)
DEADLINE: <2020-09-21 Mon ++1w>
:PROPERTIES:
:LAST_REPEAT: [2020-09-08 Tue 09:22]
:Effort: 0:30
:END:
- State "DONE" from "TODO" [2020-09-08 Tue 09:22]
- State "DONE" from "TODO" [2020-09-02 Wed 09:02]
I wish this was formated like this
** TODO Weekly Review/Inbox Review (Planning)
DEADLINE: <2020-09-21 Mon ++1w>
:PROPERTIES:
:LAST_REPEAT: [2020-09-08 Tue 09:22]
:LOGTODOCHANGEDRAWER:
- State "DONE" from "TODO" [2020-09-08 Tue 09:22]
- State "DONE" from "TODO" [2020-09-02 Wed 09:02]
:Effort: 0:30
:END:
I don't care if it is in properties but I do not want these state changes listed 300times over again in plain text...it is very ugly
TLDR
M-x customize-variable [RET] org-log-into-drawer
Set value of org-log-into-drawer to "LOGBOOK"
Background
After Digging through the org manual I was able to come up with a solution. There is not an exact example within the manual, but by reading it you will likely get the understanding required to figure the solution out yourself. As always, just read through it if you have time and make sure that it all makes sense generally. Here is a link to page that is most closely related.
https://orgmode.org/org.html#Tracking-TODO-state-changes
https://orgmode.org/org.html#Drawers
When using org-mode the style of tacking I was using for repeating tasks was habit. In the example below I have applied that explicitly through the properties drawer.
When tracking a variable with org-habit there are 4 options for storage of logging. Each time the todo state change happens org-habit was logging the state change 'outside of a drawer'; which means that when the item is opened all of the state changes appear in plain text. By default this is the setup. There are 3 options currently available.
To view these options go to customize-variable buffer for the "Org Process Group" inside of that you will find "Org Log Into Drawer" to get the todo state changes to write to the "Logbook" simply change to "logbook"
In summary we could write out the initialization file to store in logbook using:
METHOD 1: define globally using init.el
;; write todo state changes into LOGBOOK drawer
(setq org-log-into-drawer LOGBOOK)
## METHOD 2: define for a specific tree
* TODO test
DEADLINE: <2020-09-22 Tue ++1w>
:PROPERTIES:
:STYLE: habit
:LOG_INTO_DRAWER: t
:LAST_REPEAT: [2020-09-08 Tue 10:41]
:END:
:LOGBOOK:
- State "DONE" from "TODO" [2020-09-08 Tue 10:41]
- State "DONE" from "TODO" [2020-09-08 Tue 10:40]
:END:
Method 3
set this as provided by other contributor and both the state changes and the timer logs are placed inside the drawer.
;;; inside init.el
(setq org-log-done t)
Normally I too would suggest the manual, but this actually is one example I found outside the manual. I found the answer:
(setq org-log-done t)
here.
Interestingly, t isn't even one of the options in the customization choices for this variable and yet it does work to put not only timelogs into the :LOGBOOK: drawer, but also state changes. Normally I go read the source code to see why that is the case, but I can't be bothered at the moment - it works. Prior to changing this myself, I was using one of the customization options of 'time to only put clocking (and not state changes) in :LOGBOOK:, but I prefer this setting to tidy things up.

org-mode habit consistency graph not displaying

org-version 8.3.4 (elpa package, 20160530)
emacs 24.4.1 (Debian package, Installed: 24.4+1-4.1~bpo70+1)
When I started using org-mode from elpa, the habit consistency graph stopped showing. I was using a version of org-mode that comes with debian before, with emacs 23 and the graph showed.
I'm a beginner in emacs lisp, but anyway I tried stepping through the org-agenda-list function and found the org-agenda-finalize function where the org habit graph is supposed to be inserted via the org-habit-insert-consistency-graphs function. But it skips over that function, probably because this expression returns false:
(next-single-property-change (point-min) 'org-habit-p))
At this point, I don't know what to do to make habits show. This is the first time I've looked at org-mode code, I don't know what the above test is for.
Help, please?
UPDATE: 2016-06-25. I upgraded the org-mode package to elpa, 20160620 (still org-version 8.3.4). Still have the same behaviour. I am getting the package from elpa.gnu.org.
UPDATE 2: 2016-07-02: I did try pressing K (for org-habit-toggle-habits). It didn't change the contents of the buffer visibly. I also tried refreshing the buffer after typing K. And repeating the experiment, in case the K put emacs in the wrong mode the first time.
UPDATE 3: 2016-07-08: on the emacs-orgmode mailing list, I got advice to ensure that the structure of the entries with habits is:
headline
SCHEDULED
PROPERTIES
everything else
by using this function org-repair-property-drawers from this site:
http://orgmode.org/Changes.html
but that broke my weekly agenda display and also, once I fixed the entries, didn't make the habits work. Probably my entries were in worse shape than the function anticipated. But this method worked for Josiah who sent the advice. Including it here in case it helps someone else.
UPDATE 4: 2016-07-09: thanks Phil for the suggestion to make a minimal example of the problem. With the following .org file and no other, I see the problem:
** TODO daily customer meeting :SUPPORT:CUSTOMER:
:SCHEDULED: <2016-07-06 Wed 10:30 .+1d>
:PROPERTIES:
:LAST_REPEAT: [2016-07-05 Tue 12:00]
:STYLE: habit
:END:
:LOGBOOK:
- State "DONE" from "TODO" [2016-07-05 Tue 12:00]
- State "DONE" from "TODO" [2016-06-30 Thu 16:34]
- State "DONE" from "TODO" [2016-06-29 Wed 20:02]
- State "DONE" from "TODO" [2016-06-28 Tue 10:53]
- State "DONE" from "TODO" [2016-06-27 Mon 10:50]
- State "DONE" from "TODO" [2016-06-23 Thu 12:11]
- State "CANCELLED" from "TODO" [2016-06-21 Tue 13:43] \\
No meeting today, cancelled by Mmmm.
:END:
I'm using the minimal.emacs suggested in the link, namely:
(add-to-list 'load-path (expand-file-name "/home/bjb/.emacs.d/elpa/org-20160620"))
(add-to-list 'auto-mode-alist '("\\.\\(org\\ |org_archive\\|txt\\)$" . org-mode))
(setq org-agenda-files '("/home/bjb/.emacs.d/test/test.org"))
(require 'org-install)
(require 'org-habit)
;(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
;(global-set-key "\C-cb" 'org-iswitchb)
And showing the agenda with C-c a a.
I had added the leading colon to the SCHEDULED line... when I remove it, the graph shows up. However, I had added it (a while ago) because I was trying to solve other problems, which I don't remember what they were.
I will play with this, and see if I can get all my org files to load fully with habit-consistency-graphs. Thanks ... will report back with results.
Must note that when I looked at this particular item (which is a short version of an actual habit in my org-files) there were two PROPERTY drawers, one before LOGBOOK with just the LAST-REPEAT property, and one after LOGBOOK with the habit property. I merged the two property drawers to show you the failure, as I believe the PROPERTY drawer is supposed to be in one piece before the LOGBOOK drawer. So I have some maintenance to do on my org-files. I had tried to merge them into one piece in each habit before, but then agenda weekly view broke badly and I put it back the way it was. Will have to try harder.
UPDATE 5 2016-07-09: I had put in the leading colon before SCHEDULED: because I wanted to see when the 3-monthly items fell in the future ... I wanted to see them as scheduled items. That worked but when I upgraded org-mode the consistency graph went away. When I took off the leading colon on all the habits, the daily habits showed up, and I have confidence that the three-monthly items will show up when they fall on "today". But I won't get any notice of having to pay the interest ... it will just appear on the day it must be paid. Well that is for me to figure out.
Thanks everyone for considering and answering my question.
I had a similar problem today, and it turns out that somehow the habit module was turned off (but the recurrent tasks still stays in the agenda so I didn't make the connection). When I re-enable the module (M-x customize variable org-modules then tick on habit), the consistency graph displays as normal in the agenda's view.
This won't solve your issue but might help a bit:
http://orgmode.org/worg/org-faq.html#minimal-emacs
Maybe you have turned them off somehow? Does pressing 'K' in the agenda help?
I've had the same problem after upgrading org-mode from version 8.2.10 to 9.1.9 (because of this bug).
Here is what an entry was looked like (org-version = 8.2.10) :
** TODO Sleep in time
SCHEDULED: <2019-09-07 sam. 23:00 +1d>
- State "DONE" from "TODO" [2019-09-07 sam. 02:54]
- State "DONE" from "TODO" [2019-09-06 ven. 02:09]
- State "DONE" from "TODO" [2019-09-05 jeu. 00:29]
:PROPERTIES:
:STYLE: habit
:LAST_REPEAT: [2019-09-07 sam. 02:54]
:END:
... and what i've done so that the graph show up again (org-version = 9.1.9) :
** TODO Sleep in time
SCHEDULED: <2019-09-07 sam. 23:00 +1d>
:PROPERTIES:
:STYLE: habit
:LAST_REPEAT: [2019-09-07 sam. 02:54]
:END:
- State "DONE" from "TODO" [2019-09-07 sam. 02:54]
- State "DONE" from "TODO" [2019-09-06 ven. 02:09]
- State "DONE" from "TODO" [2019-09-05 jeu. 00:29]
As it's showed, I've swapped up the PROPERTIES drawer and the "log" list.
EDIT:
I just realised that this solution is exactly the same as #schmuu suggested (I don't use LOGBOOK drawer). I got the same conclusion by creating a repeating entry and marked it as done in the agenda view. The "log" item list had appeared after the PROPERTIES drawer.

Wrong sorting of items with repeated timestamps in agenda view?

I am using Emacs org-mode. Assume it is 2012-11-10 (today) and I have a TODO item:
**** LATER [#D] call John :phone:
SCHEDULED: <2012-07-23 Mon .+1m>
- State "DONE" from "TODO" [2012-06-23 Sat 12:21]
:PROPERTIES:
:LAST_REPEAT: [2012-06-23 Sat 12:21]
:END:
In the agenda view that I get with Ctrl-c a a this shows up as:
TODO: Sched.19x: LATER [#D] call John :phone:
and is sorted among the other items that have a SCHEDULED date 19 days ago. However, the item above has not been worked on for almost four months, so it should actually be sorted among the items SCHEDULED on <2012-07-23 Mon> (~110 days ago).
I consider this a bug, but I wanted to know whether there is any option I could try to fix that behavior. I have searched the internet for over an hour but did not find a solution.
It's not a bug but the expected behavior.
You scheduled the task with the repeated interval
SCHEDULED: <2012-07-23 Mon .+1m>
which means that the task is kinda re-scheduled every month. The last time it was 2012-10-27, 19 days ago.
You can remove the repeated interval
SCHEDULED: <2012-07-23 Mon>
then the task will be shown as scheduled 110 days ago.

Emacs org-mode scheduling an item multiple times a day?

I want to schedule a task in emacs org-mode to show up multiple times during the day.
Edit: as an example suppose I want yo call my wife every 2 hours during the day.
According to the Org Mode manual on Repeated Tasks there is an hourly repeater:
In the following example
** TODO Pay the rent
DEADLINE: <2005-10-01 Sat +1m>
the +1m is a repeater; the intended interpretation is that the task
has a deadline on <2005-10-01> and repeats itself every (one) month
starting from that time. You can use yearly, monthly, weekly, daily
and hourly repeat cookies by using the y/w/m/d/h letters.
You may use something like that:
* TODO Call Wife
DEADLINE: <2013-02-17 Sun 16:00 +2h>
Unfortunately, I've noticed that special repeater modifiers (++ and .+) do not work properly for hourly repeaters. The manual says:
** TODO Call Father
DEADLINE: <2008-02-10 Sun ++1w>
Marking this DONE will shift the date by at least one week,
but also by as many weeks as it takes to get this date into
the future. However, it stays on a Sunday, even if you called
and marked it done on Saturday.
Based on this, you would expect that marking an entry with an hourly repeater (such as the one above) DONE would "shift time by at least n hours but also as many hours as it takes to get this date into the future".
However, here's what I got after marking both entries DONE:
** TODO Call Father
DEADLINE: <2013-03-03 Sun ++1w>
- State "DONE" from "TODO" [2013-02-25 Mon 23:06]
:PROPERTIES:
:LAST_REPEAT: [2013-02-25 Mon 23:06]
:END:
** TODO Call Wife
DEADLINE: <2013-02-17 Sun 18:00 ++2h>
- State "DONE" from "TODO" [2013-02-25 Mon 23:06]
:PROPERTIES:
:LAST_REPEAT: [2013-02-25 Mon 23:06]
:END:
As you can see, the time in the second entry has shifted to 18:00, but the date is still the same.
Concerning an approach for creating repeating items explicitly another feature could be useful. The manual says:
An alternative to using a repeater is to create a number of copies of
a task subtree, with dates shifted in each copy. The command C-c C-x c
was created for this purpose, it is described in Structure editing.
But unfortunately, it doesn't work with hours.
Information in this post based on Org Mode version 7.9.3.e.
In the absence of hour/minute level repeaters, if the interval is not too small, you might add multiple timestamps for the hours, while using the other facilities for repeated items:
** Testentry
<2012-01-19 Do 10:00 +1w>
<2012-01-19 Do 12:00 +1w>
The resulting agenda view
Thursday 19 January 2012
Calendar: 10:00...... Testentry
Calendar: 12:00...... Testentry
[...]
Thursday 26 January 2012
8:00...... ----------------
Calendar: 9:45-10:00 XXXXXXXXXXXXXX :OFFICE:
10:00......
Calendar: 10:00...... Testentry
10:00...... ----------------
Calendar: 12:00...... Testentry
[...]

Show only notes in org-mode without org-mode-related info?

How can I get just the notes from org-mode heading without any "technical" stuff?
I mean, I want something like that
* Some project
- some note 1
- some note 2
** some chapter
- another note
- noooote
** TODO some big todo
- something to note for the task
- another thing
** some chapter
instead of that
* Some project
- some note 1
- some note 2
** some chapter
- another note
- noooote
** TODO some big todo
CLOSED: [2011-11-10 Thu 19:51]
- State "DONE" from "STARTED" [2011-11-10 Thu 19:51]
CLOCK: [2011-11-10 Thu 19:33]--[2011-11-10 Thu 19:51] => 0:18
CLOCK: [2011-11-04 Fri 15:29]--[2011-11-04 Fri 15:29] => 0:00
:PROPERTIES:
:Effort: 0:30
:END:
[2011-11-04 Fri 15:29]
- something to note for the task
- another thing
** some chapter
EDIT: I figured out I can accomplish that using exports (with #+OPTIONS: <:nil d:nil), but its not really convenient - I mean, I need to press Ctrl-c Ctrl-e u, then switch to new buffer Ctrl-b temp-buffer, then delete everything from it Ctrl-x h Ctrl-w, then add my export Ctrl-y Meta-y. Thats a LOT of keys to press.
Besides that, I couldn't get rid of stuff like - State "DONE" from "STARTED" [2011-11-10 Thu 19:51] because formally it is just a note - exactly the thing I "wanted" to keep.
Although you'll need to manually repair much of your existing org-document, the solution would be to use Logbook drawers.
To file your todo-state changes into a drawer (default to LOGBOOK) you can use (see Tracking TODO state changes): (setq org-log-into-drawer t) or :LOG_INTO_DRAWER: t as a property on the headline.
You can also use (setq org-clock-into-drawer t) to place all your CLOCK: lines into the :LOGBOOK: as well. If you want your clocking to go in a separate value, replace t with the string you want as your drawer title (e.g. (setq org-clock-int-drawer "CLOCK")
Then when you export your #+OPTIONS: d:nil will prevent any of those drawers from being exported, so none of that information will appear.