Debian Codegraph @

vicious/widgets/org_all.lua

raw symbols SCIP
1 -- widget type providing agenda from Emacs org-mode
2 -- Copyright (C) 2010 Adrian C. <[email protected]>
3 -- Copyright (C) 2010 org-awesome, Damien Leone
4 -- Copyright (C) 2017 mutlusun <[email protected]>
5 --
6 -- This file is part of Vicious.
7 --
8 -- Vicious is free software: you can redistribute it and/or modify
9 -- it under the terms of the GNU General Public License as
10 -- published by the Free Software Foundation, either version 2 of the
11 -- License, or (at your option) any later version.
12 --
13 -- Vicious is distributed in the hope that it will be useful,
14 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
15 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 -- GNU General Public License for more details.
17 --
18 -- You should have received a copy of the GNU General Public License
19 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
20
21 -- {{{ Grab environment
22 local io = { lines = io.lines }
23 local os = { time = os.time, date = os.date }
24 local helpers = require"vicious.helpers"
25 -- }}}
26
27 -- {{{ OrgMode widget type
28 return helpers.setcall(function (format, warg)
29 if not warg then return end
30
31 -- Compute delays
32 local today = os.time{ year = os.date("%Y"), month = os.date("%m"),
33 day = os.date("%d") }
34 local soon = today + 24*3600*3 -- 3 days ahead is close
35 local future = today + 24*3600*7 -- 7 days ahead is maximum
36
37 -- Initialize counters
38 local count = { past = 0, today = 0, soon = 0, future = 0 }
39
40 -- Get data from agenda files
41 for i = 1,#warg do
42 for line in io.lines(warg[i]) do
43 local scheduled = line:find"SCHEDULED:"
44 local deadline = line:find"DEADLINE:"
45 local closed = line:find"CLOSED:"
46 local b, _, y, m, d = line:find"(%d%d%d%d)-(%d%d)-(%d%d)"
47
48 if (scheduled or deadline) and not closed and b then
49 local t = os.time{ year = y, month = m, day = d }
50 if t < today then
51 count.past = count.past + 1
52 elseif t == today then
53 count.today = count.today + 1
54 elseif t <= soon then
55 count.soon = count.soon + 1
56 elseif t <= future then
57 count.future = count.future + 1
58 end
59 end
60 end
61 end
62
63 return { count.past, count.today, count.soon, count.future }
64 end)
65 -- }}}