summaryrefslogtreecommitdiffstats
path: root/different-roles.post
blob: aa7015908be52df4748b34b2541d85a5f6cd637b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
;;;;;
title: Different roles
date: 2013-01-10
tags: org-mode, emacs, todo
format: html
;;;;;
<p>
The other day I noticed that when I'm working I find it very annoying
to have tasks for my personal projects appear in either my agenda or
my todo list, so I was thinking if I couldn't make it somewhat more
flexible.
</p>

<p>
First I've added some separation between my org files, I've split
them into <code>personal-org-agenda-files</code>, <code>work-org-agenda-files</code> and
<code>common-org-agenda-files</code>, since there are also <i>some</i> tasks that I would
like to know about in either situation.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defvar oni:personal-agenda-files
  (list (expand-file-name "~/documents/org/tasks"))
  "My personal agenda, should only show up at times I don't have
  to work.")

(defvar oni:work-agenda-files
  (list (expand-file-name "~/documents/org/work"))
  "My work agenda, should only show up at times I work.")

(defvar oni:common-agenda-files
  (list (expand-file-name "~/documents/org/misc"))
  "Agenda files that are work-agnostic, should always show up.")
</pre>
</div>

<p>
At first I only seperated them with <code>org-agenda-custom-commands</code>:
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(setq org-agenda-custom-commands
      '(("P" . "Personal only")
        ("Pa" "Personal agenda" agenda ""
         ((org-agenda-files (append oni:personal-agenda-files
                                    oni:common-agenda-files))))
        ("Pt" "Personal todo" agenda ""
         ((org-agenda-files (append oni:personal-agenda-files
                                    oni:common-agenda-files))))
        ("W" . "Work only")
        ("Wa" "Work agenda" agenda ""
         ((org-agenda-files (append oni:work-agenda-files
                                    oni:common-agenda-files))))
        ("Wt" "Work todo" todo ""
         ((org-agenda-files (append oni:work-agenda-files
                                    oni:common-agenda-files))))))
</pre>
</div>

<p>
But it's clunky to have to use a separate command just to see a clean
todo list.  Then I thought, and tried, to have a function that checks
the time to see which it should use, since I work from 09:00 to
17:00, if the current time is between those times I should only look
at my work todo list, most of the time, outside of those hours I
don't really care what I have to do for work.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(defun oni:set-org-agenda-files ()
  (interactive)
  (let ((current-time (current-time-string))
        (start-time (format-time-string "%a %b %e 09:00:00 %Y"))
        (end-time (format-time-string "%a %b %e 17:00:00 %Y")))
    (if (or (and (string&lt; current-time start-time)
                 (string&lt; current-time end-time))
            (and (string&lt; start-time current-time)
                 (string&lt; end-time current-time)))
        (setq org-agenda-files
              (append oni:personal-agenda-files
                      oni:common-agenda-files))
      (setq org-agenda-files
            (append oni:work-agenda-files
                    oni:common-agenda-files)))))
</pre>
</div>

<p>
It's weird, but since Emacs doesn't have any real datetime functions
for creation/comparison, for as far as I know, it seemed easiest to
just create some strings representing the time and compare these.
</p>

<p>
Then it should be, if the current time is either before both start
and end time or after both start and end time it should return my
personal todo list, otherwise it should return my work todo list.
</p>

<p>
Now, it would be silly to have to call that manually every so-often,
so I've set it up to do so automatically.
</p>

<div class="org-src-container">
<pre class="src src-emacs-lisp">(oni:set-org-agenda-files)
(run-at-time "09:01" nil 'oni:set-org-agenda-files)
(run-at-time "17:01" nil 'oni:set-org-agenda-files)
</pre>
</div>

<p>
First, I set my agenda files to whatevers they should be <b>right now</b>.
Then I have this function run at 09:01 and 17:01, if either or both
have already passed, they won't be executed today.  This effectively
tells Emacs to switch to my work "role" after 09:00 and back to my
personal "role" after 17:00.
</p>

<p>
It's not perfect yet, but I felt like writing something.  The things
I would change might include:
</p>

<ul class="org-ul">
<li>Check the times for either <code>&lt;</code> or <code>=</code> the start/end times, so I don't
have to check for <code>:01</code> every time, but Emacs doesn't have a <code>string&lt;=</code>
function so I'll have to mimic it.</li>

<li>Always set it to my personal "role" during weekends.</li>

<li>Have them repeat every 24 hours, just in case I don't turn off my
PC for a few days.</li>
</ul>

<p>
I'll fix those soon, they're not hard to do, but this works for now.
It has worked well for me today, but I might throw it out again
tomorrow, as I sometimes tend to do.
</p>