annotate lisp/calendar/timeclock.el @ 31163:35ee2cc673cd

Renamed from skkdic-utl.el. Provide ja-dic-utl instead of skkdic-utl. (skkdic-lookup-key): Load ja-dic/ja-dic, not skkdic/skkdic.
author Kenichi Handa <handa@m17n.org>
date Fri, 25 Aug 2000 01:47:27 +0000
parents 5b4027fef808
children 0abae260f337
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; timeclock.el --- mode for keeping track of how much you work
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: John Wiegley <johnw@gnu.org>
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Created: 25 Mar 1999
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Version: 2.2
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; Keywords: calendar data
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; X-URL: http://www.emacs.org/~johnw/emacs.html
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; any later version.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; This mode is for keeping track of time intervals. You can use it
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; for whatever purpose you like, but the typical scenario is to keep
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; track of how much time you spend working on certain projects.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;; Use `timeclock-in' when you start on a project, and `timeclock-out'
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; when you're done. Once you've collected some data, you can use
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; `timeclock-workday-remaining' to see how much time is left to be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; worked today (assuming a typical average of 8 hours a day), and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; `timeclock-when-to-leave' which will calculate when you're free.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; You'll probably want to bind the timeclock commands to some handy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; keystrokes. At the moment, C-x t is unused in Emacs 20:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; (require 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; (define-key ctl-x-map "ti" 'timeclock-in)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; (define-key ctl-x-map "to" 'timeclock-out)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; (define-key ctl-x-map "tc" 'timeclock-change)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; (define-key ctl-x-map "tr" 'timeclock-reread-log)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; (define-key ctl-x-map "tu" 'timeclock-update-modeline)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; (define-key ctl-x-map "tw" 'timeclock-when-to-leave-string)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; If you want Emacs to display the amount of time "left" to your
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; workday in the modeline, you can either set the value of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; `timeclock-modeline-display' to t using M-x customize, or you
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; can add this code to your .emacs file:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; (require 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; (timeclock-modeline-display)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; To cancel this modeline display at any time, just call
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; `timeclock-modeline-display' again.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; You may also want Emacs to ask you before exiting, if you are
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; current working on a project. This can be done either by setting
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; `timeclock-ask-before-exiting' to t using M-x customize (this is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;; the default), or by adding the following to your .emacs file:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;;
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;; (add-hook 'kill-emacs-hook 'timeclock-query-out)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; NOTE: If you change your .timelog file without using timeclock's
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;; functions, or if you change the value of any of timeclock's
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;; customizable variables, you should run the command
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; `timeclock-reread-log'. This will recompute any discrepancies in
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; your average working time, and will make sure that the various
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;; display functions return the correct value.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;;; History:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;;; Code:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 (defgroup timeclock nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 "Keeping track time of the time that gets spent."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 :group 'data)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ;;; User Variables:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86
30795
5b4027fef808 (timeclock-file): Run .timelog through convert-standard-filename.
Eli Zaretskii <eliz@gnu.org>
parents: 30781
diff changeset
87 (defcustom timeclock-file (convert-standard-filename "~/.timelog")
30781
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 "*The file used to store timeclock data in."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 :type 'file
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 (defcustom timeclock-workday (* 8 60 60)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 "*The length of a work period."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 :type 'integer
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 (defcustom timeclock-relative t
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 "*When reporting time, make it relative to `timeclock-workday'?
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 For example, if the length of a normal workday is eight hours, and you
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 work four hours on Monday, then the amount of time \"remaining\" on
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 Tuesday is twelve hours -- relative to an averaged work period of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 eight hours -- or eight hours, non-relative. So relative time takes
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 into account any discrepancy of time under-worked or overworked on
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 previous days."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 :type 'boolean
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 (defcustom timeclock-get-project-function 'timeclock-ask-for-project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 "*The function used to determine the name of the current project.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 When clocking in, and no project is specified, this function will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 called to determine what the current project to be worked on is.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 If this variable is nil, no questions will be asked."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 :type 'function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 (defcustom timeclock-get-reason-function 'timeclock-ask-for-reason
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 "*A function used to determine the reason for clocking out.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 When clocking out, and no reason is specified, this function will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 called to determine what the reason is.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 If this variable is nil, no questions will be asked."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 :type 'function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 (defcustom timeclock-get-workday-function nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 "*A function used to determine the length of today's workday.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 The first time that a user clocks in each day, this function will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 called to determine what the length of the current workday is. If
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 nil, or equal to `timeclock-workday', nothing special will be done.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 If it is a quantity different from `timeclock-workday', however, a
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 record will be output to the timelog file to note the fact that that
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 day has a different length from the norm."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 :type 'function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (defcustom timeclock-ask-before-exiting t
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 "*If non-nil, ask if the user wants to clock out before exiting Emacs."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 :set (lambda (symbol value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (if value
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (add-hook 'kill-emacs-hook 'timeclock-query-out)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (remove-hook 'kill-emacs-hook 'timeclock-query-out))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (setq timeclock-ask-before-exiting value))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 :type 'boolean
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (defvar timeclock-update-timer nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 "The timer used to update `timeclock-mode-string'.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (defcustom timeclock-use-display-time t
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 "*If non-nil, use `display-time-hook' for doing modeline updates.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 The advantage to this is that it means one less timer has to be set
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 running amok in Emacs' process space. The disadvantage is that it
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 requires you to have `display-time' running. If you don't want to use
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 `display-time', but still want the modeline to show how much time is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 left, set this variable to nil. You will need to restart Emacs (or
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 toggle the value of `timeclock-modeline-display') for the change to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 take effect."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 :set (lambda (symbol value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (let ((currently-displaying
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (and (boundp 'timeclock-modeline-display)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 timeclock-modeline-display)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 ;; if we're changing to the state that
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 ;; `timeclock-modeline-display' is already using, don't
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 ;; bother toggling it. This happens on the initial loading
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 ;; of timeclock.el.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (if (and currently-displaying
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (or (and value
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (boundp 'display-time-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (memq 'timeclock-update-modeline
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 display-time-hook))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (and (not value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 timeclock-update-timer)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (setq currently-displaying nil))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (and currently-displaying
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (set-variable timeclock-modeline-display nil))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (setq timeclock-use-display-time value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (and currently-displaying
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (set-variable timeclock-modeline-display t))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 timeclock-use-display-time))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 :type 'boolean
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 :group 'timeclock
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 :require 'time)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (defcustom timeclock-first-in-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 "*A hook run for the first \"in\" event each day.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 Note that this hook is run before recording any events. Thus the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 value of `timeclock-hours-today', `timeclock-last-event' and the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 return value of function `timeclock-last-period' are relative previous
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 to today."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (defcustom timeclock-load-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 "*Hook that gets run after timeclock has been loaded."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (defcustom timeclock-in-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 "*A hook run every time an \"in\" event is recorded."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (defcustom timeclock-day-over-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 "*A hook that is run when the workday has been completed.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 This hook is only run if the current time remaining is being display
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 in the modeline. See the variable `timeclock-modeline-display'."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (defcustom timeclock-out-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 "*A hook run every time an \"out\" event is recorded."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (defcustom timeclock-done-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 "*A hook run every time a project is marked as completed."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (defcustom timeclock-event-hook nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 "*A hook run every time any event is recorded."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 :type 'hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 :group 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (defvar timeclock-last-event nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 "A list containing the last event that was recorded.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 The format of this list is (CODE TIME PROJECT). PROJECT will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 non-nil only if CODE is \"o\" or \"O\".")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (defvar timeclock-last-event-workday nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 "The number of seconds in the workday of `timeclock-last-event'.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 ;;; Internal Variables:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (defvar timeclock-discrepancy nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 "A variable containing the time discrepancy before the last event.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 Normally, timeclock assumes that you intend to work for
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 `timeclock-workday' seconds every day. Any days in which you work
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 more or less than this amount is considered either a positive or
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 negative discrepancy. If you work in such a manner that the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 discrepancy is always brought back to zero, then you will by
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 definition have worked an average amount equal to `timeclock-workday'
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 each day.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (defvar timeclock-elapsed nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 "A variable containing the time elapsed for complete periods today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 This value is not accurate enough to be useful by itself. Rather,
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 call `timeclock-workday-elapsed', to determine how much time has been
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 worked so far today. Also, if `timeclock-relative' is nil, this value
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 will be the same as `timeclock-discrepancy'.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 (defvar timeclock-last-period nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 "Integer representing the number of seconds in the last period.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 Note that you shouldn't access this value, but should use the function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 `timeclock-last-period' instead.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (defvar timeclock-mode-string nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 "The timeclock string (optionally) displayed in the modeline.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (defvar timeclock-day-over nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 "The date of the last day when notified \"day over\" for.")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 ;;; User Functions:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (defun timeclock-modeline-display (&optional arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 "Toggle display of the amount of time left today in the modeline.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 If `timeclock-use-display-time' is non-nil, the modeline will be
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 updated whenever the time display is updated. Otherwise, the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 timeclock will use its own sixty second timer to do its updating.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 With prefix ARG, turn modeline display on if and only if ARG is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 positive. Returns the new status of timeclock modeline display
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 \(non-nil means on)."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (interactive "P")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (let ((on-p (if arg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (> (prefix-numeric-value arg) 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (not timeclock-modeline-display))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (if on-p
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (let ((list-entry (memq 'global-mode-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 mode-line-format)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (unless (memq 'timeclock-mode-string mode-line-format)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (setcdr list-entry
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (cons 'timeclock-mode-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (cdr list-entry))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (unless (memq 'timeclock-update-modeline timeclock-event-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (add-hook 'timeclock-event-hook 'timeclock-update-modeline))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (when timeclock-update-timer
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 (cancel-timer timeclock-update-timer)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (setq timeclock-update-timer nil))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (if (boundp 'display-time-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (remove-hook 'display-time-hook 'timeclock-update-modeline))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (if timeclock-use-display-time
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (add-hook 'display-time-hook 'timeclock-update-modeline)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (setq timeclock-update-timer
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (run-at-time nil 60 'timeclock-update-modeline))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (setq mode-line-format
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 (delq 'timeclock-mode-string mode-line-format))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (remove-hook 'timeclock-event-hook 'timeclock-update-modeline)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 (if (boundp 'display-time-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (remove-hook 'display-time-hook
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 'timeclock-update-modeline))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 (when timeclock-update-timer
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (cancel-timer timeclock-update-timer)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 (setq timeclock-update-timer nil)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (force-mode-line-update)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 on-p))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 ;; This has to be here so that the function definition of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 ;; `timeclock-modeline-display' is known to the "set" function.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 (defcustom timeclock-modeline-display nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 "Toggle modeline display of time remaining.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 You must modify via \\[customize] for this variable to have an effect."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 :set (lambda (symbol value)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (setq timeclock-modeline-display
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (timeclock-modeline-display (or value 0))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 :type 'boolean
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 :group 'timeclock
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 :require 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (defun timeclock-in (&optional arg project find-project)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 "Clock in, recording the current time moment in the timelog.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 With a numeric prefix ARG, record the fact that today has only that
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 many hours in it to be worked. If arg is a non-numeric prefix arg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 \(non-nil, but not a number), 0 is assumed (working on a holiday or
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 weekend). *If not called interactively, ARG should be the number of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 _seconds_ worked today*. This feature only has effect the first time
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 this function is called within a day.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 PROJECT as the project being clocked into. If PROJECT is nil, and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 FIND-PROJECT is non-nil -- or the user calls `timeclock-in'
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 interactively -- call the function `timeclock-get-project-function' to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 discover the name of the project."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (interactive
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (list (and current-prefix-arg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (if (numberp current-prefix-arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (* current-prefix-arg 60 60)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 0))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (if (equal (car timeclock-last-event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (error "You've already clocked in!")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (unless timeclock-last-event
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 (timeclock-reread-log))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (unless (equal (timeclock-time-to-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (cadr timeclock-last-event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 (timeclock-time-to-date (current-time)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (let ((workday (or (and (numberp arg) arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (and arg 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 (and timeclock-get-workday-function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (funcall timeclock-get-workday-function))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 timeclock-workday)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (run-hooks 'timeclock-first-in-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 ;; settle the discrepancy for the new day
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 (setq timeclock-discrepancy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (- timeclock-discrepancy workday))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (if (not (= workday timeclock-workday))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (timeclock-log "h" (and (numberp arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (number-to-string arg))))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 (timeclock-log "i" (or project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 (and timeclock-get-project-function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (or find-project (interactive-p))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 (funcall timeclock-get-project-function))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (run-hooks 'timeclock-in-hook)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 (defun timeclock-out (&optional arg reason find-reason)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 "Clock out, recording the current time moment in the timelog.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 If a prefix ARG is given, the user has completed the project that was
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 begun during the last time segment.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 REASON is the user's reason for clocking out. If REASON is nil, and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 FIND-REASON is non-nil -- or the user calls `timeclock-out'
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 interactively -- call the function `timeclock-get-reason-function' to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 discover the reason."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (interactive "P")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 (if (equal (downcase (car timeclock-last-event)) "o")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 (error "You've already clocked out!")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 (timeclock-log
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (if arg "O" "o")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 (or reason
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (and timeclock-get-reason-function
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 (or find-reason (interactive-p))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (funcall timeclock-get-reason-function))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (run-hooks 'timeclock-out-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 (if arg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (run-hooks 'timeclock-done-hook))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (defun timeclock-status-string (&optional show-seconds today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 "Report the overall timeclock status at the present moment."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (interactive "P")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 (let* ((remainder (timeclock-workday-remaining))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (last-in (equal (car timeclock-last-event) "i"))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 status)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 (setq status
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (format "Currently %s since %s (%s), %s %s, leave at %s"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (if last-in "IN" "OUT")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (if show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (format-time-string "%-I:%M:%S %p"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (nth 1 timeclock-last-event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 (format-time-string "%-I:%M %p"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (nth 1 timeclock-last-event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (or (nth 2 timeclock-last-event)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (if last-in "**UNKNOWN**" "workday over"))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (timeclock-seconds-to-string remainder show-seconds t)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (if (> remainder 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 "remaining" "over")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (timeclock-when-to-leave-string show-seconds today-only)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (if (interactive-p)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (message status)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 status)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (defun timeclock-change (&optional arg project)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 "Change to working on a different project, by clocking in then out.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 With a prefix ARG, consider the previous project as having been
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 finished at the time of changeover. PROJECT is the name of the last
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 project you were working on."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (interactive "P")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (timeclock-out arg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 (timeclock-in nil project (interactive-p)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 (defun timeclock-query-out ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 "Ask the user before clocking out.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 This is a useful function for adding to `kill-emacs-hook'."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 (if (and (equal (car timeclock-last-event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (y-or-n-p "You're currently clocking time, clock out? "))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 (timeclock-out)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (defun timeclock-reread-log ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 "Re-read the timeclock, to account for external changes.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 Returns the new value of `timeclock-discrepancy'."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (setq timeclock-discrepancy nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (timeclock-find-discrep)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (if timeclock-modeline-display
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 (timeclock-update-modeline))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 timeclock-discrepancy)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (defun timeclock-seconds-to-string (seconds &optional show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 reverse-leader)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 "Convert SECONDS into a compact time string.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 If SHOW-SECONDS is non-nil, make the resolution of the return string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 include the second count. If REVERSE-LEADER is non-nil, it means to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 output a \"+\" if the time value is negative, rather than a \"-\".
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 This is used when negative time values have an inverted meaning (such
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 as with time remaining, where negative time really means overtime)."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (if show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (format "%s%d:%02d:%02d"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (if (< seconds 0) (if reverse-leader "+" "-") "")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 (truncate (/ (abs seconds) 60 60))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (% (truncate (/ (abs seconds) 60)) 60)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 (% (truncate (abs seconds)) 60))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (format "%s%d:%02d"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (if (< seconds 0) (if reverse-leader "+" "-") "")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (truncate (/ (abs seconds) 60 60))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 (% (truncate (/ (abs seconds) 60)) 60))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 (defun timeclock-workday-remaining (&optional today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 "Return a the number of seconds until the workday is complete.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 The amount returned is relative to the value of `timeclock-workday'.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 If TODAY-ONLY is non-nil, the value returned will be relative only to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 the time worked today, and not to past time. This argument only makes
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 a difference if `timeclock-relative' is non-nil."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (- (timeclock-find-discrep today-only)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 (defun timeclock-currently-in-p ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 "Return non-nil if the user is currently clocked in."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (equal (car timeclock-last-event) "i"))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (defun timeclock-workday-remaining-string (&optional show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 "Return a string representing the amount of time left today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 Display second resolution if SHOW-SECONDS is non-nil. If TODAY-ONLY
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 is non-nil, the display will be relative only to time worked today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 See `timeclock-relative' for more information about the meaning of
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 \"relative to today\"."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 (let ((string (timeclock-seconds-to-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (timeclock-workday-remaining today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 show-seconds t)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (if (interactive-p)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484 (message string)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 string)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (defun timeclock-workday-elapsed (&optional relative)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 "Return a the number of seconds worked so far today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 If RELATIVE is non-nil, the amount returned will be relative to past
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 time worked. The default is to return only the time that has elapsed
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 so far today."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 (+ timeclock-workday
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 (timeclock-find-discrep (not relative))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 (defun timeclock-workday-elapsed-string (&optional show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 relative)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 "Return a string representing the amount of time worked today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 Display seconds resolution if SHOW-SECONDS is non-nil. If RELATIVE is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 non-nil, the amount returned will be relative to past time worked."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (let ((string (timeclock-seconds-to-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 (timeclock-workday-elapsed relative)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 show-seconds)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 (if (interactive-p)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (message string)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 string)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 (defun timeclock-when-to-leave (&optional today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 "Return a time value representing at when the workday ends today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 If TODAY-ONLY is non-nil, the value returned will be relative only to
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 the time worked today, and not to past time. This argument only makes
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 a difference if `timeclock-relative' is non-nil."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 (timeclock-seconds-to-time
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515 (- (timeclock-time-to-seconds (current-time))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 (timeclock-find-discrep today-only))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 ;;;###autoload
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (defun timeclock-when-to-leave-string (&optional show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521 "Return a string representing at what time the workday ends today.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 This string is relative to the value of `timeclock-workday'. If
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 NO-MESSAGE is non-nil, no messages will be displayed in the
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 minibuffer. If SHOW-SECONDS is non-nil, the value printed/returned
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 will include seconds. If TODAY-ONLY is non-nil, the value returned
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 will be relative only to the time worked today, and not to past time.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 This argument only makes a difference if `timeclock-relative' is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 non-nil."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 (let* ((then (timeclock-when-to-leave today-only))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 (string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 (if show-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 (format-time-string "%-I:%M:%S %p" then)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (format-time-string "%-I:%M %p" then))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (if (interactive-p)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 (message string)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 string)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539 ;;; Internal Functions:
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 (defvar timeclock-project-list nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
542 (defvar timeclock-last-project nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 (defun timeclock-ask-for-project ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 "Ask the user for the project they are clocking into."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 (completing-read (format "Clock into which project (default \"%s\"): "
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (or timeclock-last-project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 (car timeclock-project-list)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 (mapcar 'list timeclock-project-list)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 nil nil nil nil (or timeclock-last-project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 (car timeclock-project-list))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (defvar timeclock-reason-list nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (defun timeclock-ask-for-reason ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 "Ask the user for the reason they are clocking out."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 (completing-read "Reason for clocking out: "
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558 (mapcar 'list timeclock-reason-list)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 (defun timeclock-update-modeline ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 "Update the `timeclock-mode-string' displayed in the modeline."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 (interactive)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 (let* ((remainder (timeclock-workday-remaining))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564 (last-in (equal (car timeclock-last-event) "i")))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 (when (and (< remainder 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 (not (and timeclock-day-over
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 (equal timeclock-day-over
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 (timeclock-time-to-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 (current-time))))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570 (setq timeclock-day-over
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571 (timeclock-time-to-date (current-time)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 (run-hooks 'timeclock-day-over-hook))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 (setq timeclock-mode-string
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 (format " %c%s%c"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 (if last-in ?< ?[)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 (timeclock-seconds-to-string remainder nil t)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (if last-in ?> ?])))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 (defun timeclock-log (code &optional project)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 "Log the event CODE to the timeclock log, at the time of call.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 If PROJECT is a string, it represents the project which the event is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 being logged for. Normally only \"out\" events specify a project."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 (save-excursion
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 (set-buffer (find-file-noselect timeclock-file))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (goto-char (point-max))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 (if (not (bolp))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (insert "\n"))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 (let ((now (current-time)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 (insert code " "
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 (format-time-string "%Y/%m/%d %H:%M:%S" now)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 (or (and project
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 (stringp project)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 (> (length project) 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (concat " " project))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 "")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 "\n")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (if (equal (downcase code) "o")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (setq timeclock-last-period
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 (- (timeclock-time-to-seconds now)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (timeclock-time-to-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 (cadr timeclock-last-event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 timeclock-discrepancy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603 (+ timeclock-discrepancy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 timeclock-last-period)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605 (setq timeclock-last-event (list code now project)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 (save-buffer)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607 (run-hooks 'timeclock-event-hook)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
609 (defun timeclock-read-moment ()
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
610 "Read the moment under point from the timelog."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 (save-excursion
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 (beginning-of-line)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 (let ((eol (save-excursion (end-of-line) (point))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 (if (re-search-forward
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
615 (concat "^\\(.\\)\\s-+"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
616 "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)\\s-+"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617 "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\)\\s-*"
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
618 "\\(.*\\)") eol t)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619 (let ((code (match-string 1))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
620 (year (string-to-number (match-string 2)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
621 (mon (string-to-number (match-string 3)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 (mday (string-to-number (match-string 4)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (hour (string-to-number (match-string 5)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624 (min (string-to-number (match-string 6)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625 (sec (string-to-number (match-string 7)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 (project (match-string 8)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627 (list code (encode-time sec min hour mday mon year)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 project))))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630 (defun timeclock-time-to-seconds (time)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
631 "Convert TIME to a floating point number."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632 (+ (* (car time) 65536.0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 (cadr time)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 (/ (or (car (cdr (cdr time))) 0) 1000000.0)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 (defun timeclock-seconds-to-time (seconds)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 "Convert SECONDS (a floating point number) to an Emacs time structure."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 (list (floor seconds 65536)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639 (floor (mod seconds 65536))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640 (floor (* (- seconds (ffloor seconds)) 1000000))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 (defun timeclock-time-to-date (time)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 "Convert the TIME value to a textual date string."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644 (format-time-string "%Y/%m/%d" time))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 (defun timeclock-last-period (&optional moment)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 "Return the value of the last event period.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 If the last event was a clock-in, the period will be open ended, and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649 growing every second. Otherwise, it is a fixed amount which has been
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 recorded to disk. If MOMENT is non-nil, use that as the current time.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 This is only provided for coherency when used by
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652 `timeclock-discrepancy'."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 (if (equal (car timeclock-last-event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 (- (timeclock-time-to-seconds (or moment (current-time)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 (timeclock-time-to-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 (cadr timeclock-last-event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 timeclock-last-period))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
659 (defun timeclock-find-discrep (&optional today-only)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 "Find overall discrepancy from `timeclock-workday' (in seconds).
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 If TODAY-ONLY is non-nil, the discrepancy will be not be relative, and
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 will correspond only to the amount of time elapsed today. This is
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 identical to what would be return if `timeclock-relative' were nil."
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664 (let* ((now (current-time)) (first t)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
665 (todays-date (timeclock-time-to-date now))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
666 accum event beg last-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667 last-date-limited last-date-seconds avg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 (unless timeclock-discrepancy
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669 (setq timeclock-project-list nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670 timeclock-last-project nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
671 timeclock-reason-list nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
672 (save-excursion
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
673 (set-buffer (find-file-noselect timeclock-file))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 (goto-char (point-min))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 (setq accum 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
676 (setq timeclock-elapsed 0)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677 (while (setq event (timeclock-read-moment))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
678 (cond ((equal (car event) "h")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 (setq last-date-limited
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 (timeclock-time-to-date (cadr event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
681 last-date-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
682 (string-to-number (nth 2 event))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
683 ((equal (car event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
684 (when (and (nth 2 event)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
685 (> (length (nth 2 event)) 0))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
686 (add-to-list 'timeclock-project-list (nth 2 event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
687 (setq timeclock-last-project (nth 2 event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
688 (let ((date (timeclock-time-to-date (cadr event))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
689 (if (and last-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
690 timeclock-relative
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
691 (not (equal date last-date)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
692 (setq accum (- accum
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
693 (if last-date-limited
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694 last-date-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
695 timeclock-workday)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
696 (unless (or last-date (not first))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
697 (setq first nil
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
698 accum (- accum
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
699 (if last-date-limited
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
700 last-date-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
701 timeclock-workday)))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
702 (setq last-date date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
703 last-date-limited nil)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
704 (if beg
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
705 (error "Error in format of timelog file!")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
706 (setq beg (timeclock-time-to-seconds (cadr event))))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707 ((equal (downcase (car event)) "o")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
708 (if (and (nth 2 event)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
709 (> (length (nth 2 event)) 0))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
710 (add-to-list 'timeclock-reason-list (nth 2 event)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
711 (if (or timeclock-relative
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
712 (equal last-date todays-date))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
713 (if (not beg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
714 (error "Error in format of timelog file!")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
715 (setq timeclock-last-period
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
716 (- (timeclock-time-to-seconds (cadr event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
717 beg)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
718 accum (+ timeclock-last-period accum)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
719 beg nil)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
720 (if (equal last-date todays-date)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
721 (setq timeclock-elapsed
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
722 (+ timeclock-last-period timeclock-elapsed)))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
723 (setq timeclock-last-event event
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
724 timeclock-last-event-workday
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
725 (if (equal (timeclock-time-to-date now)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
726 last-date-limited)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
727 last-date-seconds
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
728 timeclock-workday))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
729 (forward-line))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
730 (setq timeclock-discrepancy accum)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
731 (setq accum (if today-only
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
732 timeclock-elapsed
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
733 timeclock-discrepancy))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
734 (if timeclock-last-event
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
735 (if (equal (car timeclock-last-event) "i")
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
736 (setq accum (+ accum (timeclock-last-period now)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
737 (if (not (equal (timeclock-time-to-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
738 (cadr timeclock-last-event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
739 (timeclock-time-to-date now)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
740 (setq accum (- accum timeclock-last-event-workday)))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
741 (setq accum
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
742 (- accum
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
743 (if (and timeclock-last-event
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
744 (equal (timeclock-time-to-date
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
745 (cadr timeclock-last-event))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
746 (timeclock-time-to-date now)))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
747 timeclock-last-event-workday
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
748 timeclock-workday)))))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
749
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
750 (provide 'timeclock)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
751
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
752 (run-hooks 'timeclock-load-hook)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
753
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
754 ;; make sure we know the list of reasons, projects, and have computed
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
755 ;; the last event and current discrepancy.
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
756 (if (file-readable-p timeclock-file)
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
757 (timeclock-reread-log))
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
758
59479ef35bf2 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
759 ;;; timeclock.el ends here