2008-04-03 11:58:13 -04:00
|
|
|
;;; org-clock.el --- The time clocking code for Org-mode
|
|
|
|
|
2015-01-01 17:26:41 -05:00
|
|
|
;; Copyright (C) 2004-2015 Free Software Foundation, Inc.
|
2008-04-03 11:58:13 -04:00
|
|
|
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
|
|
|
;;
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 08:45:52 -04:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2008-04-03 11:58:13 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:45:52 -04:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2008-04-03 11:58:13 -04:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 08:45:52 -04:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2008-04-03 11:58:13 -04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This file contains the time clocking code for Org-mode
|
|
|
|
|
2010-07-15 16:26:51 -04:00
|
|
|
;;; Code:
|
|
|
|
|
2008-04-03 11:58:13 -04:00
|
|
|
(eval-when-compile
|
2010-04-18 10:47:57 -04:00
|
|
|
(require 'cl))
|
2013-01-27 18:02:51 -05:00
|
|
|
(require 'org)
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2015-01-12 06:35:10 -05:00
|
|
|
(declare-function calendar-iso-to-absolute "cal-iso" (&optional date))
|
2010-09-07 13:55:30 -04:00
|
|
|
(declare-function notifications-notify "notifications" (&rest params))
|
2011-07-18 13:25:10 -04:00
|
|
|
(declare-function org-pop-to-buffer-same-window "org-compat" (&optional buffer-or-name norecord label))
|
2014-09-20 16:33:05 -04:00
|
|
|
(declare-function org-element-property "org-element" (property element))
|
|
|
|
(declare-function org-element-type "org-element" (element))
|
2014-04-17 04:19:58 -04:00
|
|
|
(declare-function org-table-goto-line "org-table" (n))
|
2008-10-28 04:52:52 -04:00
|
|
|
(defvar org-time-stamp-formats)
|
2011-07-09 12:12:18 -04:00
|
|
|
(defvar org-ts-what)
|
2012-05-05 08:21:13 -04:00
|
|
|
(defvar org-frame-title-format-backup frame-title-format)
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2008-04-18 10:43:48 -04:00
|
|
|
(defgroup org-clock nil
|
|
|
|
"Options concerning clocking working time in Org-mode."
|
|
|
|
:tag "Org Clock"
|
|
|
|
:group 'org-progress)
|
|
|
|
|
2014-12-14 12:22:31 -05:00
|
|
|
(defcustom org-clock-into-drawer t
|
|
|
|
"Non-nil when clocking info should be wrapped into a drawer.
|
|
|
|
|
|
|
|
When non-nil, clocking info will be inserted into the same drawer
|
|
|
|
as log notes (see variable `org-log-into-drawer'), if it exists,
|
|
|
|
or \"LOGBOOK\" otherwise. If necessary, the drawer will be
|
|
|
|
created.
|
|
|
|
|
|
|
|
When an integer, the drawer is created only when the number of
|
|
|
|
clocking entries in an item reaches or exceeds this value.
|
|
|
|
|
|
|
|
When a string, it becomes the name of the drawer, ignoring the
|
|
|
|
log notes drawer altogether.
|
|
|
|
|
|
|
|
Do not check directly this variable in a Lisp program. Call
|
|
|
|
function `org-clock-into-drawer' instead."
|
2008-04-03 11:58:13 -04:00
|
|
|
:group 'org-todo
|
2008-04-18 10:43:48 -04:00
|
|
|
:group 'org-clock
|
2014-12-14 12:22:31 -05:00
|
|
|
:version "25.1"
|
|
|
|
:package-version '(Org . "8.3")
|
2008-04-03 11:58:13 -04:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "Always" t)
|
|
|
|
(const :tag "Only when drawer exists" nil)
|
2009-02-14 19:15:37 -05:00
|
|
|
(integer :tag "When at least N clock entries")
|
|
|
|
(const :tag "Into LOGBOOK drawer" "LOGBOOK")
|
|
|
|
(string :tag "Into Drawer named...")))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2011-06-27 06:12:23 -04:00
|
|
|
(defun org-clock-into-drawer ()
|
2014-12-14 12:22:31 -05:00
|
|
|
"Value of `org-clock-into-drawer'. but let properties overrule.
|
|
|
|
|
2011-06-27 06:12:23 -04:00
|
|
|
If the current entry has or inherits a CLOCK_INTO_DRAWER
|
2014-12-14 12:22:31 -05:00
|
|
|
property, it will be used instead of the default value.
|
|
|
|
|
|
|
|
Return value is either a string, an integer, or nil."
|
|
|
|
(let ((p (org-entry-get nil "CLOCK_INTO_DRAWER" 'inherit t)))
|
2014-10-16 15:17:00 -04:00
|
|
|
(cond ((equal p "nil") nil)
|
2014-12-14 12:22:31 -05:00
|
|
|
((equal p "t") (or (org-log-into-drawer) "LOGBOOK"))
|
|
|
|
((org-string-nw-p p)
|
|
|
|
(if (org-string-match-p "\\`[0-9]+\\'" p) (string-to-number p) p))
|
|
|
|
((org-string-nw-p org-clock-into-drawer))
|
2015-02-27 18:43:37 -05:00
|
|
|
((integerp org-clock-into-drawer) org-clock-into-drawer)
|
2014-12-14 12:22:31 -05:00
|
|
|
((not org-clock-into-drawer) nil)
|
|
|
|
((org-log-into-drawer))
|
|
|
|
(t "LOGBOOK"))))
|
2011-06-27 06:12:23 -04:00
|
|
|
|
2008-04-03 11:58:13 -04:00
|
|
|
(defcustom org-clock-out-when-done t
|
2009-04-14 03:50:05 -04:00
|
|
|
"When non-nil, clock will be stopped when the clocked entry is marked DONE.
|
2015-09-21 00:23:15 -04:00
|
|
|
\\<org-mode-map>\
|
2010-01-15 12:16:07 -05:00
|
|
|
DONE here means any DONE-like state.
|
2010-01-21 10:15:40 -05:00
|
|
|
A nil value means clock will keep running until stopped explicitly with
|
2015-09-21 00:23:15 -04:00
|
|
|
`\\[org-clock-out]', or until the clock is started in a different item.
|
2010-01-15 12:16:07 -05:00
|
|
|
Instead of t, this can also be a list of TODO states that should trigger
|
|
|
|
clocking out."
|
2008-04-18 10:43:48 -04:00
|
|
|
:group 'org-clock
|
2010-01-15 12:16:07 -05:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "No" nil)
|
|
|
|
(const :tag "Yes, when done" t)
|
|
|
|
(repeat :tag "State list"
|
|
|
|
(string :tag "TODO keyword"))))
|
2008-04-18 10:43:48 -04:00
|
|
|
|
2012-12-29 12:45:07 -05:00
|
|
|
(defcustom org-clock-rounding-minutes 0
|
|
|
|
"Rounding minutes when clocking in or out.
|
|
|
|
The default value is 0 so that no rounding is done.
|
|
|
|
When set to a non-integer value, use the car of
|
|
|
|
`org-time-stamp-rounding-minutes', like for setting a time-stamp.
|
|
|
|
|
|
|
|
E.g. if `org-clock-rounding-minutes' is set to 5, time is 14:47
|
|
|
|
and you clock in: then the clock starts at 14:45. If you clock
|
|
|
|
out within the next 5 minutes, the clock line will be removed;
|
|
|
|
if you clock out 8 minutes after your clocked in, the clock
|
|
|
|
out time will be 14:50."
|
|
|
|
:group 'org-clock
|
2013-02-26 12:21:28 -05:00
|
|
|
:version "24.4"
|
|
|
|
:package-version '(Org . "8.0")
|
2012-12-29 12:45:07 -05:00
|
|
|
:type '(choice
|
|
|
|
(integer :tag "Minutes (0 for no rounding)")
|
|
|
|
(symbol :tag "Use `org-time-stamp-rounding-minutes'" 'same-as-time-stamp)))
|
|
|
|
|
2008-04-18 10:43:48 -04:00
|
|
|
(defcustom org-clock-out-remove-zero-time-clocks nil
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means remove the clock line when the resulting time is zero."
|
2008-04-18 10:43:48 -04:00
|
|
|
:group 'org-clock
|
2008-04-03 11:58:13 -04:00
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-clock-in-switch-to-state nil
|
|
|
|
"Set task to a special todo state while clocking it.
|
2008-10-16 12:26:43 -04:00
|
|
|
The value should be the state to which the entry should be
|
2010-07-15 16:26:51 -04:00
|
|
|
switched. If the value is a function, it must take one
|
2008-10-16 12:26:43 -04:00
|
|
|
parameter (the current TODO state of the item) and return the
|
|
|
|
state to switch it to."
|
2008-04-18 10:43:48 -04:00
|
|
|
:group 'org-clock
|
2008-04-03 11:58:13 -04:00
|
|
|
:group 'org-todo
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Don't force a state" nil)
|
2008-10-16 12:26:43 -04:00
|
|
|
(string :tag "State")
|
|
|
|
(symbol :tag "Function")))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2009-06-02 11:01:11 -04:00
|
|
|
(defcustom org-clock-out-switch-to-state nil
|
|
|
|
"Set task to a special todo state after clocking out.
|
|
|
|
The value should be the state to which the entry should be
|
2010-07-15 16:26:51 -04:00
|
|
|
switched. If the value is a function, it must take one
|
2009-06-02 11:01:11 -04:00
|
|
|
parameter (the current TODO state of the item) and return the
|
|
|
|
state to switch it to."
|
|
|
|
:group 'org-clock
|
|
|
|
:group 'org-todo
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Don't force a state" nil)
|
|
|
|
(string :tag "State")
|
|
|
|
(symbol :tag "Function")))
|
|
|
|
|
2008-04-25 13:59:51 -04:00
|
|
|
(defcustom org-clock-history-length 5
|
|
|
|
"Number of clock tasks to remember in history."
|
|
|
|
:group 'org-clock
|
|
|
|
:type 'integer)
|
|
|
|
|
2009-04-22 00:41:15 -04:00
|
|
|
(defcustom org-clock-goto-may-find-recent-task t
|
2010-01-21 10:15:40 -05:00
|
|
|
"Non-nil means `org-clock-goto' can go to recent task if no active clock."
|
2009-04-22 00:41:15 -04:00
|
|
|
:group 'org-clock
|
|
|
|
:type 'boolean)
|
|
|
|
|
2008-04-03 11:58:13 -04:00
|
|
|
(defcustom org-clock-heading-function nil
|
|
|
|
"When non-nil, should be a function to create `org-clock-heading'.
|
|
|
|
This is the string shown in the mode line when a clock is running.
|
|
|
|
The function is called with point at the beginning of the headline."
|
2008-04-18 10:43:48 -04:00
|
|
|
:group 'org-clock
|
2013-05-09 09:19:02 -04:00
|
|
|
:type '(choice (const nil) (function)))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2008-09-21 01:35:01 -04:00
|
|
|
(defcustom org-clock-string-limit 0
|
2012-06-03 04:28:46 -04:00
|
|
|
"Maximum length of clock strings in the mode line. 0 means no limit."
|
2008-09-21 01:35:01 -04:00
|
|
|
:group 'org-clock
|
|
|
|
:type 'integer)
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2008-10-22 21:31:37 -04:00
|
|
|
(defcustom org-clock-in-resume nil
|
2009-04-14 03:50:05 -04:00
|
|
|
"If non-nil, resume clock when clocking into task with open clock.
|
|
|
|
When clocking into a task with a clock entry which has not been closed,
|
|
|
|
the clock can be resumed from that point."
|
2008-10-22 21:31:37 -04:00
|
|
|
:group 'org-clock
|
|
|
|
:type 'boolean)
|
|
|
|
|
2008-10-22 21:35:58 -04:00
|
|
|
(defcustom org-clock-persist nil
|
2010-07-15 16:26:51 -04:00
|
|
|
"When non-nil, save the running clock when Emacs is closed.
|
|
|
|
The clock is resumed when Emacs restarts.
|
2008-11-20 11:54:26 -05:00
|
|
|
When this is t, both the running clock, and the entire clock
|
|
|
|
history are saved. When this is the symbol `clock', only the
|
2012-12-28 05:06:57 -05:00
|
|
|
running clock is saved. When this is the symbol `history', only
|
|
|
|
the clock history is saved.
|
2008-11-20 11:54:26 -05:00
|
|
|
|
2012-12-28 05:06:57 -05:00
|
|
|
When Emacs restarts with saved clock information, the file containing
|
|
|
|
the running clock as well as all files mentioned in the clock history
|
|
|
|
will be visited.
|
|
|
|
|
|
|
|
All this depends on running `org-clock-persistence-insinuate' in your
|
|
|
|
Emacs initialization file."
|
2008-10-22 21:35:58 -04:00
|
|
|
:group 'org-clock
|
2008-11-20 11:54:26 -05:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "Just the running clock" clock)
|
2009-10-24 08:36:19 -04:00
|
|
|
(const :tag "Just the history" history)
|
2008-11-20 11:54:26 -05:00
|
|
|
(const :tag "Clock and history" t)
|
|
|
|
(const :tag "No persistence" nil)))
|
2008-10-22 21:35:58 -04:00
|
|
|
|
Better implementation of unique entry IDs.
Unique identifiers for entries can now be used more efficiently.
Internally, a hash array has replaced the alist used so far to
keep track of the files in which an ID is defined. This makes it
quite fast to find an entry by ID.
There is now a new link type which looks like this:
id:GLOBALLY-UNIQUE-IDENTIFIER
This link points to a specific entry. When you move the entry to
a different file, for example if you move it to an archive
file, this link will continue to work.
The file /org-id.el/ contains an API that can be used to write
code using these identifiers, including creating IDs and finding
them wherever they are.
Org has its own method to create unique identifiers, but if the
system has /uuidgen/ command installed (Mac's and Linux systems
generally do), it will be used by default. You an also select
the method by hand, using the variable =org-id-method=.
If the ID system ever gets confused about where a certain ID is,
it initiates a global scan of all agenda files with associated
archives, all files previously known containing any IDs, and all
currently visited Org-mode files to rebuild the hash. You can
also initiate this by hand: =M-x org-id-update-id-locations=.
Running this command will also dump into the =*Messages*= buffer
information about any duplicate IDs. These should not exist, but
if you /copy/ an entry with its properties, duplicate IDs will
inevitably be produced. This is unavoidable in a plain text
system that allows you to edit the text in arbitrary ways, and a
portion of care on your side is needed to keep this system clean.
The hash is stored in the file =~/.emacs.d/.org-id-locations=.
This is also a change from previous versions where the file was
=~/.org=id-locations=. Therefore, you can remove this old file
if you have it. I am not sure what will happen if the =.emacs.d=
directory does not exists in your setup, but in modern Emacsen, I
believe it should exist. If you do not want to use IDs across
files, you can avoid the overhead with tracking IDs by
customizing the variable =org-id-track-globally=. IDs can then
still be used for links inside a single file.
IDs will also be used when you create a new link to an Org-mode
buffer. If you use =org-store-link= (normally at =C-c l=) inside
en entry in an Org-mode buffer, and ID property will be created
if it does not exist, and the stored link will be an =id:= link.
If you prefer the much less secure linking to headline text, you
can configure the variable =org-link-to-org-use-id=. The default
setting for this variable is =create-if-interactive=, meaning
that an ID will be created when you store a link interactively,
but not if you happen to be in an Org-mode file while you create
a remember note (which usually has a link to the place where you
were when starting remember).
2008-12-05 17:35:26 -05:00
|
|
|
(defcustom org-clock-persist-file (convert-standard-filename
|
2013-01-09 10:41:12 -05:00
|
|
|
(concat user-emacs-directory "org-clock-save.el"))
|
2009-04-14 03:50:05 -04:00
|
|
|
"File to save clock data to."
|
2008-10-22 21:35:58 -04:00
|
|
|
:group 'org-clock
|
|
|
|
:type 'string)
|
|
|
|
|
|
|
|
(defcustom org-clock-persist-query-save nil
|
2009-04-14 03:50:05 -04:00
|
|
|
"When non-nil, ask before saving the current clock on exit."
|
2008-10-22 21:35:58 -04:00
|
|
|
:group 'org-clock
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-clock-persist-query-resume t
|
2009-04-14 03:50:05 -04:00
|
|
|
"When non-nil, ask before resuming any stored clock during load."
|
2008-10-22 21:35:58 -04:00
|
|
|
:group 'org-clock
|
|
|
|
:type 'boolean)
|
|
|
|
|
2009-05-25 16:01:34 -04:00
|
|
|
(defcustom org-clock-sound nil
|
2012-09-26 09:52:21 -04:00
|
|
|
"Sound to use for notifications.
|
|
|
|
Possible values are:
|
2009-05-25 16:01:34 -04:00
|
|
|
|
2012-09-26 09:52:21 -04:00
|
|
|
nil No sound played
|
|
|
|
t Standard Emacs beep
|
|
|
|
file name Play this sound file, fall back to beep"
|
2009-05-28 07:24:23 -04:00
|
|
|
:group 'org-clock
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "No sound" nil)
|
|
|
|
(const :tag "Standard beep" t)
|
2012-09-26 09:52:21 -04:00
|
|
|
(file :tag "Play sound file")))
|
2009-05-25 16:01:34 -04:00
|
|
|
|
2013-01-13 03:19:24 -05:00
|
|
|
(define-obsolete-variable-alias 'org-clock-modeline-total
|
2012-10-24 05:21:44 -04:00
|
|
|
'org-clock-mode-line-total "24.3")
|
|
|
|
|
|
|
|
(defcustom org-clock-mode-line-total 'auto
|
2012-06-03 04:28:46 -04:00
|
|
|
"Default setting for the time included for the mode line clock.
|
2009-06-02 07:12:43 -04:00
|
|
|
This can be overruled locally using the CLOCK_MODELINE_TOTAL property.
|
|
|
|
Allowed values are:
|
|
|
|
|
|
|
|
current Only the time in the current instance of the clock
|
2009-11-12 07:39:29 -05:00
|
|
|
today All time clocked into this task today
|
2009-06-02 07:12:43 -04:00
|
|
|
repeat All time clocked into this task since last repeat
|
|
|
|
all All time ever recorded for this task
|
2009-10-02 02:30:18 -04:00
|
|
|
auto Automatically, either `all', or `repeat' for repeating tasks"
|
2009-06-02 07:12:43 -04:00
|
|
|
:group 'org-clock
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Current clock" current)
|
|
|
|
(const :tag "Today's task time" today)
|
|
|
|
(const :tag "Since last repeat" repeat)
|
|
|
|
(const :tag "All task time" all)
|
|
|
|
(const :tag "Automatically, `all' or since `repeat'" auto)))
|
|
|
|
|
2013-03-14 08:53:52 -04:00
|
|
|
(org-defvaralias 'org-task-overrun-text 'org-clock-task-overrun-text)
|
2012-04-10 19:14:21 -04:00
|
|
|
(defcustom org-clock-task-overrun-text nil
|
2012-06-03 04:28:46 -04:00
|
|
|
"Extra mode line text to indicate that the clock is overrun.
|
2010-01-23 04:41:13 -05:00
|
|
|
The can be nil to indicate that instead of adding text, the clock time
|
2010-01-26 16:39:21 -05:00
|
|
|
should get a different face (`org-mode-line-clock-overrun').
|
2010-01-23 04:41:13 -05:00
|
|
|
When this is a string, it is prepended to the clock string as an indication,
|
2010-01-26 16:39:21 -05:00
|
|
|
also using the face `org-mode-line-clock-overrun'."
|
2010-01-23 04:41:13 -05:00
|
|
|
:group 'org-clock
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2010-01-23 04:41:13 -05:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "Just mark the time string" nil)
|
|
|
|
(string :tag "Text to prepend")))
|
|
|
|
|
2009-07-23 11:33:52 -04:00
|
|
|
(defcustom org-show-notification-handler nil
|
|
|
|
"Function or program to send notification with.
|
|
|
|
The function or program will be called with the notification
|
|
|
|
string as argument."
|
|
|
|
:group 'org-clock
|
|
|
|
:type '(choice
|
2013-05-09 09:19:02 -04:00
|
|
|
(const nil)
|
2009-07-23 11:33:52 -04:00
|
|
|
(string :tag "Program")
|
|
|
|
(function :tag "Function")))
|
|
|
|
|
2010-11-01 08:30:44 -04:00
|
|
|
(defgroup org-clocktable nil
|
|
|
|
"Options concerning the clock table in Org-mode."
|
|
|
|
:tag "Org Clock Table"
|
|
|
|
:group 'org-clock)
|
|
|
|
|
|
|
|
(defcustom org-clocktable-defaults
|
2012-05-30 06:35:38 -04:00
|
|
|
(list
|
|
|
|
:maxlevel 2
|
2013-01-27 18:02:51 -05:00
|
|
|
:lang (or (org-bound-and-true-p org-export-default-language) "en")
|
2012-05-30 06:35:38 -04:00
|
|
|
:scope 'file
|
|
|
|
:block nil
|
2012-12-29 06:35:18 -05:00
|
|
|
:wstart 1
|
2013-03-15 06:17:12 -04:00
|
|
|
:mstart 1
|
2012-05-30 06:35:38 -04:00
|
|
|
:tstart nil
|
|
|
|
:tend nil
|
|
|
|
:step nil
|
|
|
|
:stepskip0 nil
|
|
|
|
:fileskip0 nil
|
|
|
|
:tags nil
|
|
|
|
:emphasize nil
|
|
|
|
:link nil
|
|
|
|
:narrow '40!
|
|
|
|
:indent t
|
|
|
|
:formula nil
|
|
|
|
:timestamp nil
|
|
|
|
:level nil
|
|
|
|
:tcolumns nil
|
|
|
|
:formatter nil)
|
2010-11-01 08:30:44 -04:00
|
|
|
"Default properties for clock tables."
|
2009-09-17 02:33:54 -04:00
|
|
|
:group 'org-clock
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2009-09-17 02:33:54 -04:00
|
|
|
:type 'plist)
|
|
|
|
|
2010-11-01 08:30:44 -04:00
|
|
|
(defcustom org-clock-clocktable-formatter 'org-clocktable-write-default
|
2010-11-11 11:43:52 -05:00
|
|
|
"Function to turn clocking data into a table.
|
2010-11-01 08:30:44 -04:00
|
|
|
For more information, see `org-clocktable-write-default'."
|
|
|
|
:group 'org-clocktable
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2010-11-01 08:30:44 -04:00
|
|
|
:type 'function)
|
|
|
|
|
2011-03-17 06:22:00 -04:00
|
|
|
;; FIXME: translate es and nl last string "Clock summary at"
|
2011-02-13 07:57:06 -05:00
|
|
|
(defcustom org-clock-clocktable-language-setup
|
2011-03-17 06:22:00 -04:00
|
|
|
'(("en" "File" "L" "Timestamp" "Headline" "Time" "ALL" "Total time" "File time" "Clock summary at")
|
|
|
|
("es" "Archivo" "N" "Fecha y hora" "Tarea" "Tiempo" "TODO" "Tiempo total" "Tiempo archivo" "Clock summary at")
|
|
|
|
("fr" "Fichier" "N" "Horodatage" "En-tête" "Durée" "TOUT" "Durée totale" "Durée fichier" "Horodatage sommaire à")
|
|
|
|
("nl" "Bestand" "N" "Tijdstip" "Hoofding" "Duur" "ALLES" "Totale duur" "Bestandstijd" "Clock summary at"))
|
2011-02-13 07:57:06 -05:00
|
|
|
"Terms used in clocktable, translated to different languages."
|
|
|
|
:group 'org-clocktable
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2011-02-13 07:57:06 -05:00
|
|
|
:type 'alist)
|
|
|
|
|
2010-11-01 08:30:44 -04:00
|
|
|
(defcustom org-clock-clocktable-default-properties '(:maxlevel 2 :scope file)
|
|
|
|
"Default properties for new clocktables.
|
|
|
|
These will be inserted into the BEGIN line, to make it easy for users to
|
|
|
|
play with them."
|
|
|
|
:group 'org-clocktable
|
|
|
|
:type 'plist)
|
|
|
|
|
2009-10-16 22:28:15 -04:00
|
|
|
(defcustom org-clock-idle-time nil
|
|
|
|
"When non-nil, resolve open clocks if the user is idle more than X minutes."
|
|
|
|
:group 'org-clock
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Never" nil)
|
|
|
|
(integer :tag "After N minutes")))
|
|
|
|
|
2009-10-25 18:03:23 -04:00
|
|
|
(defcustom org-clock-auto-clock-resolution 'when-no-clock-is-running
|
|
|
|
"When to automatically resolve open clocks found in Org buffers."
|
2009-10-19 16:53:45 -04:00
|
|
|
:group 'org-clock
|
2009-10-25 18:03:23 -04:00
|
|
|
:type '(choice
|
|
|
|
(const :tag "Never" nil)
|
|
|
|
(const :tag "Always" t)
|
|
|
|
(const :tag "When no clock is running" when-no-clock-is-running)))
|
2009-10-19 16:53:45 -04:00
|
|
|
|
2010-02-27 07:21:31 -05:00
|
|
|
(defcustom org-clock-report-include-clocking-task nil
|
|
|
|
"When non-nil, include the current clocking task time in clock reports."
|
|
|
|
:group 'org-clock
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2010-02-27 07:21:31 -05:00
|
|
|
:type 'boolean)
|
|
|
|
|
2010-05-16 11:42:53 -04:00
|
|
|
(defcustom org-clock-resolve-expert nil
|
|
|
|
"Non-nil means do not show the splash buffer with the clock resolver."
|
|
|
|
:group 'org-clock
|
2012-03-19 16:38:12 -04:00
|
|
|
:version "24.1"
|
2010-05-16 11:42:53 -04:00
|
|
|
:type 'boolean)
|
|
|
|
|
2012-07-12 08:04:54 -04:00
|
|
|
(defcustom org-clock-continuously nil
|
|
|
|
"Non-nil means to start clocking from the last clock-out time, if any."
|
|
|
|
:type 'boolean
|
|
|
|
:version "24.1"
|
|
|
|
:group 'org-clock)
|
|
|
|
|
2012-03-27 18:49:55 -04:00
|
|
|
(defcustom org-clock-total-time-cell-format "*%s*"
|
|
|
|
"Format string for the total time cells."
|
|
|
|
:group 'org-clock
|
|
|
|
:version "24.1"
|
2013-08-08 08:32:01 -04:00
|
|
|
:type 'string)
|
2012-03-27 18:49:55 -04:00
|
|
|
|
2012-04-20 07:06:46 -04:00
|
|
|
(defcustom org-clock-file-time-cell-format "*%s*"
|
|
|
|
"Format string for the file time cells."
|
|
|
|
:group 'org-clock
|
|
|
|
:version "24.1"
|
2013-08-08 08:32:01 -04:00
|
|
|
:type 'string)
|
2012-04-20 07:06:46 -04:00
|
|
|
|
2012-02-29 12:04:22 -05:00
|
|
|
(defcustom org-clock-clocked-in-display 'mode-line
|
|
|
|
"When clocked in for a task, org-mode can display the current
|
|
|
|
task and accumulated time in the mode line and/or frame title.
|
|
|
|
Allowed values are:
|
|
|
|
|
|
|
|
both displays in both mode line and frame title
|
|
|
|
mode-line displays only in mode line (default)
|
|
|
|
frame-title displays only in frame title
|
|
|
|
nil current clock is not displayed"
|
|
|
|
:group 'org-clock
|
|
|
|
:type '(choice
|
|
|
|
(const :tag "Mode line" mode-line)
|
|
|
|
(const :tag "Frame title" frame-title)
|
|
|
|
(const :tag "Both" both)
|
|
|
|
(const :tag "None" nil)))
|
|
|
|
|
2012-05-05 08:21:13 -04:00
|
|
|
(defcustom org-clock-frame-title-format '(t org-mode-line-string)
|
|
|
|
"The value for `frame-title-format' when clocking in.
|
|
|
|
|
2015-09-21 00:23:36 -04:00
|
|
|
When `org-clock-clocked-in-display' is set to `frame-title'
|
|
|
|
or `both', clocking in will replace `frame-title-format' with
|
2012-05-05 08:21:13 -04:00
|
|
|
this value. Clocking out will restore `frame-title-format'.
|
|
|
|
|
|
|
|
`org-frame-title-string' is a format string using the same
|
|
|
|
specifications than `frame-title-format', which see."
|
|
|
|
:version "24.1"
|
|
|
|
:group 'org-clock
|
|
|
|
:type 'sexp)
|
|
|
|
|
2013-01-11 17:16:45 -05:00
|
|
|
(defcustom org-clock-x11idle-program-name "x11idle"
|
|
|
|
"Name of the program which prints X11 idle time in milliseconds.
|
|
|
|
|
|
|
|
You can find x11idle.c in the contrib/scripts directory of the
|
|
|
|
Org git distribution. Or, you can do:
|
|
|
|
|
|
|
|
sudo apt-get install xprintidle
|
|
|
|
|
|
|
|
if you are using Debian."
|
|
|
|
:group 'org-clock
|
2013-02-26 12:21:28 -05:00
|
|
|
:version "24.4"
|
|
|
|
:package-version '(Org . "8.0")
|
2013-01-11 17:16:45 -05:00
|
|
|
:type 'string)
|
|
|
|
|
2014-07-28 11:43:15 -04:00
|
|
|
(defcustom org-clock-goto-before-context 2
|
|
|
|
"Number of lines of context to display before currently clocked-in entry.
|
|
|
|
This applies when using `org-clock-goto'."
|
|
|
|
:group 'org-clock
|
|
|
|
:type 'integer)
|
|
|
|
|
|
|
|
(defcustom org-clock-display-default-range 'thisyear
|
|
|
|
"Default range when displaying clocks with `org-clock-display'."
|
|
|
|
:group 'org-clock
|
|
|
|
:type '(choice (const today)
|
|
|
|
(const yesterday)
|
|
|
|
(const thisweek)
|
|
|
|
(const lastweek)
|
|
|
|
(const thismonth)
|
|
|
|
(const lastmonth)
|
|
|
|
(const thisyear)
|
|
|
|
(const lastyear)
|
2015-02-20 05:35:16 -05:00
|
|
|
(const untilnow)
|
2014-07-28 11:43:15 -04:00
|
|
|
(const :tag "Select range interactively" interactive)))
|
|
|
|
|
2009-07-17 03:02:56 -04:00
|
|
|
(defvar org-clock-in-prepare-hook nil
|
|
|
|
"Hook run when preparing the clock.
|
|
|
|
This hook is run before anything happens to the task that
|
|
|
|
you want to clock in. For example, you can use this hook
|
|
|
|
to add an effort property.")
|
2009-06-21 11:26:52 -04:00
|
|
|
(defvar org-clock-in-hook nil
|
|
|
|
"Hook run when starting the clock.")
|
|
|
|
(defvar org-clock-out-hook nil
|
|
|
|
"Hook run when stopping the current clock.")
|
|
|
|
|
|
|
|
(defvar org-clock-cancel-hook nil
|
2014-01-06 05:02:18 -05:00
|
|
|
"Hook run when canceling the current clock.")
|
2009-06-21 11:26:52 -04:00
|
|
|
(defvar org-clock-goto-hook nil
|
|
|
|
"Hook run when selecting the currently clocked-in entry.")
|
2009-10-25 02:48:05 -04:00
|
|
|
(defvar org-clock-has-been-used nil
|
|
|
|
"Has the clock been used during the current Emacs session?")
|
2009-06-21 11:26:52 -04:00
|
|
|
|
2015-02-20 05:35:16 -05:00
|
|
|
(defconst org-clock--oldest-date
|
|
|
|
(let* ((dichotomy
|
|
|
|
(lambda (min max pred)
|
|
|
|
(if (funcall pred min) min
|
|
|
|
(incf min)
|
|
|
|
(while (> (- max min) 1)
|
|
|
|
(let ((mean (+ (ash min -1) (ash max -1) (logand min max 1))))
|
|
|
|
(if (funcall pred mean) (setq max mean) (setq min mean)))))
|
|
|
|
max))
|
|
|
|
(high
|
|
|
|
(funcall dichotomy
|
|
|
|
most-negative-fixnum
|
|
|
|
0
|
|
|
|
(lambda (m) (ignore-errors (decode-time (list m 0))))))
|
|
|
|
(low
|
|
|
|
(funcall dichotomy
|
|
|
|
most-negative-fixnum
|
|
|
|
0
|
|
|
|
(lambda (m) (ignore-errors (decode-time (list high m)))))))
|
|
|
|
(list high low))
|
|
|
|
"Internal time for oldest date representable on the system.")
|
|
|
|
|
2008-04-03 11:58:13 -04:00
|
|
|
;;; The clock for measuring work time.
|
|
|
|
|
|
|
|
(defvar org-mode-line-string "")
|
|
|
|
(put 'org-mode-line-string 'risky-local-variable t)
|
|
|
|
|
2009-01-08 05:19:37 -05:00
|
|
|
(defvar org-clock-mode-line-timer nil)
|
2009-10-17 04:56:45 -04:00
|
|
|
(defvar org-clock-idle-timer nil)
|
2009-11-03 04:35:05 -05:00
|
|
|
(defvar org-clock-heading) ; defined in org.el
|
2008-04-03 11:58:13 -04:00
|
|
|
(defvar org-clock-start-time "")
|
|
|
|
|
2010-03-27 11:49:17 -04:00
|
|
|
(defvar org-clock-leftover-time nil
|
2014-01-06 05:02:18 -05:00
|
|
|
"If non-nil, user canceled a clock; this is when leftover time started.")
|
2009-10-17 04:56:45 -04:00
|
|
|
|
2009-06-08 02:00:46 -04:00
|
|
|
(defvar org-clock-effort ""
|
2010-07-15 16:26:51 -04:00
|
|
|
"Effort estimate of the currently clocking task.")
|
2009-05-25 10:54:03 -04:00
|
|
|
|
2009-05-27 02:49:51 -04:00
|
|
|
(defvar org-clock-total-time nil
|
2009-05-28 07:24:23 -04:00
|
|
|
"Holds total time, spent previously on currently clocked item.
|
|
|
|
This does not include the time in the currently running clock.")
|
2009-05-26 17:30:38 -04:00
|
|
|
|
2008-04-25 13:59:51 -04:00
|
|
|
(defvar org-clock-history nil
|
2008-05-01 03:52:45 -04:00
|
|
|
"List of marker pointing to recent clocked tasks.")
|
2008-04-25 02:18:49 -04:00
|
|
|
|
2008-04-25 09:44:07 -04:00
|
|
|
(defvar org-clock-default-task (make-marker)
|
|
|
|
"Marker pointing to the default task that should clock time.
|
|
|
|
The clock can be made to switch to this task after clocking out
|
|
|
|
of a different task.")
|
|
|
|
|
|
|
|
(defvar org-clock-interrupted-task (make-marker)
|
2008-05-01 03:52:45 -04:00
|
|
|
"Marker pointing to the task that has been interrupted by the current clock.")
|
2008-04-25 09:44:07 -04:00
|
|
|
|
2009-01-08 05:19:37 -05:00
|
|
|
(defvar org-clock-mode-line-map (make-sparse-keymap))
|
|
|
|
(define-key org-clock-mode-line-map [mode-line mouse-2] 'org-clock-goto)
|
2009-06-17 01:40:09 -04:00
|
|
|
(define-key org-clock-mode-line-map [mode-line mouse-1] 'org-clock-menu)
|
|
|
|
|
|
|
|
(defun org-clock-menu ()
|
|
|
|
(interactive)
|
|
|
|
(popup-menu
|
|
|
|
'("Clock"
|
|
|
|
["Clock out" org-clock-out t]
|
|
|
|
["Change effort estimate" org-clock-modify-effort-estimate t]
|
|
|
|
["Go to clock entry" org-clock-goto t]
|
|
|
|
["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"])))
|
2008-09-21 01:35:01 -04:00
|
|
|
|
2008-04-25 02:18:49 -04:00
|
|
|
(defun org-clock-history-push (&optional pos buffer)
|
2008-04-25 13:59:51 -04:00
|
|
|
"Push a marker to the clock history."
|
2008-05-09 15:40:50 -04:00
|
|
|
(setq org-clock-history-length (max 1 (min 35 org-clock-history-length)))
|
2010-06-24 01:36:13 -04:00
|
|
|
(let ((m (move-marker (make-marker)
|
|
|
|
(or pos (point)) (org-base-buffer
|
|
|
|
(or buffer (current-buffer)))))
|
|
|
|
n l)
|
2008-04-25 13:59:51 -04:00
|
|
|
(while (setq n (member m org-clock-history))
|
|
|
|
(move-marker (car n) nil))
|
2008-04-25 02:18:49 -04:00
|
|
|
(setq org-clock-history
|
2008-04-25 13:59:51 -04:00
|
|
|
(delq nil
|
|
|
|
(mapcar (lambda (x) (if (marker-buffer x) x nil))
|
|
|
|
org-clock-history)))
|
|
|
|
(when (>= (setq l (length org-clock-history)) org-clock-history-length)
|
|
|
|
(setq org-clock-history
|
|
|
|
(nreverse
|
|
|
|
(nthcdr (- l org-clock-history-length -1)
|
|
|
|
(nreverse org-clock-history)))))
|
|
|
|
(push m org-clock-history)))
|
2008-04-25 02:18:49 -04:00
|
|
|
|
2008-05-02 03:01:56 -04:00
|
|
|
(defun org-clock-save-markers-for-cut-and-paste (beg end)
|
|
|
|
"Save relative positions of markers in region."
|
|
|
|
(org-check-and-save-marker org-clock-marker beg end)
|
2009-08-07 05:00:16 -04:00
|
|
|
(org-check-and-save-marker org-clock-hd-marker beg end)
|
2008-05-02 03:01:56 -04:00
|
|
|
(org-check-and-save-marker org-clock-default-task beg end)
|
|
|
|
(org-check-and-save-marker org-clock-interrupted-task beg end)
|
|
|
|
(mapc (lambda (m) (org-check-and-save-marker m beg end))
|
|
|
|
org-clock-history))
|
|
|
|
|
2015-09-01 04:29:33 -04:00
|
|
|
(defun org-clock-drawer-name ()
|
|
|
|
"Return clock drawer's name for current entry, or nil."
|
|
|
|
(let ((drawer (org-clock-into-drawer)))
|
|
|
|
(cond ((integerp drawer) (org-log-into-drawer))
|
|
|
|
((stringp drawer) drawer)
|
|
|
|
(t nil))))
|
|
|
|
|
2010-03-09 11:10:15 -05:00
|
|
|
(defun org-clocking-buffer ()
|
2010-07-15 16:26:51 -04:00
|
|
|
"Return the clocking buffer if we are currently clocking a task or nil."
|
2010-03-09 11:10:15 -05:00
|
|
|
(marker-buffer org-clock-marker))
|
|
|
|
|
|
|
|
(defun org-clocking-p ()
|
2010-07-15 16:26:51 -04:00
|
|
|
"Return t when clocking a task."
|
2010-03-09 11:10:15 -05:00
|
|
|
(not (equal (org-clocking-buffer) nil)))
|
|
|
|
|
2011-01-24 19:03:48 -05:00
|
|
|
(defvar org-clock-before-select-task-hook nil
|
|
|
|
"Hook called in task selection just before prompting the user.")
|
|
|
|
|
2008-04-25 02:18:49 -04:00
|
|
|
(defun org-clock-select-task (&optional prompt)
|
2013-04-10 04:08:45 -04:00
|
|
|
"Select a task that was recently associated with clocking."
|
2008-04-25 02:18:49 -04:00
|
|
|
(interactive)
|
2013-04-13 04:21:16 -04:00
|
|
|
(let (och chl sel-list rpl (i 0) s)
|
|
|
|
;; Remove successive dups from the clock history to consider
|
|
|
|
(mapc (lambda (c) (if (not (equal c (car och))) (push c och)))
|
|
|
|
org-clock-history)
|
|
|
|
(setq och (reverse och) chl (length och))
|
2013-04-10 04:08:45 -04:00
|
|
|
(if (zerop chl)
|
|
|
|
(user-error "No recent clock")
|
|
|
|
(save-window-excursion
|
|
|
|
(org-switch-to-buffer-other-window
|
|
|
|
(get-buffer-create "*Clock Task Select*"))
|
|
|
|
(erase-buffer)
|
|
|
|
(when (marker-buffer org-clock-default-task)
|
|
|
|
(insert (org-add-props "Default Task\n" nil 'face 'bold))
|
|
|
|
(setq s (org-clock-insert-selection-line ?d org-clock-default-task))
|
|
|
|
(push s sel-list))
|
|
|
|
(when (marker-buffer org-clock-interrupted-task)
|
|
|
|
(insert (org-add-props "The task interrupted by starting the last one\n" nil 'face 'bold))
|
|
|
|
(setq s (org-clock-insert-selection-line ?i org-clock-interrupted-task))
|
|
|
|
(push s sel-list))
|
|
|
|
(when (org-clocking-p)
|
|
|
|
(insert (org-add-props "Current Clocking Task\n" nil 'face 'bold))
|
|
|
|
(setq s (org-clock-insert-selection-line ?c org-clock-marker))
|
|
|
|
(push s sel-list))
|
|
|
|
(insert (org-add-props "Recent Tasks\n" nil 'face 'bold))
|
|
|
|
(mapc
|
|
|
|
(lambda (m)
|
|
|
|
(when (marker-buffer m)
|
|
|
|
(setq i (1+ i)
|
|
|
|
s (org-clock-insert-selection-line
|
|
|
|
(if (< i 10)
|
|
|
|
(+ i ?0)
|
|
|
|
(+ i (- ?A 10))) m))
|
|
|
|
(if (fboundp 'int-to-char) (setf (car s) (int-to-char (car s))))
|
|
|
|
(push s sel-list)))
|
2013-04-13 04:21:16 -04:00
|
|
|
och)
|
2013-04-10 04:08:45 -04:00
|
|
|
(run-hooks 'org-clock-before-select-task-hook)
|
|
|
|
(goto-char (point-min))
|
|
|
|
;; Set min-height relatively to circumvent a possible but in
|
|
|
|
;; `fit-window-to-buffer'
|
|
|
|
(fit-window-to-buffer nil nil (if (< chl 10) chl (+ 5 chl)))
|
|
|
|
(message (or prompt "Select task for clocking:"))
|
|
|
|
(setq cursor-type nil rpl (read-char-exclusive))
|
2014-10-20 09:27:46 -04:00
|
|
|
(kill-buffer)
|
2013-04-10 04:08:45 -04:00
|
|
|
(cond
|
|
|
|
((eq rpl ?q) nil)
|
|
|
|
((eq rpl ?x) nil)
|
|
|
|
((assoc rpl sel-list) (cdr (assoc rpl sel-list)))
|
|
|
|
(t (user-error "Invalid task choice %c" rpl)))))))
|
2008-04-25 02:18:49 -04:00
|
|
|
|
|
|
|
(defun org-clock-insert-selection-line (i marker)
|
2009-05-05 03:57:00 -04:00
|
|
|
"Insert a line for the clock selection menu.
|
|
|
|
And return a cons cell with the selection character integer and the marker
|
|
|
|
pointing to it."
|
2008-04-25 02:18:49 -04:00
|
|
|
(when (marker-buffer marker)
|
2013-04-12 02:21:48 -04:00
|
|
|
(let (file cat task heading prefix)
|
2008-04-29 15:06:53 -04:00
|
|
|
(with-current-buffer (org-base-buffer (marker-buffer marker))
|
2008-04-25 02:18:49 -04:00
|
|
|
(save-excursion
|
2008-04-29 15:06:53 -04:00
|
|
|
(save-restriction
|
|
|
|
(widen)
|
2009-11-23 15:04:31 -05:00
|
|
|
(ignore-errors
|
|
|
|
(goto-char marker)
|
|
|
|
(setq file (buffer-file-name (marker-buffer marker))
|
2011-01-03 07:12:42 -05:00
|
|
|
cat (org-get-category)
|
2009-11-23 15:04:31 -05:00
|
|
|
heading (org-get-heading 'notags)
|
|
|
|
prefix (save-excursion
|
|
|
|
(org-back-to-heading t)
|
Don't use `outline-regexp' anymore.
Use `org-outline-regexp' instead or `outline-regexp'. Also use the
new defconst `org-outline-regexp-bol' to match `org-outline-regexp'
at the beginning of line.
* org.el (org-outline-regexp-bol): New defconst.
(org-outline-level, org-set-font-lock-defaults, org-cycle)
(org-overview, org-content, org-flag-drawer)
(org-first-headline-recenter, org-insert-todo-heading)
(org-map-region, org-move-subtree-down, org-paste-subtree)
(org-kill-is-subtree-p, org-context-p, org-refile)
(org-refile-new-child, org-toggle-comment, org-todo)
(org-add-planning-info, org-add-log-setup, org-scan-tags)
(org-set-tags, org-insert-property-drawer)
(org-prepare-agenda-buffers, org-preview-latex-fragment)
(org-speed-command-default-hook, org-check-for-hidden)
(org-toggle-item, org-toggle-heading)
(org-indent-line-function, org-set-autofill-regexps)
(org-fill-paragraph, org-toggle-fixed-width-section)
(org-yank-generic, org-yank-folding-would-swallow-text)
(org-first-sibling-p, org-goto-sibling)
(org-goto-first-child, org-show-entry): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-remember.el (org-remember-handler): Use
`org-outline-regexp-bol'.
* org-mouse.el (org-mouse-match-todo-keyword, org-mode-hook)
(org-mouse-move-tree, org-mouse-transform-to-outline): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-macs.el (org-with-limited-levels)
(org-get-limited-outline-regexp): Use `org-outline-regexp'.
* org-indent.el (org-indent-outline-re)
(org-indent-refresh-section, org-indent-refresh-to): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-html.el (org-export-as-html): Use
`org-outline-regexp-bol'.
* org-footnote.el (org-footnote-at-definition-p)
(org-footnote-normalize): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-exp.el (org-export-preprocess-string): Don't redefine
`outline-regexp'.
* org-docbook.el (org-export-as-docbook): Use
`org-outline-regexp-bol'.
* org-colview.el (org-columns, org-columns-compute): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-colview-xemacs.el (org-columns, org-columns-compute):
Use `org-outline-regexp-bol'.
* org-clock.el (org-clock-insert-selection-line)
(org-clock-in, org-clock-out, org-dblock-write:clocktable):
Use `org-outline-regexp' and `org-outline-regexp-bol'.
* org-ascii.el (org-export-as-ascii)
(org-export-ascii-push-links): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-archive.el (org-archive-to-archive-sibling)
(org-archive-all-done): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-agenda.el (org-agenda, org-search-view)
(org-agenda-list-stuck-projects, org-agenda-get-timestamps)
(org-agenda-get-progress, org-agenda-get-blocks): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
2011-07-17 15:17:08 -04:00
|
|
|
(looking-at org-outline-regexp)
|
2009-11-23 15:04:31 -05:00
|
|
|
(match-string 0))
|
|
|
|
task (substring
|
|
|
|
(org-fontify-like-in-org-mode
|
|
|
|
(concat prefix heading)
|
|
|
|
org-odd-levels-only)
|
|
|
|
(length prefix)))))))
|
2013-04-12 02:21:48 -04:00
|
|
|
(when (and cat task)
|
|
|
|
(insert (format "[%c] %-12s %s\n" i cat task))
|
2008-04-25 02:18:49 -04:00
|
|
|
(cons i marker)))))
|
2008-09-21 01:35:01 -04:00
|
|
|
|
2012-04-10 19:14:21 -04:00
|
|
|
(defvar org-clock-task-overrun nil
|
2010-01-23 04:41:13 -05:00
|
|
|
"Internal flag indicating if the clock has overrun the planned time.")
|
|
|
|
(defvar org-clock-update-period 60
|
|
|
|
"Number of seconds between mode line clock string updates.")
|
|
|
|
|
2009-05-25 10:54:03 -04:00
|
|
|
(defun org-clock-get-clock-string ()
|
2010-02-20 11:38:31 -05:00
|
|
|
"Form a clock-string, that will be shown in the mode line.
|
|
|
|
If an effort estimate was defined for the current item, use
|
2009-05-28 07:24:23 -04:00
|
|
|
01:30/01:50 format (clocked/estimated).
|
|
|
|
If not, show simply the clocked time like 01:50."
|
2012-11-11 17:20:24 -05:00
|
|
|
(let ((clocked-time (org-clock-get-clocked-time)))
|
2010-01-23 04:41:13 -05:00
|
|
|
(if org-clock-effort
|
|
|
|
(let* ((effort-in-minutes
|
2011-02-28 11:43:33 -05:00
|
|
|
(org-duration-string-to-minutes org-clock-effort))
|
2010-01-23 04:41:13 -05:00
|
|
|
(work-done-str
|
|
|
|
(org-propertize
|
2012-11-11 17:20:24 -05:00
|
|
|
(org-minutes-to-clocksum-string clocked-time)
|
2012-04-10 19:14:21 -04:00
|
|
|
'face (if (and org-clock-task-overrun (not org-clock-task-overrun-text))
|
2010-01-23 04:41:13 -05:00
|
|
|
'org-mode-line-clock-overrun 'org-mode-line-clock)))
|
2012-11-11 17:20:24 -05:00
|
|
|
(effort-str (org-minutes-to-clocksum-string effort-in-minutes))
|
2010-01-23 04:41:13 -05:00
|
|
|
(clockstr (org-propertize
|
2012-05-05 05:30:58 -04:00
|
|
|
(concat " [%s/" effort-str
|
2010-02-20 11:38:31 -05:00
|
|
|
"] (" (replace-regexp-in-string "%" "%%" org-clock-heading) ")")
|
2010-01-23 04:41:13 -05:00
|
|
|
'face 'org-mode-line-clock)))
|
|
|
|
(format clockstr work-done-str))
|
2012-11-11 17:20:24 -05:00
|
|
|
(org-propertize (concat "[" (org-minutes-to-clocksum-string clocked-time)
|
|
|
|
(format " (%s)" org-clock-heading) "]")
|
2010-01-23 04:41:13 -05:00
|
|
|
'face 'org-mode-line-clock))))
|
2009-05-25 10:54:03 -04:00
|
|
|
|
2012-09-19 05:36:32 -04:00
|
|
|
(defun org-clock-get-last-clock-out-time ()
|
|
|
|
"Get the last clock-out time for the current subtree."
|
|
|
|
(save-excursion
|
|
|
|
(let ((end (save-excursion (org-end-of-subtree))))
|
|
|
|
(when (re-search-forward (concat org-clock-string
|
|
|
|
".*\\]--\\(\\[[^]]+\\]\\)") end t)
|
|
|
|
(org-time-string-to-time (match-string 1))))))
|
|
|
|
|
2009-05-25 16:01:34 -04:00
|
|
|
(defun org-clock-update-mode-line ()
|
2010-01-23 04:41:13 -05:00
|
|
|
(if org-clock-effort
|
|
|
|
(org-clock-notify-once-if-expired)
|
2012-04-10 19:14:21 -04:00
|
|
|
(setq org-clock-task-overrun nil))
|
2009-05-25 16:01:34 -04:00
|
|
|
(setq org-mode-line-string
|
|
|
|
(org-propertize
|
|
|
|
(let ((clock-string (org-clock-get-clock-string))
|
2009-06-17 01:40:09 -04:00
|
|
|
(help-text "Org-mode clock is running.\nmouse-1 shows a menu\nmouse-2 will jump to task"))
|
2009-05-25 16:01:34 -04:00
|
|
|
(if (and (> org-clock-string-limit 0)
|
|
|
|
(> (length clock-string) org-clock-string-limit))
|
2010-01-23 04:41:13 -05:00
|
|
|
(org-propertize
|
|
|
|
(substring clock-string 0 org-clock-string-limit)
|
|
|
|
'help-echo (concat help-text ": " org-clock-heading))
|
2009-05-25 16:01:34 -04:00
|
|
|
(org-propertize clock-string 'help-echo help-text)))
|
|
|
|
'local-map org-clock-mode-line-map
|
2012-05-05 08:21:13 -04:00
|
|
|
'mouse-face (if (featurep 'xemacs) 'highlight 'mode-line-highlight)))
|
2012-04-10 19:14:21 -04:00
|
|
|
(if (and org-clock-task-overrun org-clock-task-overrun-text)
|
2010-01-23 04:41:13 -05:00
|
|
|
(setq org-mode-line-string
|
|
|
|
(concat (org-propertize
|
2012-04-10 19:14:21 -04:00
|
|
|
org-clock-task-overrun-text
|
2010-01-23 04:41:13 -05:00
|
|
|
'face 'org-mode-line-clock-overrun) org-mode-line-string)))
|
2009-05-25 16:01:34 -04:00
|
|
|
(force-mode-line-update))
|
|
|
|
|
2009-05-26 17:30:38 -04:00
|
|
|
(defun org-clock-get-clocked-time ()
|
2009-06-09 16:33:13 -04:00
|
|
|
"Get the clocked time for the current item in minutes.
|
2009-10-04 02:36:18 -04:00
|
|
|
The time returned includes the time spent on this task in
|
2009-05-28 07:24:23 -04:00
|
|
|
previous clocking intervals."
|
|
|
|
(let ((currently-clocked-time
|
2009-09-02 08:37:47 -04:00
|
|
|
(floor (- (org-float-time)
|
|
|
|
(org-float-time org-clock-start-time)) 60)))
|
2009-05-28 07:24:23 -04:00
|
|
|
(+ currently-clocked-time (or org-clock-total-time 0))))
|
2009-05-26 17:30:38 -04:00
|
|
|
|
2009-06-17 01:40:09 -04:00
|
|
|
(defun org-clock-modify-effort-estimate (&optional value)
|
2012-03-05 00:09:28 -05:00
|
|
|
"Add to or set the effort estimate of the item currently being clocked.
|
2009-11-12 07:39:29 -05:00
|
|
|
VALUE can be a number of minutes, or a string with format hh:mm or mm.
|
|
|
|
When the string starts with a + or a - sign, the current value of the effort
|
2013-05-21 06:37:05 -04:00
|
|
|
property will be changed by that amount. If the effort value is expressed
|
2013-11-17 03:12:41 -05:00
|
|
|
as an `org-effort-durations' (e.g. \"3h\"), the modified value will be
|
2013-05-21 06:37:05 -04:00
|
|
|
converted to a hh:mm duration.
|
2013-05-21 06:33:36 -04:00
|
|
|
|
2013-05-21 06:37:05 -04:00
|
|
|
This command will update the \"Effort\" property of the currently
|
|
|
|
clocked item, and the value displayed in the mode line."
|
2012-03-05 00:09:28 -05:00
|
|
|
(interactive)
|
|
|
|
(if (org-clock-is-active)
|
|
|
|
(let ((current org-clock-effort) sign)
|
|
|
|
(unless value
|
|
|
|
;; Prompt user for a value or a change
|
|
|
|
(setq value
|
|
|
|
(read-string
|
|
|
|
(format "Set effort (hh:mm or mm%s): "
|
|
|
|
(if current
|
|
|
|
(format ", prefix + to add to %s" org-clock-effort)
|
|
|
|
"")))))
|
|
|
|
(when (stringp value)
|
|
|
|
;; A string. See if it is a delta
|
|
|
|
(setq sign (string-to-char value))
|
|
|
|
(if (member sign '(?- ?+))
|
|
|
|
(setq current (org-duration-string-to-minutes current)
|
|
|
|
value (substring value 1))
|
|
|
|
(setq current 0))
|
|
|
|
(setq value (org-duration-string-to-minutes value))
|
|
|
|
(if (equal ?- sign)
|
|
|
|
(setq value (- current value))
|
|
|
|
(if (equal ?+ sign) (setq value (+ current value)))))
|
|
|
|
(setq value (max 0 value)
|
2012-11-11 17:20:24 -05:00
|
|
|
org-clock-effort (org-minutes-to-clocksum-string value))
|
2012-03-05 00:09:28 -05:00
|
|
|
(org-entry-put org-clock-marker "Effort" org-clock-effort)
|
|
|
|
(org-clock-update-mode-line)
|
|
|
|
(message "Effort is now %s" org-clock-effort))
|
|
|
|
(message "Clock is not currently active")))
|
2009-06-16 03:42:05 -04:00
|
|
|
|
2009-05-25 16:01:34 -04:00
|
|
|
(defvar org-clock-notification-was-shown nil
|
|
|
|
"Shows if we have shown notification already.")
|
|
|
|
|
|
|
|
(defun org-clock-notify-once-if-expired ()
|
2009-07-26 08:59:49 -04:00
|
|
|
"Show notification if we spent more time than we estimated before.
|
2009-05-25 16:01:34 -04:00
|
|
|
Notification is shown only once."
|
2010-03-09 11:10:15 -05:00
|
|
|
(when (org-clocking-p)
|
2011-02-28 11:43:33 -05:00
|
|
|
(let ((effort-in-minutes (org-duration-string-to-minutes org-clock-effort))
|
2009-06-09 16:27:56 -04:00
|
|
|
(clocked-time (org-clock-get-clocked-time)))
|
2012-04-10 19:14:21 -04:00
|
|
|
(if (setq org-clock-task-overrun
|
2010-01-23 04:41:13 -05:00
|
|
|
(if (or (null effort-in-minutes) (zerop effort-in-minutes))
|
|
|
|
nil
|
|
|
|
(>= clocked-time effort-in-minutes)))
|
2009-06-09 16:27:56 -04:00
|
|
|
(unless org-clock-notification-was-shown
|
|
|
|
(setq org-clock-notification-was-shown t)
|
2009-08-23 14:44:29 -04:00
|
|
|
(org-notify
|
2015-09-21 00:23:36 -04:00
|
|
|
(format-message "Task `%s' should be finished by now. (%s)"
|
|
|
|
org-clock-heading org-clock-effort)
|
|
|
|
org-clock-sound))
|
2009-06-09 16:27:56 -04:00
|
|
|
(setq org-clock-notification-was-shown nil)))))
|
2009-05-28 07:24:23 -04:00
|
|
|
|
2009-08-23 14:44:29 -04:00
|
|
|
(defun org-notify (notification &optional play-sound)
|
2012-09-26 09:52:21 -04:00
|
|
|
"Send a NOTIFICATION and maybe PLAY-SOUND.
|
|
|
|
If PLAY-SOUND is non-nil, it overrides `org-clock-sound'."
|
2009-08-25 23:28:25 -04:00
|
|
|
(org-show-notification notification)
|
2012-09-26 09:52:21 -04:00
|
|
|
(if play-sound (org-clock-play-sound play-sound)))
|
2009-08-23 14:44:29 -04:00
|
|
|
|
2009-05-28 07:24:23 -04:00
|
|
|
(defun org-show-notification (notification)
|
2009-08-03 11:30:30 -04:00
|
|
|
"Show notification.
|
2009-07-26 13:11:51 -04:00
|
|
|
Use `org-show-notification-handler' if defined,
|
|
|
|
use libnotify if available, or fall back on a message."
|
2009-07-23 11:33:52 -04:00
|
|
|
(cond ((functionp org-show-notification-handler)
|
|
|
|
(funcall org-show-notification-handler notification))
|
|
|
|
((stringp org-show-notification-handler)
|
2009-08-03 11:30:30 -04:00
|
|
|
(start-process "emacs-timer-notification" nil
|
2009-07-23 11:33:52 -04:00
|
|
|
org-show-notification-handler notification))
|
2012-04-02 10:52:16 -04:00
|
|
|
((fboundp 'notifications-notify)
|
2010-09-02 17:51:22 -04:00
|
|
|
(notifications-notify
|
|
|
|
:title "Org-mode message"
|
|
|
|
:body notification
|
|
|
|
;; FIXME how to link to the Org icon?
|
|
|
|
;; :app-icon "~/.emacs.d/icons/mail.png"
|
|
|
|
:urgency 'low))
|
2012-04-28 17:43:10 -04:00
|
|
|
((executable-find "notify-send")
|
2009-08-03 11:30:30 -04:00
|
|
|
(start-process "emacs-timer-notification" nil
|
2009-07-23 11:33:52 -04:00
|
|
|
"notify-send" notification))
|
|
|
|
;; Maybe the handler will send a message, so only use message as
|
|
|
|
;; a fall back option
|
2009-11-06 18:43:27 -05:00
|
|
|
(t (message "%s" notification))))
|
2009-05-25 16:01:34 -04:00
|
|
|
|
2012-09-26 09:52:21 -04:00
|
|
|
(defun org-clock-play-sound (&optional clock-sound)
|
2009-05-28 07:24:23 -04:00
|
|
|
"Play sound as configured by `org-clock-sound'.
|
2012-09-26 09:52:21 -04:00
|
|
|
Use alsa's aplay tool if available.
|
|
|
|
If CLOCK-SOUND is non-nil, it overrides `org-clock-sound'."
|
|
|
|
(let ((org-clock-sound (or clock-sound org-clock-sound)))
|
|
|
|
(cond
|
|
|
|
((not org-clock-sound))
|
|
|
|
((eq org-clock-sound t) (beep t) (beep t))
|
|
|
|
((stringp org-clock-sound)
|
|
|
|
(let ((file (expand-file-name org-clock-sound)))
|
|
|
|
(if (file-exists-p file)
|
|
|
|
(if (executable-find "aplay")
|
|
|
|
(start-process "org-clock-play-notification" nil
|
|
|
|
"aplay" file)
|
|
|
|
(condition-case nil
|
|
|
|
(play-sound-file file)
|
|
|
|
(error (beep t) (beep t))))))))))
|
2009-05-28 07:24:23 -04:00
|
|
|
|
2008-04-03 11:58:13 -04:00
|
|
|
(defvar org-clock-mode-line-entry nil
|
2012-06-03 04:28:46 -04:00
|
|
|
"Information for the mode line about the running clock.")
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2009-10-16 22:21:13 -04:00
|
|
|
(defun org-find-open-clocks (file)
|
|
|
|
"Search through the given file and find all open clocks."
|
|
|
|
(let ((buf (or (get-file-buffer file)
|
|
|
|
(find-file-noselect file)))
|
2014-08-26 03:11:23 -04:00
|
|
|
(org-clock-re (concat org-clock-string " \\(\\[.*?\\]\\)$"))
|
2009-10-16 22:21:13 -04:00
|
|
|
clocks)
|
|
|
|
(with-current-buffer buf
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
2014-08-26 03:11:23 -04:00
|
|
|
(while (re-search-forward org-clock-re nil t)
|
2010-05-16 13:11:16 -04:00
|
|
|
(push (cons (copy-marker (match-end 1) t)
|
2009-10-16 22:21:13 -04:00
|
|
|
(org-time-string-to-time (match-string 1))) clocks))))
|
|
|
|
clocks))
|
|
|
|
|
|
|
|
(defsubst org-is-active-clock (clock)
|
|
|
|
"Return t if CLOCK is the currently active clock."
|
|
|
|
(and (org-clock-is-active)
|
|
|
|
(= org-clock-marker (car clock))))
|
|
|
|
|
|
|
|
(defmacro org-with-clock-position (clock &rest forms)
|
|
|
|
"Evaluate FORMS with CLOCK as the current active clock."
|
|
|
|
`(with-current-buffer (marker-buffer (car ,clock))
|
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-char (car ,clock))
|
|
|
|
(beginning-of-line)
|
|
|
|
,@forms))))
|
Provide edebug specifications for macros
* org-macs.el (org-with-gensyms, org-called-interactively-p)
(with-silent-modifications, org-bound-and-true-p)
(org-unmodified, org-re, org-preserve-lc)
(org-without-partial-completion, org-with-point-at)
(org-no-warnings, org-if-unprotected, org-if-unprotected-1)
(org-if-unprotected-at, org-with-remote-undo)
(org-no-read-only, org-save-outline-visibility)
(org-with-wide-buffer, org-with-limited-levels)
(org-eval-in-environment): Provide edebug specifications.
* org-src.el (org-src-do-at-code-block): Dto.
* org-publish.el (org-publish-with-aux-preprocess-maybe): Dto.
* org-compat.el (org-xemacs-without-invisibility): Dto.
* org-clock.el (org-with-clock-position, org-with-clock): Dto.
* org-agenda.el (org-agenda-with-point-at-orig-entry)
(org-batch-agenda, org-batch-agenda-csv)
(org-batch-store-agenda-views): Dto.
* ob.el (org-babel-do-in-edit-buffer)
(org-babel-map-src-blocks, org-babel-map-inline-src-blocks): Dto.
* ob-tangle.el (org-babel-with-temp-filebuffer): Dto.
* ob-table.el (sbe): Dto.
* ob-exp.el (org-babel-exp-in-export-file): Dto.
* ob-comint.el (org-babel-comint-in-buffer)
(org-babel-comint-with-output): Dto.
2011-08-11 02:57:25 -04:00
|
|
|
(def-edebug-spec org-with-clock-position (form body))
|
2009-10-16 22:21:13 -04:00
|
|
|
(put 'org-with-clock-position 'lisp-indent-function 1)
|
|
|
|
|
|
|
|
(defmacro org-with-clock (clock &rest forms)
|
|
|
|
"Evaluate FORMS with CLOCK as the current active clock.
|
|
|
|
This macro also protects the current active clock from being altered."
|
|
|
|
`(org-with-clock-position ,clock
|
|
|
|
(let ((org-clock-start-time (cdr ,clock))
|
|
|
|
(org-clock-total-time)
|
|
|
|
(org-clock-history)
|
|
|
|
(org-clock-effort)
|
|
|
|
(org-clock-marker (car ,clock))
|
|
|
|
(org-clock-hd-marker (save-excursion
|
|
|
|
(outline-back-to-heading t)
|
|
|
|
(point-marker))))
|
|
|
|
,@forms)))
|
Provide edebug specifications for macros
* org-macs.el (org-with-gensyms, org-called-interactively-p)
(with-silent-modifications, org-bound-and-true-p)
(org-unmodified, org-re, org-preserve-lc)
(org-without-partial-completion, org-with-point-at)
(org-no-warnings, org-if-unprotected, org-if-unprotected-1)
(org-if-unprotected-at, org-with-remote-undo)
(org-no-read-only, org-save-outline-visibility)
(org-with-wide-buffer, org-with-limited-levels)
(org-eval-in-environment): Provide edebug specifications.
* org-src.el (org-src-do-at-code-block): Dto.
* org-publish.el (org-publish-with-aux-preprocess-maybe): Dto.
* org-compat.el (org-xemacs-without-invisibility): Dto.
* org-clock.el (org-with-clock-position, org-with-clock): Dto.
* org-agenda.el (org-agenda-with-point-at-orig-entry)
(org-batch-agenda, org-batch-agenda-csv)
(org-batch-store-agenda-views): Dto.
* ob.el (org-babel-do-in-edit-buffer)
(org-babel-map-src-blocks, org-babel-map-inline-src-blocks): Dto.
* ob-tangle.el (org-babel-with-temp-filebuffer): Dto.
* ob-table.el (sbe): Dto.
* ob-exp.el (org-babel-exp-in-export-file): Dto.
* ob-comint.el (org-babel-comint-in-buffer)
(org-babel-comint-with-output): Dto.
2011-08-11 02:57:25 -04:00
|
|
|
(def-edebug-spec org-with-clock (form body))
|
2009-10-16 22:21:13 -04:00
|
|
|
(put 'org-with-clock 'lisp-indent-function 1)
|
|
|
|
|
2010-05-16 11:42:53 -04:00
|
|
|
(defsubst org-clock-clock-in (clock &optional resume start-time)
|
2009-10-16 22:21:13 -04:00
|
|
|
"Clock in to the clock located by CLOCK.
|
|
|
|
If necessary, clock-out of the currently active clock."
|
|
|
|
(org-with-clock-position clock
|
|
|
|
(let ((org-clock-in-resume (or resume org-clock-in-resume)))
|
2010-05-16 11:42:53 -04:00
|
|
|
(org-clock-in nil start-time))))
|
2009-10-16 22:21:13 -04:00
|
|
|
|
|
|
|
(defsubst org-clock-clock-out (clock &optional fail-quietly at-time)
|
|
|
|
"Clock out of the clock located by CLOCK."
|
|
|
|
(let ((temp (copy-marker (car clock)
|
|
|
|
(marker-insertion-type (car clock)))))
|
|
|
|
(if (org-is-active-clock clock)
|
2012-08-09 08:52:38 -04:00
|
|
|
(org-clock-out nil fail-quietly at-time)
|
2009-10-16 22:21:13 -04:00
|
|
|
(org-with-clock clock
|
2012-08-09 08:52:38 -04:00
|
|
|
(org-clock-out nil fail-quietly at-time)))
|
2009-10-16 22:21:13 -04:00
|
|
|
(setcar clock temp)))
|
|
|
|
|
|
|
|
(defsubst org-clock-clock-cancel (clock)
|
|
|
|
"Cancel the clock located by CLOCK."
|
|
|
|
(let ((temp (copy-marker (car clock)
|
|
|
|
(marker-insertion-type (car clock)))))
|
|
|
|
(if (org-is-active-clock clock)
|
|
|
|
(org-clock-cancel)
|
|
|
|
(org-with-clock clock
|
|
|
|
(org-clock-cancel)))
|
|
|
|
(setcar clock temp)))
|
|
|
|
|
2009-10-17 04:38:36 -04:00
|
|
|
(defvar org-clock-clocking-in nil)
|
2009-10-17 04:56:45 -04:00
|
|
|
(defvar org-clock-resolving-clocks nil)
|
|
|
|
(defvar org-clock-resolving-clocks-due-to-idleness nil)
|
2009-10-17 04:38:36 -04:00
|
|
|
|
2010-05-16 11:42:53 -04:00
|
|
|
(defun org-clock-resolve-clock (clock resolve-to clock-out-time
|
|
|
|
&optional close-p restart-p fail-quietly)
|
2009-10-17 04:38:36 -04:00
|
|
|
"Resolve `CLOCK' given the time `RESOLVE-TO', and the present.
|
2010-05-16 11:42:53 -04:00
|
|
|
`CLOCK' is a cons cell of the form (MARKER START-TIME)."
|
2009-10-17 04:56:45 -04:00
|
|
|
(let ((org-clock-resolving-clocks t))
|
|
|
|
(cond
|
|
|
|
((null resolve-to)
|
|
|
|
(org-clock-clock-cancel clock)
|
|
|
|
(if (and restart-p (not org-clock-clocking-in))
|
|
|
|
(org-clock-clock-in clock)))
|
|
|
|
|
|
|
|
((eq resolve-to 'now)
|
|
|
|
(if restart-p
|
|
|
|
(error "RESTART-P is not valid here"))
|
|
|
|
(if (or close-p org-clock-clocking-in)
|
|
|
|
(org-clock-clock-out clock fail-quietly)
|
|
|
|
(unless (org-is-active-clock clock)
|
|
|
|
(org-clock-clock-in clock t))))
|
|
|
|
|
|
|
|
((not (time-less-p resolve-to (current-time)))
|
|
|
|
(error "RESOLVE-TO must refer to a time in the past"))
|
|
|
|
|
|
|
|
(t
|
|
|
|
(if restart-p
|
|
|
|
(error "RESTART-P is not valid here"))
|
2010-05-16 11:42:53 -04:00
|
|
|
(org-clock-clock-out clock fail-quietly (or clock-out-time
|
|
|
|
resolve-to))
|
2009-10-17 04:56:45 -04:00
|
|
|
(unless org-clock-clocking-in
|
|
|
|
(if close-p
|
2010-05-16 11:42:53 -04:00
|
|
|
(setq org-clock-leftover-time (and (null clock-out-time)
|
|
|
|
resolve-to))
|
|
|
|
(org-clock-clock-in clock nil (and clock-out-time
|
|
|
|
resolve-to))))))))
|
|
|
|
|
|
|
|
(defun org-clock-jump-to-current-clock (&optional effective-clock)
|
|
|
|
(interactive)
|
2014-12-14 12:22:31 -05:00
|
|
|
(let ((drawer (org-clock-into-drawer))
|
2011-06-27 06:12:23 -04:00
|
|
|
(clock (or effective-clock (cons org-clock-marker
|
2010-05-16 11:42:53 -04:00
|
|
|
org-clock-start-time))))
|
|
|
|
(unless (marker-buffer (car clock))
|
|
|
|
(error "No clock is currently running"))
|
|
|
|
(org-with-clock clock (org-clock-goto))
|
|
|
|
(with-current-buffer (marker-buffer (car clock))
|
|
|
|
(goto-char (car clock))
|
2014-12-14 12:22:31 -05:00
|
|
|
(when drawer
|
|
|
|
(org-with-wide-buffer
|
|
|
|
(let ((drawer-re (format "^[ \t]*:%s:[ \t]*$"
|
2015-08-12 07:46:47 -04:00
|
|
|
(regexp-quote (if (stringp drawer) drawer "LOGBOOK"))))
|
2014-12-14 12:22:31 -05:00
|
|
|
(beg (save-excursion (outline-back-to-heading t) (point))))
|
|
|
|
(catch 'exit
|
|
|
|
(while (re-search-backward drawer-re beg t)
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
(when (eq (org-element-type element) 'drawer)
|
|
|
|
(when (> (org-element-property :end element) (car clock))
|
|
|
|
(org-flag-drawer nil element))
|
|
|
|
(throw 'exit nil)))))))))))
|
2009-10-17 04:38:36 -04:00
|
|
|
|
|
|
|
(defun org-clock-resolve (clock &optional prompt-fn last-valid fail-quietly)
|
|
|
|
"Resolve an open org-mode clock.
|
|
|
|
An open clock was found, with `dangling' possibly being non-nil.
|
|
|
|
If this function was invoked with a prefix argument, non-dangling
|
|
|
|
open clocks are ignored. The given clock requires some sort of
|
|
|
|
user intervention to resolve it, either because a clock was left
|
|
|
|
dangling or due to an idle timeout. The clock resolution can
|
|
|
|
either be:
|
|
|
|
|
|
|
|
(a) deleted, the user doesn't care about the clock
|
|
|
|
(b) restarted from the current time (if no other clock is open)
|
|
|
|
(c) closed, giving the clock X minutes
|
|
|
|
(d) closed and then restarted
|
|
|
|
(e) resumed, as if the user had never left
|
|
|
|
|
|
|
|
The format of clock is (CONS MARKER START-TIME), where MARKER
|
|
|
|
identifies the buffer and position the clock is open at (and
|
|
|
|
thus, the heading it's under), and START-TIME is when the clock
|
|
|
|
was started."
|
|
|
|
(assert clock)
|
|
|
|
(let* ((ch
|
|
|
|
(save-window-excursion
|
|
|
|
(save-excursion
|
2009-10-17 04:56:45 -04:00
|
|
|
(unless org-clock-resolving-clocks-due-to-idleness
|
2010-05-16 11:42:53 -04:00
|
|
|
(org-clock-jump-to-current-clock clock))
|
|
|
|
(unless org-clock-resolve-expert
|
|
|
|
(with-output-to-temp-buffer "*Org Clock*"
|
2015-09-21 00:23:36 -04:00
|
|
|
(princ (format-message "Select a Clock Resolution Command:
|
2010-05-16 11:42:53 -04:00
|
|
|
|
2013-04-08 12:19:43 -04:00
|
|
|
i/q Ignore this question; the same as keeping all the idle time.
|
2010-05-16 11:42:53 -04:00
|
|
|
|
|
|
|
k/K Keep X minutes of the idle time (default is all). If this
|
|
|
|
amount is less than the default, you will be clocked out
|
|
|
|
that many minutes after the time that idling began, and then
|
|
|
|
clocked back in at the present time.
|
2013-04-08 12:19:43 -04:00
|
|
|
|
2015-09-21 00:23:58 -04:00
|
|
|
g/G Indicate that you \"got back\" X minutes ago. This is quite
|
2015-09-21 00:23:36 -04:00
|
|
|
different from `k': it clocks you out from the beginning of
|
2010-05-16 11:42:53 -04:00
|
|
|
the idle period and clock you back in X minutes ago.
|
2013-04-08 12:19:43 -04:00
|
|
|
|
2010-05-16 11:42:53 -04:00
|
|
|
s/S Subtract the idle time from the current clock. This is the
|
|
|
|
same as keeping 0 minutes.
|
2013-04-08 12:19:43 -04:00
|
|
|
|
2010-05-16 11:42:53 -04:00
|
|
|
C Cancel the open timer altogether. It will be as though you
|
|
|
|
never clocked in.
|
2013-04-08 12:19:43 -04:00
|
|
|
|
2010-05-16 11:42:53 -04:00
|
|
|
j/J Jump to the current clock, to make manual adjustments.
|
|
|
|
|
|
|
|
For all these options, using uppercase makes your final state
|
2015-09-21 00:23:36 -04:00
|
|
|
to be CLOCKED OUT."))))
|
2010-05-16 11:42:53 -04:00
|
|
|
(org-fit-window-to-buffer (get-buffer-window "*Org Clock*"))
|
2009-10-17 04:38:36 -04:00
|
|
|
(let (char-pressed)
|
2010-04-21 03:03:30 -04:00
|
|
|
(when (featurep 'xemacs)
|
|
|
|
(message (concat (funcall prompt-fn clock)
|
2010-05-16 11:42:53 -04:00
|
|
|
" [jkKgGsScCiq]? "))
|
2010-04-21 03:03:30 -04:00
|
|
|
(setq char-pressed (read-char-exclusive)))
|
2009-12-25 18:02:48 -05:00
|
|
|
(while (or (null char-pressed)
|
2010-05-16 11:42:53 -04:00
|
|
|
(and (not (memq char-pressed
|
|
|
|
'(?k ?K ?g ?G ?s ?S ?C
|
|
|
|
?j ?J ?i ?q)))
|
2009-12-25 18:02:48 -05:00
|
|
|
(or (ding) t)))
|
|
|
|
(setq char-pressed
|
|
|
|
(read-char (concat (funcall prompt-fn clock)
|
2010-05-16 11:42:53 -04:00
|
|
|
" [jkKgGSscCiq]? ")
|
2009-12-25 18:02:48 -05:00
|
|
|
nil 45)))
|
2010-05-16 11:42:53 -04:00
|
|
|
(and (not (memq char-pressed '(?i ?q))) char-pressed)))))
|
|
|
|
(default
|
|
|
|
(floor (/ (org-float-time
|
|
|
|
(time-subtract (current-time) last-valid)) 60)))
|
|
|
|
(keep
|
|
|
|
(and (memq ch '(?k ?K))
|
|
|
|
(read-number "Keep how many minutes? " default)))
|
|
|
|
(gotback
|
|
|
|
(and (memq ch '(?g ?G))
|
|
|
|
(read-number "Got back how many minutes ago? " default)))
|
2009-10-17 04:38:36 -04:00
|
|
|
(subtractp (memq ch '(?s ?S)))
|
2009-10-17 11:55:59 -04:00
|
|
|
(barely-started-p (< (- (org-float-time last-valid)
|
|
|
|
(org-float-time (cdr clock))) 45))
|
2009-10-17 04:38:36 -04:00
|
|
|
(start-over (and subtractp barely-started-p)))
|
2010-05-16 11:42:53 -04:00
|
|
|
(cond
|
|
|
|
((memq ch '(?j ?J))
|
|
|
|
(if (eq ch ?J)
|
|
|
|
(org-clock-resolve-clock clock 'now nil t nil fail-quietly))
|
|
|
|
(org-clock-jump-to-current-clock clock))
|
|
|
|
((or (null ch)
|
|
|
|
(not (memq ch '(?k ?K ?g ?G ?s ?S ?C))))
|
|
|
|
(message ""))
|
|
|
|
(t
|
2009-10-17 04:38:36 -04:00
|
|
|
(org-clock-resolve-clock
|
|
|
|
clock (cond
|
|
|
|
((or (eq ch ?C)
|
|
|
|
;; If the time on the clock was less than a minute before
|
|
|
|
;; the user went away, and they've ask to subtract all the
|
|
|
|
;; time...
|
|
|
|
start-over)
|
|
|
|
nil)
|
2010-05-16 11:42:53 -04:00
|
|
|
((or subtractp
|
|
|
|
(and gotback (= gotback 0)))
|
2009-10-17 04:38:36 -04:00
|
|
|
last-valid)
|
2010-05-16 11:42:53 -04:00
|
|
|
((or (and keep (= keep default))
|
|
|
|
(and gotback (= gotback default)))
|
2009-10-17 04:38:36 -04:00
|
|
|
'now)
|
2010-05-16 11:42:53 -04:00
|
|
|
(keep
|
|
|
|
(time-add last-valid (seconds-to-time (* 60 keep))))
|
|
|
|
(gotback
|
|
|
|
(time-subtract (current-time)
|
|
|
|
(seconds-to-time (* 60 gotback))))
|
2009-10-17 04:38:36 -04:00
|
|
|
(t
|
2010-05-16 11:42:53 -04:00
|
|
|
(error "Unexpected, please report this as a bug")))
|
|
|
|
(and gotback last-valid)
|
|
|
|
(memq ch '(?K ?G ?S))
|
2009-10-17 04:38:36 -04:00
|
|
|
(and start-over
|
2010-05-16 11:42:53 -04:00
|
|
|
(not (memq ch '(?K ?G ?S ?C))))
|
|
|
|
fail-quietly)))))
|
2009-10-17 04:38:36 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2010-05-16 13:20:39 -04:00
|
|
|
(defun org-resolve-clocks (&optional only-dangling-p prompt-fn last-valid)
|
2009-10-17 04:38:36 -04:00
|
|
|
"Resolve all currently open org-mode clocks.
|
2010-05-16 13:20:39 -04:00
|
|
|
If `only-dangling-p' is non-nil, only ask to resolve dangling
|
|
|
|
\(i.e., not currently open and valid) clocks."
|
2009-10-17 04:38:36 -04:00
|
|
|
(interactive "P")
|
|
|
|
(unless org-clock-resolving-clocks
|
|
|
|
(let ((org-clock-resolving-clocks t))
|
|
|
|
(dolist (file (org-files-list))
|
|
|
|
(let ((clocks (org-find-open-clocks file)))
|
|
|
|
(dolist (clock clocks)
|
|
|
|
(let ((dangling (or (not (org-clock-is-active))
|
|
|
|
(/= (car clock) org-clock-marker))))
|
2010-05-16 13:20:39 -04:00
|
|
|
(if (or (not only-dangling-p) dangling)
|
2012-08-11 13:10:44 -04:00
|
|
|
(org-clock-resolve
|
|
|
|
clock
|
|
|
|
(or prompt-fn
|
|
|
|
(function
|
|
|
|
(lambda (clock)
|
|
|
|
(format
|
|
|
|
"Dangling clock started %d mins ago"
|
2014-10-28 21:42:51 -04:00
|
|
|
(floor (- (org-float-time)
|
|
|
|
(org-float-time (cdr clock)))
|
|
|
|
60)))))
|
2012-08-11 13:10:44 -04:00
|
|
|
(or last-valid
|
|
|
|
(cdr clock)))))))))))
|
2009-10-17 04:38:36 -04:00
|
|
|
|
2009-10-16 22:28:15 -04:00
|
|
|
(defun org-emacs-idle-seconds ()
|
|
|
|
"Return the current Emacs idle time in seconds, or nil if not idle."
|
|
|
|
(let ((idle-time (current-idle-time)))
|
|
|
|
(if idle-time
|
2009-10-17 11:55:59 -04:00
|
|
|
(org-float-time idle-time)
|
2009-10-16 22:28:15 -04:00
|
|
|
0)))
|
|
|
|
|
|
|
|
(defun org-mac-idle-seconds ()
|
2010-07-15 16:26:51 -04:00
|
|
|
"Return the current Mac idle time in seconds."
|
2009-10-16 22:28:15 -04:00
|
|
|
(string-to-number (shell-command-to-string "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle; last}'")))
|
|
|
|
|
2012-07-28 05:53:05 -04:00
|
|
|
(defvar org-x11idle-exists-p
|
|
|
|
;; Check that x11idle exists
|
2012-08-29 07:25:39 -04:00
|
|
|
(and (eq window-system 'x)
|
2015-04-15 22:04:45 -04:00
|
|
|
(eq 0 (call-process-shell-command
|
|
|
|
(format "command -v %s" org-clock-x11idle-program-name)))
|
2012-07-28 05:53:05 -04:00
|
|
|
;; Check that x11idle can retrieve the idle time
|
2015-04-15 22:04:45 -04:00
|
|
|
;; FIXME: Why "..-shell-command" rather than just `call-process'?
|
|
|
|
(eq 0 (call-process-shell-command org-clock-x11idle-program-name))))
|
2012-07-28 05:53:05 -04:00
|
|
|
|
2009-10-21 05:52:48 -04:00
|
|
|
(defun org-x11-idle-seconds ()
|
2010-07-15 16:26:51 -04:00
|
|
|
"Return the current X11 idle time in seconds."
|
2013-01-11 17:16:45 -05:00
|
|
|
(/ (string-to-number (shell-command-to-string org-clock-x11idle-program-name)) 1000))
|
2009-10-21 05:52:48 -04:00
|
|
|
|
2009-10-16 22:28:15 -04:00
|
|
|
(defun org-user-idle-seconds ()
|
|
|
|
"Return the number of seconds the user has been idle for.
|
|
|
|
This routine returns a floating point number."
|
2009-12-25 18:02:48 -05:00
|
|
|
(cond
|
|
|
|
((eq system-type 'darwin)
|
|
|
|
(org-mac-idle-seconds))
|
2012-07-28 05:53:05 -04:00
|
|
|
((and (eq window-system 'x) org-x11idle-exists-p)
|
2012-07-28 02:35:04 -04:00
|
|
|
(org-x11-idle-seconds))
|
|
|
|
(t
|
|
|
|
(org-emacs-idle-seconds))))
|
2009-10-16 22:28:15 -04:00
|
|
|
|
2009-10-22 06:22:36 -04:00
|
|
|
(defvar org-clock-user-idle-seconds)
|
|
|
|
|
2009-10-17 04:56:45 -04:00
|
|
|
(defun org-resolve-clocks-if-idle ()
|
|
|
|
"Resolve all currently open org-mode clocks.
|
|
|
|
This is performed after `org-clock-idle-time' minutes, to check
|
|
|
|
if the user really wants to stay clocked in after being idle for
|
|
|
|
so long."
|
|
|
|
(when (and org-clock-idle-time (not org-clock-resolving-clocks)
|
2013-04-04 03:42:57 -04:00
|
|
|
org-clock-marker (marker-buffer org-clock-marker))
|
2009-12-25 18:02:48 -05:00
|
|
|
(let* ((org-clock-user-idle-seconds (org-user-idle-seconds))
|
|
|
|
(org-clock-user-idle-start
|
|
|
|
(time-subtract (current-time)
|
|
|
|
(seconds-to-time org-clock-user-idle-seconds)))
|
|
|
|
(org-clock-resolving-clocks-due-to-idleness t))
|
2009-10-22 06:22:36 -04:00
|
|
|
(if (> org-clock-user-idle-seconds (* 60 org-clock-idle-time))
|
2009-10-17 04:56:45 -04:00
|
|
|
(org-clock-resolve
|
|
|
|
(cons org-clock-marker
|
|
|
|
org-clock-start-time)
|
|
|
|
(function
|
|
|
|
(lambda (clock)
|
2009-11-05 02:07:06 -05:00
|
|
|
(format "Clocked in & idle for %.1f mins"
|
2009-11-03 04:35:05 -05:00
|
|
|
(/ (org-float-time
|
2009-10-31 18:12:08 -04:00
|
|
|
(time-subtract (current-time)
|
2009-11-05 02:07:06 -05:00
|
|
|
org-clock-user-idle-start))
|
|
|
|
60.0))))
|
|
|
|
org-clock-user-idle-start)))))
|
2009-10-17 04:56:45 -04:00
|
|
|
|
2013-02-19 06:59:46 -05:00
|
|
|
(defvar org-clock-current-task nil "Task currently clocked in.")
|
2012-07-12 19:45:49 -04:00
|
|
|
(defvar org-clock-out-time nil) ; store the time of the last clock-out
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 14:57:31 -05:00
|
|
|
(defvar org--msg-extra)
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
2010-05-16 11:42:53 -04:00
|
|
|
(defun org-clock-in (&optional select start-time)
|
2008-04-03 11:58:13 -04:00
|
|
|
"Start the clock on the current item.
|
2008-04-25 02:18:49 -04:00
|
|
|
If necessary, clock-out of the currently active clock.
|
2012-08-09 08:52:38 -04:00
|
|
|
With a prefix argument SELECT (\\[universal-argument]), offer a list of recently clocked
|
|
|
|
tasks to clock into. When SELECT is \\[universal-argument] \\[universal-argument], clock into the current task
|
|
|
|
and mark it as the default task, a special task that will always be offered
|
|
|
|
in the clocking selection, associated with the letter `d'.
|
2012-07-12 08:04:54 -04:00
|
|
|
When SELECT is \\[universal-argument] \\[universal-argument] \\[universal-argument], \
|
2012-08-09 08:52:38 -04:00
|
|
|
clock in by using the last clock-out
|
|
|
|
time as the start time \(see `org-clock-continuously' to
|
|
|
|
make this the default behavior.)"
|
2008-04-25 02:18:49 -04:00
|
|
|
(interactive "P")
|
2009-06-09 10:51:52 -04:00
|
|
|
(setq org-clock-notification-was-shown nil)
|
2014-05-23 10:51:55 -04:00
|
|
|
(org-refresh-properties
|
|
|
|
org-effort-property '((effort . identity)
|
|
|
|
(effort-minutes . org-duration-string-to-minutes)))
|
2008-11-23 02:07:56 -05:00
|
|
|
(catch 'abort
|
2009-10-17 04:56:45 -04:00
|
|
|
(let ((interrupting (and (not org-clock-resolving-clocks-due-to-idleness)
|
2010-03-09 11:10:15 -05:00
|
|
|
(org-clocking-p)))
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 14:57:31 -05:00
|
|
|
ts selected-task target-pos (org--msg-extra "")
|
2010-03-27 11:49:17 -04:00
|
|
|
(leftover (and (not org-clock-resolving-clocks)
|
2012-08-11 13:10:44 -04:00
|
|
|
org-clock-leftover-time)))
|
2011-03-10 01:40:20 -05:00
|
|
|
|
2009-10-25 18:03:23 -04:00
|
|
|
(when (and org-clock-auto-clock-resolution
|
|
|
|
(or (not interrupting)
|
|
|
|
(eq t org-clock-auto-clock-resolution))
|
|
|
|
(not org-clock-clocking-in)
|
|
|
|
(not org-clock-resolving-clocks))
|
2010-03-27 11:49:17 -04:00
|
|
|
(setq org-clock-leftover-time nil)
|
2009-10-17 04:38:36 -04:00
|
|
|
(let ((org-clock-clocking-in t))
|
|
|
|
(org-resolve-clocks))) ; check if any clocks are dangling
|
2011-03-10 01:40:20 -05:00
|
|
|
|
2012-07-12 08:04:54 -04:00
|
|
|
(when (equal select '(64))
|
|
|
|
;; Set start-time to `org-clock-out-time'
|
|
|
|
(let ((org-clock-continuously t))
|
|
|
|
(org-clock-in nil org-clock-out-time)))
|
|
|
|
|
2008-11-23 02:07:56 -05:00
|
|
|
(when (equal select '(4))
|
|
|
|
(setq selected-task (org-clock-select-task "Clock-in on task: "))
|
|
|
|
(if selected-task
|
|
|
|
(setq selected-task (copy-marker selected-task))
|
|
|
|
(error "Abort")))
|
2011-03-10 01:40:20 -05:00
|
|
|
|
|
|
|
(when (equal select '(16))
|
|
|
|
;; Mark as default clocking task
|
|
|
|
(org-clock-mark-default-task))
|
|
|
|
|
2008-11-23 02:07:56 -05:00
|
|
|
(when interrupting
|
2008-12-16 09:31:41 -05:00
|
|
|
;; We are interrupting the clocking of a different task.
|
2008-11-23 02:07:56 -05:00
|
|
|
;; Save a marker to this task, so that we can go back.
|
2009-11-27 02:09:10 -05:00
|
|
|
;; First check if we are trying to clock into the same task!
|
2010-10-03 16:21:59 -04:00
|
|
|
(when (save-excursion
|
2009-11-27 02:09:10 -05:00
|
|
|
(unless selected-task
|
|
|
|
(org-back-to-heading t))
|
|
|
|
(and (equal (marker-buffer org-clock-hd-marker)
|
|
|
|
(if selected-task
|
|
|
|
(marker-buffer selected-task)
|
|
|
|
(current-buffer)))
|
|
|
|
(= (marker-position org-clock-hd-marker)
|
|
|
|
(if selected-task
|
|
|
|
(marker-position selected-task)
|
2011-03-10 01:40:21 -05:00
|
|
|
(point)))
|
|
|
|
(equal org-clock-current-task (nth 4 (org-heading-components)))))
|
2010-10-03 16:21:59 -04:00
|
|
|
(message "Clock continues in \"%s\"" org-clock-heading)
|
|
|
|
(throw 'abort nil))
|
|
|
|
(move-marker org-clock-interrupted-task
|
|
|
|
(marker-position org-clock-marker)
|
|
|
|
(marker-buffer org-clock-marker))
|
2010-10-03 11:47:15 -04:00
|
|
|
(let ((org-clock-clocking-in t))
|
2012-08-09 08:52:38 -04:00
|
|
|
(org-clock-out nil t)))
|
2009-11-27 02:09:10 -05:00
|
|
|
|
2009-10-02 02:40:02 -04:00
|
|
|
;; Clock in at which position?
|
|
|
|
(setq target-pos
|
2012-01-02 13:52:35 -05:00
|
|
|
(if (and (eobp) (not (org-at-heading-p)))
|
2009-10-02 02:40:02 -04:00
|
|
|
(point-at-bol 0)
|
|
|
|
(point)))
|
2008-11-23 02:07:56 -05:00
|
|
|
(save-excursion
|
|
|
|
(when (and selected-task (marker-buffer selected-task))
|
|
|
|
;; There is a selected task, move to the correct buffer
|
|
|
|
;; and set the new target position.
|
|
|
|
(set-buffer (org-base-buffer (marker-buffer selected-task)))
|
|
|
|
(setq target-pos (marker-position selected-task))
|
|
|
|
(move-marker selected-task nil))
|
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-char target-pos)
|
|
|
|
(org-back-to-heading t)
|
|
|
|
(or interrupting (move-marker org-clock-interrupted-task nil))
|
2013-04-24 04:47:16 -04:00
|
|
|
(run-hooks 'org-clock-in-prepare-hook)
|
|
|
|
(org-clock-history-push)
|
2013-02-19 06:59:46 -05:00
|
|
|
(setq org-clock-current-task (nth 4 (org-heading-components)))
|
2008-11-23 02:07:56 -05:00
|
|
|
(cond ((functionp org-clock-in-switch-to-state)
|
|
|
|
(looking-at org-complex-heading-regexp)
|
|
|
|
(let ((newstate (funcall org-clock-in-switch-to-state
|
|
|
|
(match-string 2))))
|
|
|
|
(if newstate (org-todo newstate))))
|
|
|
|
((and org-clock-in-switch-to-state
|
Don't use `outline-regexp' anymore.
Use `org-outline-regexp' instead or `outline-regexp'. Also use the
new defconst `org-outline-regexp-bol' to match `org-outline-regexp'
at the beginning of line.
* org.el (org-outline-regexp-bol): New defconst.
(org-outline-level, org-set-font-lock-defaults, org-cycle)
(org-overview, org-content, org-flag-drawer)
(org-first-headline-recenter, org-insert-todo-heading)
(org-map-region, org-move-subtree-down, org-paste-subtree)
(org-kill-is-subtree-p, org-context-p, org-refile)
(org-refile-new-child, org-toggle-comment, org-todo)
(org-add-planning-info, org-add-log-setup, org-scan-tags)
(org-set-tags, org-insert-property-drawer)
(org-prepare-agenda-buffers, org-preview-latex-fragment)
(org-speed-command-default-hook, org-check-for-hidden)
(org-toggle-item, org-toggle-heading)
(org-indent-line-function, org-set-autofill-regexps)
(org-fill-paragraph, org-toggle-fixed-width-section)
(org-yank-generic, org-yank-folding-would-swallow-text)
(org-first-sibling-p, org-goto-sibling)
(org-goto-first-child, org-show-entry): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-remember.el (org-remember-handler): Use
`org-outline-regexp-bol'.
* org-mouse.el (org-mouse-match-todo-keyword, org-mode-hook)
(org-mouse-move-tree, org-mouse-transform-to-outline): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-macs.el (org-with-limited-levels)
(org-get-limited-outline-regexp): Use `org-outline-regexp'.
* org-indent.el (org-indent-outline-re)
(org-indent-refresh-section, org-indent-refresh-to): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-html.el (org-export-as-html): Use
`org-outline-regexp-bol'.
* org-footnote.el (org-footnote-at-definition-p)
(org-footnote-normalize): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-exp.el (org-export-preprocess-string): Don't redefine
`outline-regexp'.
* org-docbook.el (org-export-as-docbook): Use
`org-outline-regexp-bol'.
* org-colview.el (org-columns, org-columns-compute): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-colview-xemacs.el (org-columns, org-columns-compute):
Use `org-outline-regexp-bol'.
* org-clock.el (org-clock-insert-selection-line)
(org-clock-in, org-clock-out, org-dblock-write:clocktable):
Use `org-outline-regexp' and `org-outline-regexp-bol'.
* org-ascii.el (org-export-as-ascii)
(org-export-ascii-push-links): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-archive.el (org-archive-to-archive-sibling)
(org-archive-all-done): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-agenda.el (org-agenda, org-search-view)
(org-agenda-list-stuck-projects, org-agenda-get-timestamps)
(org-agenda-get-progress, org-agenda-get-blocks): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
2011-07-17 15:17:08 -04:00
|
|
|
(not (looking-at (concat org-outline-regexp "[ \t]*"
|
2008-11-23 02:07:56 -05:00
|
|
|
org-clock-in-switch-to-state
|
|
|
|
"\\>"))))
|
|
|
|
(org-todo org-clock-in-switch-to-state)))
|
|
|
|
(setq org-clock-heading
|
|
|
|
(cond ((and org-clock-heading-function
|
|
|
|
(functionp org-clock-heading-function))
|
|
|
|
(funcall org-clock-heading-function))
|
2013-02-19 06:59:46 -05:00
|
|
|
((nth 4 (org-heading-components))
|
2010-01-26 17:01:59 -05:00
|
|
|
(replace-regexp-in-string
|
|
|
|
"\\[\\[.*?\\]\\[\\(.*?\\)\\]\\]" "\\1"
|
2013-02-19 06:59:46 -05:00
|
|
|
(match-string-no-properties 4)))
|
2008-11-23 02:07:56 -05:00
|
|
|
(t "???")))
|
2009-04-14 06:40:25 -04:00
|
|
|
(org-clock-find-position org-clock-in-resume)
|
2008-11-23 02:07:56 -05:00
|
|
|
(cond
|
|
|
|
((and org-clock-in-resume
|
|
|
|
(looking-at
|
2011-12-31 03:05:11 -05:00
|
|
|
(concat "^[ \t]*" org-clock-string
|
2008-11-23 02:07:56 -05:00
|
|
|
" \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"
|
2015-09-17 19:08:20 -04:00
|
|
|
" *\\sw+.? +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$")))
|
2008-11-23 02:07:56 -05:00
|
|
|
(message "Matched %s" (match-string 1))
|
|
|
|
(setq ts (concat "[" (match-string 1) "]"))
|
|
|
|
(goto-char (match-end 1))
|
|
|
|
(setq org-clock-start-time
|
|
|
|
(apply 'encode-time
|
2009-05-28 07:24:23 -04:00
|
|
|
(org-parse-time-string (match-string 1))))
|
2013-01-23 08:48:52 -05:00
|
|
|
(setq org-clock-effort (org-entry-get (point) org-effort-property))
|
2009-06-02 07:12:43 -04:00
|
|
|
(setq org-clock-total-time (org-clock-sum-current-item
|
|
|
|
(org-clock-get-sum-start))))
|
2008-11-23 02:07:56 -05:00
|
|
|
((eq org-clock-in-resume 'auto-restart)
|
|
|
|
;; called from org-clock-load during startup,
|
|
|
|
;; do not interrupt, but warn!
|
|
|
|
(message "Cannot restart clock because task does not contain unfinished clock")
|
|
|
|
(ding)
|
|
|
|
(sit-for 2)
|
|
|
|
(throw 'abort nil))
|
|
|
|
(t
|
2009-02-11 09:01:13 -05:00
|
|
|
(insert-before-markers "\n")
|
|
|
|
(backward-char 1)
|
2012-07-11 13:11:26 -04:00
|
|
|
(org-indent-line)
|
2009-02-14 19:15:37 -05:00
|
|
|
(when (and (save-excursion
|
|
|
|
(end-of-line 0)
|
|
|
|
(org-in-item-p)))
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(org-indent-line-to (- (org-get-indentation) 2)))
|
2008-10-22 21:31:37 -04:00
|
|
|
(insert org-clock-string " ")
|
2013-01-23 08:48:52 -05:00
|
|
|
(setq org-clock-effort (org-entry-get (point) org-effort-property))
|
2009-06-02 07:12:43 -04:00
|
|
|
(setq org-clock-total-time (org-clock-sum-current-item
|
|
|
|
(org-clock-get-sum-start)))
|
2009-10-17 04:56:45 -04:00
|
|
|
(setq org-clock-start-time
|
2012-07-12 08:04:54 -04:00
|
|
|
(or (and org-clock-continuously org-clock-out-time)
|
|
|
|
(and leftover
|
2009-10-17 04:56:45 -04:00
|
|
|
(y-or-n-p
|
|
|
|
(format
|
|
|
|
"You stopped another clock %d mins ago; start this one from then? "
|
2012-12-29 12:45:07 -05:00
|
|
|
(/ (- (org-float-time
|
2013-02-19 06:40:33 -05:00
|
|
|
(org-current-time org-clock-rounding-minutes t))
|
2010-03-27 11:49:17 -04:00
|
|
|
(org-float-time leftover)) 60)))
|
|
|
|
leftover)
|
2010-05-16 11:42:53 -04:00
|
|
|
start-time
|
2013-02-19 06:40:33 -05:00
|
|
|
(org-current-time org-clock-rounding-minutes t)))
|
2009-05-28 07:24:23 -04:00
|
|
|
(setq ts (org-insert-time-stamp org-clock-start-time
|
|
|
|
'with-hm 'inactive))))
|
2008-11-23 02:07:56 -05:00
|
|
|
(move-marker org-clock-marker (point) (buffer-base-buffer))
|
2009-08-07 05:00:16 -04:00
|
|
|
(move-marker org-clock-hd-marker
|
|
|
|
(save-excursion (org-back-to-heading t) (point))
|
|
|
|
(buffer-base-buffer))
|
2009-10-25 02:48:05 -04:00
|
|
|
(setq org-clock-has-been-used t)
|
2012-02-29 12:04:22 -05:00
|
|
|
;; add to mode line
|
|
|
|
(when (or (eq org-clock-clocked-in-display 'mode-line)
|
|
|
|
(eq org-clock-clocked-in-display 'both))
|
|
|
|
(or global-mode-string (setq global-mode-string '("")))
|
|
|
|
(or (memq 'org-mode-line-string global-mode-string)
|
|
|
|
(setq global-mode-string
|
|
|
|
(append global-mode-string '(org-mode-line-string)))))
|
|
|
|
;; add to frame title
|
2012-05-05 08:21:13 -04:00
|
|
|
(when (or (eq org-clock-clocked-in-display 'frame-title)
|
|
|
|
(eq org-clock-clocked-in-display 'both))
|
|
|
|
(setq frame-title-format org-clock-frame-title-format))
|
2009-01-08 05:19:37 -05:00
|
|
|
(org-clock-update-mode-line)
|
2009-10-16 22:06:09 -04:00
|
|
|
(when org-clock-mode-line-timer
|
|
|
|
(cancel-timer org-clock-mode-line-timer)
|
|
|
|
(setq org-clock-mode-line-timer nil))
|
2012-02-29 12:04:22 -05:00
|
|
|
(when org-clock-clocked-in-display
|
|
|
|
(setq org-clock-mode-line-timer
|
|
|
|
(run-with-timer org-clock-update-period
|
|
|
|
org-clock-update-period
|
|
|
|
'org-clock-update-mode-line)))
|
2009-10-17 04:56:45 -04:00
|
|
|
(when org-clock-idle-timer
|
|
|
|
(cancel-timer org-clock-idle-timer)
|
|
|
|
(setq org-clock-idle-timer nil))
|
|
|
|
(setq org-clock-idle-timer
|
|
|
|
(run-with-timer 60 60 'org-resolve-clocks-if-idle))
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 14:57:31 -05:00
|
|
|
(message "Clock starts at %s - %s" ts org--msg-extra)
|
2009-07-06 16:30:39 -04:00
|
|
|
(run-hooks 'org-clock-in-hook)))))))
|
2009-06-02 07:12:43 -04:00
|
|
|
|
2012-07-06 06:54:43 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun org-clock-in-last (&optional arg)
|
|
|
|
"Clock in the last closed clocked item.
|
2012-07-12 08:04:54 -04:00
|
|
|
When already clocking in, send an warning.
|
|
|
|
With a universal prefix argument, select the task you want to
|
|
|
|
clock in from the last clocked in tasks.
|
|
|
|
With two universal prefix arguments, start clocking using the
|
2012-08-09 08:52:38 -04:00
|
|
|
last clock-out time, if any.
|
|
|
|
With three universal prefix arguments, interactively prompt
|
|
|
|
for a todo state to switch to, overriding the existing value
|
|
|
|
`org-clock-in-switch-to-state'."
|
2012-07-06 06:54:43 -04:00
|
|
|
(interactive "P")
|
2015-01-31 06:46:50 -05:00
|
|
|
(if (equal arg '(4)) (org-clock-in arg)
|
2012-07-12 08:04:54 -04:00
|
|
|
(let ((start-time (if (or org-clock-continuously (equal arg '(16)))
|
2012-12-29 12:45:07 -05:00
|
|
|
(or org-clock-out-time
|
2013-02-19 06:40:33 -05:00
|
|
|
(org-current-time org-clock-rounding-minutes t))
|
|
|
|
(org-current-time org-clock-rounding-minutes t))))
|
2012-07-14 02:33:48 -04:00
|
|
|
(if (null org-clock-history)
|
|
|
|
(message "No last clock")
|
2012-08-09 08:52:38 -04:00
|
|
|
(let ((org-clock-in-switch-to-state
|
|
|
|
(if (and (not org-clock-current-task) (equal arg '(64)))
|
|
|
|
(completing-read "Switch to state: "
|
|
|
|
(and org-clock-history
|
|
|
|
(with-current-buffer
|
|
|
|
(marker-buffer (car org-clock-history))
|
|
|
|
org-todo-keywords-1)))
|
|
|
|
org-clock-in-switch-to-state))
|
|
|
|
(already-clocking org-clock-current-task))
|
|
|
|
(org-clock-clock-in (list (car org-clock-history)) nil start-time)
|
|
|
|
(or already-clocking
|
|
|
|
;; Don't display a message if we are already clocking in
|
|
|
|
(message "Clocking back: %s (in %s)"
|
|
|
|
org-clock-current-task
|
|
|
|
(buffer-name (marker-buffer org-clock-marker)))))))))
|
2012-07-06 06:54:43 -04:00
|
|
|
|
2009-06-17 01:40:09 -04:00
|
|
|
(defun org-clock-mark-default-task ()
|
|
|
|
"Mark current task as default task."
|
|
|
|
(interactive)
|
|
|
|
(save-excursion
|
|
|
|
(org-back-to-heading t)
|
|
|
|
(move-marker org-clock-default-task (point))))
|
|
|
|
|
2009-06-02 07:12:43 -04:00
|
|
|
(defun org-clock-get-sum-start ()
|
2009-06-02 10:36:16 -04:00
|
|
|
"Return the time from which clock times should be counted.
|
|
|
|
This is for the currently running clock as it is displayed
|
|
|
|
in the mode line. This function looks at the properties
|
|
|
|
LAST_REPEAT and in particular CLOCK_MODELINE_TOTAL and the
|
2012-10-24 05:21:44 -04:00
|
|
|
corresponding variable `org-clock-mode-line-total' and then
|
2009-06-02 10:36:16 -04:00
|
|
|
decides which time to use."
|
2009-06-02 07:12:43 -04:00
|
|
|
(let ((cmt (or (org-entry-get nil "CLOCK_MODELINE_TOTAL")
|
2012-10-24 05:21:44 -04:00
|
|
|
(symbol-name org-clock-mode-line-total)))
|
2009-06-02 07:12:43 -04:00
|
|
|
(lr (org-entry-get nil "LAST_REPEAT")))
|
|
|
|
(cond
|
|
|
|
((equal cmt "current")
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 14:57:31 -05:00
|
|
|
(setq org--msg-extra "showing time in current clock instance")
|
2009-06-02 07:12:43 -04:00
|
|
|
(current-time))
|
|
|
|
((equal cmt "today")
|
2013-11-12 15:11:23 -05:00
|
|
|
(setq org--msg-extra "showing today's task time.")
|
2015-07-26 23:56:50 -04:00
|
|
|
(let* ((dt (decode-time))
|
2013-10-17 01:41:49 -04:00
|
|
|
(hour (nth 2 dt))
|
|
|
|
(day (nth 3 dt)))
|
|
|
|
(if (< hour org-extend-today-until) (setf (nth 3 dt) (1- day)))
|
|
|
|
(setf (nth 2 dt) org-extend-today-until)
|
|
|
|
(setq dt (append (list 0 0) (nthcdr 2 dt)))
|
2009-06-02 07:12:43 -04:00
|
|
|
(apply 'encode-time dt)))
|
|
|
|
((or (equal cmt "all")
|
|
|
|
(and (or (not cmt) (equal cmt "auto"))
|
|
|
|
(not lr)))
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 14:57:31 -05:00
|
|
|
(setq org--msg-extra "showing entire task time.")
|
2009-06-02 07:12:43 -04:00
|
|
|
nil)
|
|
|
|
((or (equal cmt "repeat")
|
|
|
|
(and (or (not cmt) (equal cmt "auto"))
|
|
|
|
lr))
|
Backport changes from Emacs revs 115081 and 115082
2013-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
Address some byte-compiler warnings.
* ob-abc.el (org-babel-expand-body:abc): Use dolist.
(org-babel-execute:abc): Fix regexp quoting.
* ob-calc.el (org--var-syms): Rename from `var-syms'.
* ob-lilypond.el (ly-compile-lilyfile): Remove redundant let-binding.
* ob-table.el (sbe): Move debug declaration.
* org-clock.el (org--msg-extra): Rename from `msg-extra'.
* org.el (org-version): Avoid var name starting with _.
(org-inhibit-startup, org-called-with-limited-levels)
(org-link-search-inhibit-query, org-time-was-given)
(org-end-time-was-given, org-def, org-defdecode, org-with-time):
* org-colview.el (org-agenda-overriding-columns-format):
* org-agenda.el (org-agenda-multi, org-depend-tag-blocked)
(org-agenda-show-log-scoped):
* ob-python.el (py-which-bufname, python-shell-buffer-name):
* ob-haskell.el (org-export-copy-to-kill-ring):
* ob-exp.el (org-link-search-inhibit-query):
* ob-R.el (ess-eval-visibly-p):
* ob-core.el (org-src-window-setup): Declare before use.
(org-babel-expand-noweb-references): Remove unused `blocks-in-buffer'.
* ox-odt.el (org-odt-hfy-face-to-css):
* org-src.el (org-src-associate-babel-session, org-src-get-lang-mode):
* org-bibtex.el (org-bibtex-get, org-bibtex-ask, org-bibtex)
(org-bibtex-check):
* ob-tangle.el (org-babel-tangle, org-babel-spec-to-string)
(org-babel-tangle-single-block, org-babel-tangle-comment-links):
* ob-table.el (sbe):
* ob-sqlite.el (org-babel-sqlite-expand-vars):
* ob-sql.el (org-babel-sql-expand-vars):
* ob-shen.el (org-babel-execute:shen):
* ob-sh.el (org-babel-execute:sh, org-babel-sh-evaluate):
* ob-scala.el (org-babel-scala-evaluate):
* ob-ruby.el (org-babel-ruby-table-or-string)
(org-babel-ruby-evaluate):
* ob-python.el (org-babel-python-table-or-string)
(org-babel-python-evaluate-external-process)
(org-babel-python-evaluate-session):
* ob-picolisp.el (org-babel-execute:picolisp):
* ob-perl.el (org-babel-perl-evaluate):
* ob-maxima.el (org-babel-execute:maxima):
* ob-lisp.el (org-babel-execute:lisp):
* ob-java.el (org-babel-execute:java):
* ob-io.el (org-babel-io-evaluate):
* ob-haskell.el (org-babel-execute:haskell):
* ob-fortran.el (org-babel-execute:fortran):
* ob-exp.el (org-babel-exp-code):
* ob-emacs-lisp.el (org-babel-execute:emacs-lisp):
* ob-ditaa.el (org-babel-execute:ditaa):
* ob-core.el (org-babel-execute-src-block, org-babel-sha1-hash)
(org-babel-parse-header-arguments, org-babel-reassemble-table)
(org-babel-goto-src-block-head, org-babel-mark-block)
(org-babel-expand-noweb-references, org-babel-script-escape)
(org-babel-process-file-name):
* ob-clojure.el (org-babel-execute:clojure):
* ob-calc.el (org-babel-execute:calc):
* ob-awk.el (org-babel-execute:awk):
* ob-abc.el (org-babel-execute:abc):
* ob-R.el (org-babel-expand-body:R):
* ob-C.el (org-babel-C-execute): Avoid deprecated ((lambda) ...).
2013-11-12 Glenn Morris <rgm@gnu.org>
* ox-html.el (org-html-scripts): Add 2013 to copyright years.
(org-html-infojs-template): Copyright holder to FSF.
2013-11-12 14:57:31 -05:00
|
|
|
(setq org--msg-extra "showing task time since last repeat.")
|
2009-06-02 07:12:43 -04:00
|
|
|
(if (not lr)
|
|
|
|
nil
|
|
|
|
(org-time-string-to-time lr)))
|
|
|
|
(t nil))))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2009-04-14 03:50:05 -04:00
|
|
|
(defun org-clock-find-position (find-unclosed)
|
|
|
|
"Find the location where the next clock line should be inserted.
|
|
|
|
When FIND-UNCLOSED is non-nil, first check if there is an unclosed clock
|
|
|
|
line and position cursor in that line."
|
2008-04-03 11:58:13 -04:00
|
|
|
(org-back-to-heading t)
|
|
|
|
(catch 'exit
|
2015-10-25 10:51:53 -04:00
|
|
|
(let* ((beg (line-beginning-position))
|
2014-09-20 16:33:05 -04:00
|
|
|
(end (save-excursion (outline-next-heading) (point)))
|
|
|
|
(org-clock-into-drawer (org-clock-into-drawer))
|
2015-09-01 04:29:33 -04:00
|
|
|
(drawer (org-clock-drawer-name)))
|
2014-09-20 16:33:05 -04:00
|
|
|
;; Look for a running clock if FIND-UNCLOSED in non-nil.
|
|
|
|
(when find-unclosed
|
|
|
|
(let ((open-clock-re
|
|
|
|
(concat "^[ \t]*"
|
|
|
|
org-clock-string
|
|
|
|
" \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"
|
|
|
|
" *\\sw+ +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$")))
|
|
|
|
(while (re-search-forward open-clock-re end t)
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
(when (and (eq (org-element-type element) 'clock)
|
|
|
|
(eq (org-element-property :status element) 'running))
|
|
|
|
(beginning-of-line)
|
|
|
|
(throw 'exit t))))))
|
|
|
|
;; Look for an existing clock drawer.
|
|
|
|
(when drawer
|
|
|
|
(goto-char beg)
|
2014-12-14 12:22:31 -05:00
|
|
|
(let ((drawer-re (concat "^[ \t]*:" (regexp-quote drawer) ":[ \t]*$")))
|
2014-09-20 16:33:05 -04:00
|
|
|
(while (re-search-forward drawer-re end t)
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
(when (eq (org-element-type element) 'drawer)
|
|
|
|
(let ((cend (org-element-property :contents-end element)))
|
|
|
|
(if (and (not org-log-states-order-reversed) cend)
|
|
|
|
(goto-char cend)
|
|
|
|
(forward-line))
|
|
|
|
(throw 'exit t)))))))
|
2008-04-03 11:58:13 -04:00
|
|
|
(goto-char beg)
|
2014-09-20 16:33:05 -04:00
|
|
|
(let ((clock-re (concat "^[ \t]*" org-clock-string))
|
|
|
|
(count 0) positions first)
|
|
|
|
;; Count the CLOCK lines and store their positions.
|
|
|
|
(save-excursion
|
|
|
|
(while (re-search-forward clock-re end t)
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
(when (eq (org-element-type element) 'clock)
|
|
|
|
(setq positions (cons (line-beginning-position) positions)
|
|
|
|
count (1+ count))))))
|
|
|
|
(cond
|
|
|
|
((null positions)
|
|
|
|
;; Skip planning line and property drawer, if any.
|
2015-10-17 19:39:36 -04:00
|
|
|
(org-end-of-meta-data)
|
2014-09-20 16:33:05 -04:00
|
|
|
(unless (bolp) (insert "\n"))
|
|
|
|
;; Create a new drawer if necessary.
|
2014-12-03 09:24:40 -05:00
|
|
|
(when (and org-clock-into-drawer
|
|
|
|
(or (not (wholenump org-clock-into-drawer))
|
|
|
|
(< org-clock-into-drawer 2)))
|
2014-09-20 16:33:05 -04:00
|
|
|
(let ((beg (point)))
|
|
|
|
(insert ":" drawer ":\n:END:\n")
|
|
|
|
(org-indent-region beg (point))
|
|
|
|
(goto-char beg)
|
|
|
|
(org-flag-drawer t)
|
|
|
|
(forward-line))))
|
|
|
|
;; When a clock drawer needs to be created because of the
|
2015-10-17 19:39:36 -04:00
|
|
|
;; number of clock items or simply if it is missing, collect
|
|
|
|
;; all clocks in the section and wrap them within the drawer.
|
|
|
|
((or drawer
|
|
|
|
(and (wholenump org-clock-into-drawer)
|
|
|
|
(>= (1+ count) org-clock-into-drawer)))
|
2014-09-20 16:33:05 -04:00
|
|
|
;; Skip planning line and property drawer, if any.
|
2015-10-17 19:39:36 -04:00
|
|
|
(org-end-of-meta-data)
|
2014-09-20 16:33:05 -04:00
|
|
|
(let ((beg (point)))
|
|
|
|
(insert
|
|
|
|
(mapconcat
|
|
|
|
(lambda (p)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char p)
|
|
|
|
(org-trim (delete-and-extract-region
|
|
|
|
(save-excursion (skip-chars-backward " \r\t\n")
|
|
|
|
(line-beginning-position 2))
|
|
|
|
(line-beginning-position 2)))))
|
|
|
|
positions "\n")
|
|
|
|
"\n:END:\n")
|
|
|
|
(let ((end (point-marker)))
|
|
|
|
(goto-char beg)
|
|
|
|
(save-excursion (insert ":" drawer ":\n"))
|
|
|
|
(org-flag-drawer t)
|
|
|
|
(org-indent-region (point) end)
|
|
|
|
(forward-line)
|
|
|
|
(unless org-log-states-order-reversed
|
|
|
|
(goto-char end)
|
|
|
|
(beginning-of-line -1))
|
|
|
|
(set-marker end nil))))
|
|
|
|
(org-log-states-order-reversed (goto-char (car (last positions))))
|
|
|
|
(t (goto-char (car positions))))))))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2012-08-09 08:52:38 -04:00
|
|
|
(defun org-clock-out (&optional switch-to-state fail-quietly at-time)
|
2008-04-03 11:58:13 -04:00
|
|
|
"Stop the currently running clock.
|
2012-08-09 08:52:38 -04:00
|
|
|
Throw an error if there is no running clock and FAIL-QUIETLY is nil.
|
|
|
|
With a universal prefix, prompt for a state to switch the clocked out task
|
|
|
|
to, overriding the existing value of `org-clock-out-switch-to-state'."
|
|
|
|
(interactive "P")
|
2008-04-03 11:58:13 -04:00
|
|
|
(catch 'exit
|
2010-04-25 18:02:49 -04:00
|
|
|
(when (not (org-clocking-p))
|
|
|
|
(setq global-mode-string
|
|
|
|
(delq 'org-mode-line-string global-mode-string))
|
2012-05-05 08:21:13 -04:00
|
|
|
(setq frame-title-format org-frame-title-format-backup)
|
2010-04-25 18:02:49 -04:00
|
|
|
(force-mode-line-update)
|
2012-12-11 12:11:24 -05:00
|
|
|
(if fail-quietly (throw 'exit t) (user-error "No active clock")))
|
2012-08-09 08:52:38 -04:00
|
|
|
(let ((org-clock-out-switch-to-state
|
|
|
|
(if switch-to-state
|
|
|
|
(completing-read "Switch to state: "
|
|
|
|
(with-current-buffer
|
|
|
|
(marker-buffer org-clock-marker)
|
|
|
|
org-todo-keywords-1)
|
|
|
|
nil t "DONE")
|
|
|
|
org-clock-out-switch-to-state))
|
2012-12-29 12:45:07 -05:00
|
|
|
(now (org-current-time org-clock-rounding-minutes))
|
2012-08-09 08:52:38 -04:00
|
|
|
ts te s h m remove)
|
2012-07-12 08:04:54 -04:00
|
|
|
(setq org-clock-out-time now)
|
2010-04-18 10:39:44 -04:00
|
|
|
(save-excursion ; Do not replace this with `with-current-buffer'.
|
2012-05-18 07:16:11 -04:00
|
|
|
(org-no-warnings (set-buffer (org-clocking-buffer)))
|
2009-05-25 10:54:03 -04:00
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(goto-char org-clock-marker)
|
2008-04-21 16:05:46 -04:00
|
|
|
(beginning-of-line 1)
|
2009-05-25 10:54:03 -04:00
|
|
|
(if (and (looking-at (concat "[ \t]*" org-keyword-time-regexp))
|
|
|
|
(equal (match-string 1) org-clock-string))
|
|
|
|
(setq ts (match-string 2))
|
|
|
|
(if fail-quietly (throw 'exit nil) (error "Clock start time is gone")))
|
|
|
|
(goto-char (match-end 0))
|
2008-04-21 16:05:46 -04:00
|
|
|
(delete-region (point) (point-at-eol))
|
2009-05-25 10:54:03 -04:00
|
|
|
(insert "--")
|
2012-07-12 08:04:54 -04:00
|
|
|
(setq te (org-insert-time-stamp (or at-time now) 'with-hm 'inactive))
|
2009-09-02 08:37:47 -04:00
|
|
|
(setq s (- (org-float-time (apply 'encode-time (org-parse-time-string te)))
|
|
|
|
(org-float-time (apply 'encode-time (org-parse-time-string ts))))
|
2009-05-25 10:54:03 -04:00
|
|
|
h (floor (/ s 3600))
|
|
|
|
s (- s (* 3600 h))
|
|
|
|
m (floor (/ s 60))
|
|
|
|
s (- s (* 60 s)))
|
|
|
|
(insert " => " (format "%2d:%02d" h m))
|
|
|
|
(when (setq remove (and org-clock-out-remove-zero-time-clocks
|
|
|
|
(= (+ h m) 0)))
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(delete-region (point) (point-at-eol))
|
|
|
|
(and (looking-at "\n") (> (point-max) (1+ (point)))
|
|
|
|
(delete-char 1)))
|
2013-04-04 03:40:02 -04:00
|
|
|
(move-marker org-clock-marker nil)
|
|
|
|
(move-marker org-clock-hd-marker nil)
|
2009-05-25 10:54:03 -04:00
|
|
|
(when org-log-note-clock-out
|
|
|
|
(org-add-log-setup 'clock-out nil nil nil nil
|
|
|
|
(concat "# Task: " (org-get-heading t) "\n\n")))
|
|
|
|
(when org-clock-mode-line-timer
|
|
|
|
(cancel-timer org-clock-mode-line-timer)
|
|
|
|
(setq org-clock-mode-line-timer nil))
|
2009-10-17 04:56:45 -04:00
|
|
|
(when org-clock-idle-timer
|
|
|
|
(cancel-timer org-clock-idle-timer)
|
|
|
|
(setq org-clock-idle-timer nil))
|
2009-05-25 10:54:03 -04:00
|
|
|
(setq global-mode-string
|
|
|
|
(delq 'org-mode-line-string global-mode-string))
|
2012-05-05 08:21:13 -04:00
|
|
|
(setq frame-title-format org-frame-title-format-backup)
|
2009-06-02 11:01:11 -04:00
|
|
|
(when org-clock-out-switch-to-state
|
|
|
|
(save-excursion
|
|
|
|
(org-back-to-heading t)
|
2010-01-15 12:16:07 -05:00
|
|
|
(let ((org-inhibit-logging t)
|
|
|
|
(org-clock-out-when-done nil))
|
2009-06-02 11:01:11 -04:00
|
|
|
(cond
|
|
|
|
((functionp org-clock-out-switch-to-state)
|
|
|
|
(looking-at org-complex-heading-regexp)
|
|
|
|
(let ((newstate (funcall org-clock-out-switch-to-state
|
|
|
|
(match-string 2))))
|
|
|
|
(if newstate (org-todo newstate))))
|
|
|
|
((and org-clock-out-switch-to-state
|
Don't use `outline-regexp' anymore.
Use `org-outline-regexp' instead or `outline-regexp'. Also use the
new defconst `org-outline-regexp-bol' to match `org-outline-regexp'
at the beginning of line.
* org.el (org-outline-regexp-bol): New defconst.
(org-outline-level, org-set-font-lock-defaults, org-cycle)
(org-overview, org-content, org-flag-drawer)
(org-first-headline-recenter, org-insert-todo-heading)
(org-map-region, org-move-subtree-down, org-paste-subtree)
(org-kill-is-subtree-p, org-context-p, org-refile)
(org-refile-new-child, org-toggle-comment, org-todo)
(org-add-planning-info, org-add-log-setup, org-scan-tags)
(org-set-tags, org-insert-property-drawer)
(org-prepare-agenda-buffers, org-preview-latex-fragment)
(org-speed-command-default-hook, org-check-for-hidden)
(org-toggle-item, org-toggle-heading)
(org-indent-line-function, org-set-autofill-regexps)
(org-fill-paragraph, org-toggle-fixed-width-section)
(org-yank-generic, org-yank-folding-would-swallow-text)
(org-first-sibling-p, org-goto-sibling)
(org-goto-first-child, org-show-entry): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-remember.el (org-remember-handler): Use
`org-outline-regexp-bol'.
* org-mouse.el (org-mouse-match-todo-keyword, org-mode-hook)
(org-mouse-move-tree, org-mouse-transform-to-outline): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-macs.el (org-with-limited-levels)
(org-get-limited-outline-regexp): Use `org-outline-regexp'.
* org-indent.el (org-indent-outline-re)
(org-indent-refresh-section, org-indent-refresh-to): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-html.el (org-export-as-html): Use
`org-outline-regexp-bol'.
* org-footnote.el (org-footnote-at-definition-p)
(org-footnote-normalize): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-exp.el (org-export-preprocess-string): Don't redefine
`outline-regexp'.
* org-docbook.el (org-export-as-docbook): Use
`org-outline-regexp-bol'.
* org-colview.el (org-columns, org-columns-compute): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-colview-xemacs.el (org-columns, org-columns-compute):
Use `org-outline-regexp-bol'.
* org-clock.el (org-clock-insert-selection-line)
(org-clock-in, org-clock-out, org-dblock-write:clocktable):
Use `org-outline-regexp' and `org-outline-regexp-bol'.
* org-ascii.el (org-export-as-ascii)
(org-export-ascii-push-links): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-archive.el (org-archive-to-archive-sibling)
(org-archive-all-done): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-agenda.el (org-agenda, org-search-view)
(org-agenda-list-stuck-projects, org-agenda-get-timestamps)
(org-agenda-get-progress, org-agenda-get-blocks): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
2011-07-17 15:17:08 -04:00
|
|
|
(not (looking-at (concat org-outline-regexp "[ \t]*"
|
2009-06-02 11:01:11 -04:00
|
|
|
org-clock-out-switch-to-state
|
|
|
|
"\\>"))))
|
|
|
|
(org-todo org-clock-out-switch-to-state))))))
|
2009-05-25 10:54:03 -04:00
|
|
|
(force-mode-line-update)
|
2012-11-11 17:20:24 -05:00
|
|
|
(message (concat "Clock stopped at %s after "
|
|
|
|
(org-minutes-to-clocksum-string (+ (* 60 h) m)) "%s")
|
|
|
|
te (if remove " => LINE REMOVED" ""))
|
2014-12-14 12:22:31 -05:00
|
|
|
(let ((h org-clock-out-hook)
|
|
|
|
(clock-drawer (org-clock-into-drawer)))
|
2013-03-02 11:39:23 -05:00
|
|
|
;; If a closing note needs to be stored in the drawer
|
|
|
|
;; where clocks are stored, let's temporarily disable
|
2014-12-14 12:22:31 -05:00
|
|
|
;; `org-clock-remove-empty-clock-drawer'.
|
|
|
|
(if (and clock-drawer
|
|
|
|
(not (stringp clock-drawer))
|
|
|
|
(org-log-into-drawer)
|
2013-03-02 11:39:23 -05:00
|
|
|
(eq org-log-done 'note)
|
|
|
|
org-clock-out-when-done)
|
|
|
|
(setq h (delq 'org-clock-remove-empty-clock-drawer h)))
|
|
|
|
(mapc (lambda (f) (funcall f)) h))
|
2012-03-19 16:38:12 -04:00
|
|
|
(unless (org-clocking-p)
|
2013-02-19 06:59:46 -05:00
|
|
|
(setq org-clock-current-task nil)))))))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2011-07-09 09:20:31 -04:00
|
|
|
(add-hook 'org-clock-out-hook 'org-clock-remove-empty-clock-drawer)
|
|
|
|
|
2015-09-01 04:29:33 -04:00
|
|
|
(defun org-clock-remove-empty-clock-drawer ()
|
|
|
|
"Remove empty clock drawers in current subtree."
|
|
|
|
(save-excursion
|
|
|
|
(org-back-to-heading t)
|
|
|
|
(org-map-tree
|
|
|
|
(lambda ()
|
|
|
|
(let ((drawer (org-clock-drawer-name))
|
|
|
|
(case-fold-search t))
|
|
|
|
(when drawer
|
|
|
|
(let ((re (format "^[ \t]*:%s:[ \t]*$" (regexp-quote drawer)))
|
|
|
|
(end (save-excursion (outline-next-heading))))
|
|
|
|
(while (re-search-forward re end t)
|
|
|
|
(org-remove-empty-drawer-at (point))))))))))
|
2011-07-09 09:20:31 -04:00
|
|
|
|
2012-12-18 06:16:20 -05:00
|
|
|
(defun org-clock-timestamps-up (&optional n)
|
|
|
|
"Increase CLOCK timestamps at cursor.
|
|
|
|
Optional argument N tells to change by that many units."
|
|
|
|
(interactive "P")
|
|
|
|
(org-clock-timestamps-change 'up n))
|
2011-07-09 11:38:21 -04:00
|
|
|
|
2012-12-18 06:16:20 -05:00
|
|
|
(defun org-clock-timestamps-down (&optional n)
|
|
|
|
"Increase CLOCK timestamps at cursor.
|
|
|
|
Optional argument N tells to change by that many units."
|
|
|
|
(interactive "P")
|
|
|
|
(org-clock-timestamps-change 'down n))
|
2011-07-09 11:38:21 -04:00
|
|
|
|
2012-12-18 06:16:20 -05:00
|
|
|
(defun org-clock-timestamps-change (updown &optional n)
|
2011-07-09 11:38:59 -04:00
|
|
|
"Change CLOCK timestamps synchronously at cursor.
|
2015-09-21 00:24:12 -04:00
|
|
|
UPDOWN tells whether to change `up' or `down'.
|
2012-12-18 06:16:20 -05:00
|
|
|
Optional argument N tells to change by that many units."
|
2011-07-09 11:38:21 -04:00
|
|
|
(setq org-ts-what nil)
|
2011-07-09 17:54:49 -04:00
|
|
|
(when (org-at-timestamp-p t)
|
|
|
|
(let ((tschange (if (eq updown 'up) 'org-timestamp-up
|
|
|
|
'org-timestamp-down))
|
|
|
|
ts1 begts1 ts2 begts2 updatets1 tdiff)
|
|
|
|
(save-excursion
|
|
|
|
(move-beginning-of-line 1)
|
|
|
|
(re-search-forward org-ts-regexp3 nil t)
|
|
|
|
(setq ts1 (match-string 0) begts1 (match-beginning 0))
|
|
|
|
(when (re-search-forward org-ts-regexp3 nil t)
|
|
|
|
(setq ts2 (match-string 0) begts2 (match-beginning 0))))
|
|
|
|
;; Are we on the second timestamp?
|
|
|
|
(if (<= begts2 (point)) (setq updatets1 t))
|
|
|
|
(if (not ts2)
|
|
|
|
;; fall back on org-timestamp-up if there is only one
|
2012-12-18 06:16:20 -05:00
|
|
|
(funcall tschange n)
|
2011-07-09 17:54:49 -04:00
|
|
|
;; setq this so that (boundp 'org-ts-what is non-nil)
|
2012-12-18 06:16:20 -05:00
|
|
|
(funcall tschange n)
|
2011-07-09 17:54:49 -04:00
|
|
|
(let ((ts (if updatets1 ts2 ts1))
|
|
|
|
(begts (if updatets1 begts1 begts2)))
|
|
|
|
(setq tdiff
|
|
|
|
(subtract-time
|
|
|
|
(org-time-string-to-time org-last-changed-timestamp)
|
|
|
|
(org-time-string-to-time ts)))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char begts)
|
|
|
|
(org-timestamp-change
|
|
|
|
(round (/ (org-float-time tdiff)
|
|
|
|
(cond ((eq org-ts-what 'minute) 60)
|
|
|
|
((eq org-ts-what 'hour) 3600)
|
|
|
|
((eq org-ts-what 'day) (* 24 3600))
|
|
|
|
((eq org-ts-what 'month) (* 24 3600 31))
|
|
|
|
((eq org-ts-what 'year) (* 24 3600 365.2)))))
|
|
|
|
org-ts-what 'updown)))))))
|
2011-07-09 11:38:21 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-04-03 11:58:13 -04:00
|
|
|
(defun org-clock-cancel ()
|
2010-05-16 13:11:16 -04:00
|
|
|
"Cancel the running clock by removing the start timestamp."
|
2008-04-03 11:58:13 -04:00
|
|
|
(interactive)
|
2010-04-25 18:02:49 -04:00
|
|
|
(when (not (org-clocking-p))
|
|
|
|
(setq global-mode-string
|
2012-08-11 13:10:44 -04:00
|
|
|
(delq 'org-mode-line-string global-mode-string))
|
2012-05-05 08:21:13 -04:00
|
|
|
(setq frame-title-format org-frame-title-format-backup)
|
2010-04-25 18:02:49 -04:00
|
|
|
(force-mode-line-update)
|
|
|
|
(error "No active clock"))
|
2013-10-20 08:40:09 -04:00
|
|
|
(save-excursion ; Do not replace this with `with-current-buffer'.
|
2012-05-18 07:16:11 -04:00
|
|
|
(org-no-warnings (set-buffer (org-clocking-buffer)))
|
2008-04-03 11:58:13 -04:00
|
|
|
(goto-char org-clock-marker)
|
2015-04-20 21:55:00 -04:00
|
|
|
(if (org-looking-back (concat "^[ \t]*" org-clock-string ".*")
|
|
|
|
(line-beginning-position))
|
2012-07-12 08:04:54 -04:00
|
|
|
(progn (delete-region (1- (point-at-bol)) (point-at-eol))
|
2013-10-20 08:40:09 -04:00
|
|
|
(org-remove-empty-drawer-at (point)))
|
2012-07-12 08:04:54 -04:00
|
|
|
(message "Clock gone, cancel the timer anyway")
|
|
|
|
(sit-for 2)))
|
2013-04-04 03:40:02 -04:00
|
|
|
(move-marker org-clock-marker nil)
|
|
|
|
(move-marker org-clock-hd-marker nil)
|
2008-04-03 11:58:13 -04:00
|
|
|
(setq global-mode-string
|
|
|
|
(delq 'org-mode-line-string global-mode-string))
|
2012-05-05 08:21:13 -04:00
|
|
|
(setq frame-title-format org-frame-title-format-backup)
|
2008-04-03 11:58:13 -04:00
|
|
|
(force-mode-line-update)
|
2009-06-21 11:26:52 -04:00
|
|
|
(message "Clock canceled")
|
|
|
|
(run-hooks 'org-clock-cancel-hook))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-04-25 02:18:49 -04:00
|
|
|
(defun org-clock-goto (&optional select)
|
2009-04-21 14:25:30 -04:00
|
|
|
"Go to the currently clocked-in entry, or to the most recently clocked one.
|
|
|
|
With prefix arg SELECT, offer recently clocked tasks for selection."
|
2009-06-19 08:03:34 -04:00
|
|
|
(interactive "@P")
|
2009-04-21 14:25:30 -04:00
|
|
|
(let* ((recent nil)
|
|
|
|
(m (cond
|
|
|
|
(select
|
|
|
|
(or (org-clock-select-task "Select task to go to: ")
|
|
|
|
(error "No task selected")))
|
2010-03-09 11:10:15 -05:00
|
|
|
((org-clocking-p) org-clock-marker)
|
2009-04-22 00:41:15 -04:00
|
|
|
((and org-clock-goto-may-find-recent-task
|
|
|
|
(car org-clock-history)
|
2009-04-21 14:25:30 -04:00
|
|
|
(marker-buffer (car org-clock-history)))
|
|
|
|
(setq recent t)
|
|
|
|
(car org-clock-history))
|
|
|
|
(t (error "No active or recent clock task")))))
|
2011-07-18 13:25:10 -04:00
|
|
|
(org-pop-to-buffer-same-window (marker-buffer m))
|
2008-04-29 15:06:53 -04:00
|
|
|
(if (or (< m (point-min)) (> m (point-max))) (widen))
|
2008-04-25 02:18:49 -04:00
|
|
|
(goto-char m)
|
|
|
|
(org-show-entry)
|
2009-07-08 08:29:18 -04:00
|
|
|
(org-back-to-heading t)
|
2008-04-25 02:18:49 -04:00
|
|
|
(org-cycle-hide-drawers 'children)
|
2013-09-10 05:57:05 -04:00
|
|
|
(recenter org-clock-goto-before-context)
|
2010-02-24 07:36:41 -05:00
|
|
|
(org-reveal)
|
2009-04-21 14:25:30 -04:00
|
|
|
(if recent
|
2009-06-21 11:26:52 -04:00
|
|
|
(message "No running clock, this is the most recently clocked task"))
|
|
|
|
(run-hooks 'org-clock-goto-hook)))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2015-11-05 11:47:38 -05:00
|
|
|
(defvar-local org-clock-file-total-minutes nil
|
2008-04-03 11:58:13 -04:00
|
|
|
"Holds the file total time in minutes, after a call to `org-clock-sum'.")
|
|
|
|
|
2012-08-05 05:12:04 -04:00
|
|
|
(defun org-clock-sum-today (&optional headline-filter)
|
|
|
|
"Sum the times for each subtree for today."
|
|
|
|
(let ((range (org-clock-special-range 'today)))
|
2014-04-20 09:09:32 -04:00
|
|
|
(org-clock-sum (car range) (cadr range)
|
|
|
|
headline-filter :org-clock-minutes-today)))
|
|
|
|
|
2014-07-28 11:43:15 -04:00
|
|
|
(defun org-clock-sum-custom (&optional headline-filter range propname)
|
2014-04-20 09:09:32 -04:00
|
|
|
"Sum the times for each subtree for today."
|
2014-07-28 11:43:15 -04:00
|
|
|
(let ((r (or (and (symbolp range) (org-clock-special-range range))
|
|
|
|
(org-clock-special-range
|
|
|
|
(intern (completing-read
|
|
|
|
"Range: "
|
|
|
|
'("today" "yesterday" "thisweek" "lastweek"
|
|
|
|
"thismonth" "lastmonth" "thisyear" "lastyear"
|
|
|
|
"interactive")
|
|
|
|
nil t))))))
|
|
|
|
(org-clock-sum (car r) (cadr r)
|
|
|
|
headline-filter (or propname :org-clock-minutes-custom))))
|
2012-08-05 05:12:04 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2012-08-05 05:12:04 -04:00
|
|
|
(defun org-clock-sum (&optional tstart tend headline-filter propname)
|
2008-04-03 11:58:13 -04:00
|
|
|
"Sum the times for each subtree.
|
2009-06-02 07:12:43 -04:00
|
|
|
Puts the resulting times in minutes as a text property on each headline.
|
2012-08-05 05:12:04 -04:00
|
|
|
TSTART and TEND can mark a time range to be considered.
|
|
|
|
HEADLINE-FILTER is a zero-arg function that, if specified, is called for
|
|
|
|
each headline in the time range with point at the headline. Headlines for
|
|
|
|
which HEADLINE-FILTER returns nil are excluded from the clock summation.
|
|
|
|
PROPNAME lets you set a custom text property instead of :org-clock-minutes."
|
2013-02-25 05:44:27 -05:00
|
|
|
(org-with-silent-modifications
|
|
|
|
(let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
|
|
|
|
org-clock-string
|
|
|
|
"[ \t]*\\(?:\\(\\[.*?\\]\\)-+\\(\\[.*?\\]\\)\\|=>[ \t]+\\([0-9]+\\):\\([0-9]+\\)\\)"))
|
|
|
|
(lmax 30)
|
|
|
|
(ltimes (make-vector lmax 0))
|
|
|
|
(t1 0)
|
|
|
|
(level 0)
|
|
|
|
ts te dt
|
|
|
|
time)
|
|
|
|
(if (stringp tstart) (setq tstart (org-time-string-to-seconds tstart)))
|
|
|
|
(if (stringp tend) (setq tend (org-time-string-to-seconds tend)))
|
|
|
|
(if (consp tstart) (setq tstart (org-float-time tstart)))
|
|
|
|
(if (consp tend) (setq tend (org-float-time tend)))
|
|
|
|
(remove-text-properties (point-min) (point-max)
|
|
|
|
`(,(or propname :org-clock-minutes) t
|
|
|
|
:org-clock-force-headline-inclusion t))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-max))
|
|
|
|
(while (re-search-backward re nil t)
|
|
|
|
(cond
|
|
|
|
((match-end 2)
|
|
|
|
;; Two time stamps
|
|
|
|
(setq ts (match-string 2)
|
|
|
|
te (match-string 3)
|
|
|
|
ts (org-float-time
|
|
|
|
(apply 'encode-time (org-parse-time-string ts)))
|
|
|
|
te (org-float-time
|
|
|
|
(apply 'encode-time (org-parse-time-string te)))
|
|
|
|
ts (if tstart (max ts tstart) ts)
|
|
|
|
te (if tend (min te tend) te)
|
|
|
|
dt (- te ts)
|
|
|
|
t1 (if (> dt 0) (+ t1 (floor (/ dt 60))) t1)))
|
|
|
|
((match-end 4)
|
|
|
|
;; A naked time
|
|
|
|
(setq t1 (+ t1 (string-to-number (match-string 5))
|
|
|
|
(* 60 (string-to-number (match-string 4))))))
|
|
|
|
(t ;; A headline
|
|
|
|
;; Add the currently clocking item time to the total
|
|
|
|
(when (and org-clock-report-include-clocking-task
|
|
|
|
(equal (org-clocking-buffer) (current-buffer))
|
|
|
|
(equal (marker-position org-clock-hd-marker) (point))
|
|
|
|
tstart
|
|
|
|
tend
|
|
|
|
(>= (org-float-time org-clock-start-time) tstart)
|
|
|
|
(<= (org-float-time org-clock-start-time) tend))
|
|
|
|
(let ((time (floor (- (org-float-time)
|
|
|
|
(org-float-time org-clock-start-time)) 60)))
|
|
|
|
(setq t1 (+ t1 time))))
|
|
|
|
(let* ((headline-forced
|
|
|
|
(get-text-property (point)
|
|
|
|
:org-clock-force-headline-inclusion))
|
|
|
|
(headline-included
|
|
|
|
(or (null headline-filter)
|
|
|
|
(save-excursion
|
|
|
|
(save-match-data (funcall headline-filter))))))
|
|
|
|
(setq level (- (match-end 1) (match-beginning 1)))
|
2014-02-24 12:27:28 -05:00
|
|
|
(when (>= level lmax)
|
|
|
|
(setq ltimes (vconcat ltimes (make-vector lmax 0)) lmax (* 2 lmax)))
|
2013-02-25 05:44:27 -05:00
|
|
|
(when (or (> t1 0) (> (aref ltimes level) 0))
|
|
|
|
(when (or headline-included headline-forced)
|
|
|
|
(if headline-included
|
|
|
|
(loop for l from 0 to level do
|
|
|
|
(aset ltimes l (+ (aref ltimes l) t1))))
|
|
|
|
(setq time (aref ltimes level))
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
(put-text-property (point) (point-at-eol)
|
|
|
|
(or propname :org-clock-minutes) time)
|
|
|
|
(if headline-filter
|
|
|
|
(save-excursion
|
|
|
|
(save-match-data
|
|
|
|
(while
|
|
|
|
(> (funcall outline-level) 1)
|
|
|
|
(outline-up-heading 1 t)
|
|
|
|
(put-text-property
|
|
|
|
(point) (point-at-eol)
|
|
|
|
:org-clock-force-headline-inclusion t))))))
|
|
|
|
(setq t1 0)
|
|
|
|
(loop for l from level to (1- lmax) do
|
|
|
|
(aset ltimes l 0)))))))
|
|
|
|
(setq org-clock-file-total-minutes (aref ltimes 0))))))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2009-06-02 08:49:38 -04:00
|
|
|
(defun org-clock-sum-current-item (&optional tstart)
|
2010-07-15 16:26:51 -04:00
|
|
|
"Return time, clocked on current item in total."
|
2009-06-02 08:49:38 -04:00
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(org-narrow-to-subtree)
|
|
|
|
(org-clock-sum tstart)
|
|
|
|
org-clock-file-total-minutes)))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2014-05-27 03:45:54 -04:00
|
|
|
(defun org-clock-display (&optional arg)
|
2008-04-03 11:58:13 -04:00
|
|
|
"Show subtree times in the entire buffer.
|
2014-04-20 09:09:32 -04:00
|
|
|
|
|
|
|
With one universal prefix argument, show the total time for
|
|
|
|
today. With two universal prefix arguments, show the total time
|
|
|
|
for a custom range, entered at the prompt. With three universal
|
|
|
|
prefix arguments, show the total time in the echo area.
|
2011-02-26 10:29:59 -05:00
|
|
|
|
|
|
|
Use \\[org-clock-remove-overlays] to remove the subtree times."
|
2014-04-20 09:09:32 -04:00
|
|
|
(interactive "P")
|
2009-01-08 05:19:37 -05:00
|
|
|
(org-clock-remove-overlays)
|
2014-04-20 09:09:32 -04:00
|
|
|
(let* ((todayp (equal arg '(4)))
|
2014-07-28 11:43:15 -04:00
|
|
|
(customp (member arg '((16) today yesterday
|
2015-02-20 05:35:16 -05:00
|
|
|
thisweek lastweek thismonth
|
|
|
|
lastmonth thisyear lastyear
|
|
|
|
untilnow interactive)))
|
2014-07-28 11:43:15 -04:00
|
|
|
(prop (cond ((not arg) :org-clock-minutes-default)
|
|
|
|
(todayp :org-clock-minutes-today)
|
2014-04-20 09:09:32 -04:00
|
|
|
(customp :org-clock-minutes-custom)
|
|
|
|
(t :org-clock-minutes)))
|
|
|
|
time h m p)
|
2014-07-28 11:43:15 -04:00
|
|
|
(cond ((not arg) (org-clock-sum-custom
|
|
|
|
nil org-clock-display-default-range prop))
|
|
|
|
(todayp (org-clock-sum-today))
|
|
|
|
(customp (org-clock-sum-custom nil arg))
|
2014-04-20 09:09:32 -04:00
|
|
|
(t (org-clock-sum)))
|
|
|
|
(unless (eq arg '(64))
|
2008-04-03 11:58:13 -04:00
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(while (or (and (equal (setq p (point)) (point-min))
|
2014-04-20 09:09:32 -04:00
|
|
|
(get-text-property p prop))
|
2008-04-03 11:58:13 -04:00
|
|
|
(setq p (next-single-property-change
|
2014-04-20 09:09:32 -04:00
|
|
|
(point) prop)))
|
2008-04-03 11:58:13 -04:00
|
|
|
(goto-char p)
|
2014-04-20 09:09:32 -04:00
|
|
|
(when (setq time (get-text-property p prop))
|
2014-04-17 04:19:58 -04:00
|
|
|
(org-clock-put-overlay time)))
|
2008-04-03 11:58:13 -04:00
|
|
|
(setq h (/ org-clock-file-total-minutes 60)
|
|
|
|
m (- org-clock-file-total-minutes (* 60 h)))
|
|
|
|
;; Arrange to remove the overlays upon next change.
|
|
|
|
(when org-remove-highlights-with-change
|
2009-01-08 05:19:37 -05:00
|
|
|
(org-add-hook 'before-change-functions 'org-clock-remove-overlays
|
2008-04-03 11:58:13 -04:00
|
|
|
nil 'local))))
|
2014-04-20 09:09:32 -04:00
|
|
|
(message (concat (format "Total file time%s: "
|
|
|
|
(cond (todayp " for today")
|
|
|
|
(customp " (custom)")
|
|
|
|
(t "")))
|
2014-05-27 03:45:54 -04:00
|
|
|
(org-minutes-to-clocksum-string
|
|
|
|
org-clock-file-total-minutes)
|
|
|
|
" (%d hours and %d minutes)")
|
|
|
|
h m)))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2015-11-05 11:47:38 -05:00
|
|
|
(defvar-local org-clock-overlays nil)
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2014-04-17 04:19:58 -04:00
|
|
|
(defun org-clock-put-overlay (time)
|
2008-04-03 11:58:13 -04:00
|
|
|
"Put an overlays on the current line, displaying TIME.
|
|
|
|
This creates a new overlay and stores it in `org-clock-overlays', so that it
|
|
|
|
will be easy to remove."
|
2014-04-18 10:41:29 -04:00
|
|
|
(let (ov tx)
|
2014-04-18 15:30:12 -04:00
|
|
|
(beginning-of-line)
|
|
|
|
(when (looking-at org-complex-heading-regexp)
|
|
|
|
(goto-char (match-beginning 4)))
|
|
|
|
(setq ov (make-overlay (point) (point-at-eol))
|
|
|
|
tx (concat (buffer-substring-no-properties (point) (match-end 4))
|
2014-04-18 15:33:52 -04:00
|
|
|
(org-add-props
|
|
|
|
(make-string
|
|
|
|
(max 0 (- (- 60 (current-column))
|
|
|
|
(- (match-end 4) (match-beginning 4))
|
|
|
|
(length (org-get-at-bol 'line-prefix)))) ?·)
|
|
|
|
'(face shadow))
|
2014-04-17 04:19:58 -04:00
|
|
|
(org-add-props
|
2014-04-17 07:10:09 -04:00
|
|
|
(format " %9s " (org-minutes-to-clocksum-string time))
|
2014-04-18 15:33:52 -04:00
|
|
|
'(face org-clock-overlay))
|
2008-04-03 11:58:13 -04:00
|
|
|
""))
|
|
|
|
(if (not (featurep 'xemacs))
|
2010-04-18 10:37:42 -04:00
|
|
|
(overlay-put ov 'display tx)
|
|
|
|
(overlay-put ov 'invisible t)
|
|
|
|
(overlay-put ov 'end-glyph (make-glyph tx)))
|
2008-04-03 11:58:13 -04:00
|
|
|
(push ov org-clock-overlays)))
|
|
|
|
|
2013-11-15 00:53:59 -05:00
|
|
|
;;;###autoload
|
2009-01-08 05:19:37 -05:00
|
|
|
(defun org-clock-remove-overlays (&optional beg end noremove)
|
2008-04-03 11:58:13 -04:00
|
|
|
"Remove the occur highlights from the buffer.
|
|
|
|
BEG and END are ignored. If NOREMOVE is nil, remove this function
|
|
|
|
from the `before-change-functions' in the current buffer."
|
|
|
|
(interactive)
|
|
|
|
(unless org-inhibit-highlight-removal
|
2010-04-18 10:37:42 -04:00
|
|
|
(mapc 'delete-overlay org-clock-overlays)
|
2008-04-03 11:58:13 -04:00
|
|
|
(setq org-clock-overlays nil)
|
|
|
|
(unless noremove
|
|
|
|
(remove-hook 'before-change-functions
|
2009-01-08 05:19:37 -05:00
|
|
|
'org-clock-remove-overlays 'local))))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2012-04-02 02:07:52 -04:00
|
|
|
(defvar org-state) ;; dynamically scoped into this function
|
2008-04-03 11:58:13 -04:00
|
|
|
(defun org-clock-out-if-current ()
|
|
|
|
"Clock out if the current entry contains the running clock.
|
|
|
|
This is used to stop the clock after a TODO entry is marked DONE,
|
|
|
|
and is only done if the variable `org-clock-out-when-done' is not nil."
|
2011-11-19 21:44:07 -05:00
|
|
|
(when (and (org-clocking-p)
|
|
|
|
org-clock-out-when-done
|
2011-12-11 12:25:58 -05:00
|
|
|
(marker-buffer org-clock-marker)
|
2010-01-15 12:16:07 -05:00
|
|
|
(or (and (eq t org-clock-out-when-done)
|
2012-04-02 02:07:52 -04:00
|
|
|
(member org-state org-done-keywords))
|
2010-01-15 12:16:07 -05:00
|
|
|
(and (listp org-clock-out-when-done)
|
2012-04-02 02:07:52 -04:00
|
|
|
(member org-state org-clock-out-when-done)))
|
2010-03-09 11:10:15 -05:00
|
|
|
(equal (or (buffer-base-buffer (org-clocking-buffer))
|
|
|
|
(org-clocking-buffer))
|
2009-03-23 16:02:23 -04:00
|
|
|
(or (buffer-base-buffer (current-buffer))
|
|
|
|
(current-buffer)))
|
2008-04-03 11:58:13 -04:00
|
|
|
(< (point) org-clock-marker)
|
|
|
|
(> (save-excursion (outline-next-heading) (point))
|
|
|
|
org-clock-marker))
|
|
|
|
;; Clock out, but don't accept a logging message for this.
|
2010-01-15 12:16:07 -05:00
|
|
|
(let ((org-log-note-clock-out nil)
|
|
|
|
(org-clock-out-switch-to-state nil))
|
2008-04-03 11:58:13 -04:00
|
|
|
(org-clock-out))))
|
|
|
|
|
|
|
|
(add-hook 'org-after-todo-state-change-hook
|
|
|
|
'org-clock-out-if-current)
|
|
|
|
|
2008-04-04 17:44:48 -04:00
|
|
|
;;;###autoload
|
2012-10-02 04:03:15 -04:00
|
|
|
(defun org-clock-get-clocktable (&rest props)
|
2008-04-04 17:44:48 -04:00
|
|
|
"Get a formatted clocktable with parameters according to PROPS.
|
|
|
|
The table is created in a temporary buffer, fully formatted and
|
|
|
|
fontified, and then returned."
|
|
|
|
;; Set the defaults
|
|
|
|
(setq props (plist-put props :name "clocktable"))
|
|
|
|
(unless (plist-member props :maxlevel)
|
|
|
|
(setq props (plist-put props :maxlevel 2)))
|
|
|
|
(unless (plist-member props :scope)
|
|
|
|
(setq props (plist-put props :scope 'agenda)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(org-mode)
|
|
|
|
(org-create-dblock props)
|
|
|
|
(org-update-dblock)
|
2014-05-29 16:08:43 -04:00
|
|
|
(font-lock-ensure)
|
2008-04-04 17:44:48 -04:00
|
|
|
(forward-line 2)
|
|
|
|
(buffer-substring (point) (progn
|
2010-11-20 05:43:45 -05:00
|
|
|
(re-search-forward "^[ \t]*#\\+END" nil t)
|
2008-04-04 17:44:48 -04:00
|
|
|
(point-at-bol)))))
|
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-04-03 11:58:13 -04:00
|
|
|
(defun org-clock-report (&optional arg)
|
|
|
|
"Create a table containing a report about clocked time.
|
|
|
|
If the cursor is inside an existing clocktable block, then the table
|
2011-03-17 11:52:23 -04:00
|
|
|
will be updated. If not, a new clocktable will be inserted. The scope
|
2011-07-09 12:12:18 -04:00
|
|
|
of the new clock will be subtree when called from within a subtree, and
|
2011-03-17 11:52:23 -04:00
|
|
|
file elsewhere.
|
|
|
|
|
2008-04-03 11:58:13 -04:00
|
|
|
When called with a prefix argument, move to the first clock table in the
|
|
|
|
buffer and update it."
|
|
|
|
(interactive "P")
|
2009-01-08 05:19:37 -05:00
|
|
|
(org-clock-remove-overlays)
|
2008-04-03 11:58:13 -04:00
|
|
|
(when arg
|
|
|
|
(org-find-dblock "clocktable")
|
|
|
|
(org-show-entry))
|
|
|
|
(if (org-in-clocktable-p)
|
|
|
|
(goto-char (org-in-clocktable-p))
|
2011-07-09 12:12:18 -04:00
|
|
|
(let ((props (if (ignore-errors
|
2011-03-17 11:52:23 -04:00
|
|
|
(save-excursion (org-back-to-heading)))
|
|
|
|
(list :name "clocktable" :scope 'subtree)
|
|
|
|
(list :name "clocktable"))))
|
2011-07-09 12:12:18 -04:00
|
|
|
(org-create-dblock
|
2011-03-17 11:52:23 -04:00
|
|
|
(org-combine-plists org-clock-clocktable-default-properties props))))
|
2008-04-03 11:58:13 -04:00
|
|
|
(org-update-dblock))
|
|
|
|
|
2010-11-29 05:27:47 -05:00
|
|
|
(defun org-day-of-week (day month year)
|
|
|
|
"Returns the day of the week as an integer."
|
|
|
|
(nth 6
|
|
|
|
(decode-time
|
|
|
|
(date-to-time
|
|
|
|
(format "%d-%02d-%02dT00:00:00" year month day)))))
|
|
|
|
|
|
|
|
(defun org-quarter-to-date (quarter year)
|
|
|
|
"Get the date (week day year) of the first day of a given quarter."
|
2010-12-03 04:20:41 -05:00
|
|
|
(let (startday)
|
2010-11-29 05:27:47 -05:00
|
|
|
(cond
|
2010-12-03 04:20:41 -05:00
|
|
|
((= quarter 1)
|
|
|
|
(setq startday (org-day-of-week 1 1 year))
|
|
|
|
(cond
|
|
|
|
((= startday 0)
|
|
|
|
(list 52 7 (- year 1)))
|
|
|
|
((= startday 6)
|
|
|
|
(list 52 6 (- year 1)))
|
|
|
|
((<= startday 4)
|
|
|
|
(list 1 startday year))
|
|
|
|
((> startday 4)
|
|
|
|
(list 53 startday (- year 1)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
((= quarter 2)
|
|
|
|
(setq startday (org-day-of-week 1 4 year))
|
|
|
|
(cond
|
|
|
|
((= startday 0)
|
|
|
|
(list 13 startday year))
|
|
|
|
((< startday 4)
|
|
|
|
(list 14 startday year))
|
|
|
|
((>= startday 4)
|
|
|
|
(list 13 startday year))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
((= quarter 3)
|
|
|
|
(setq startday (org-day-of-week 1 7 year))
|
|
|
|
(cond
|
|
|
|
((= startday 0)
|
|
|
|
(list 26 startday year))
|
|
|
|
((< startday 4)
|
|
|
|
(list 27 startday year))
|
|
|
|
((>= startday 4)
|
|
|
|
(list 26 startday year))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
((= quarter 4)
|
|
|
|
(setq startday (org-day-of-week 1 10 year))
|
|
|
|
(cond
|
|
|
|
((= startday 0)
|
|
|
|
(list 39 startday year))
|
|
|
|
((<= startday 4)
|
|
|
|
(list 40 startday year))
|
|
|
|
((> startday 4)
|
|
|
|
(list 39 startday year)))))))
|
2010-11-29 05:27:47 -05:00
|
|
|
|
2013-03-15 06:17:12 -04:00
|
|
|
(defun org-clock-special-range (key &optional time as-strings wstart mstart)
|
2008-04-03 11:58:13 -04:00
|
|
|
"Return two times bordering a special time range.
|
2015-02-20 05:35:16 -05:00
|
|
|
|
|
|
|
KEY is a symbol specifying the range and can be one of `today',
|
|
|
|
`yesterday', `thisweek', `lastweek', `thismonth', `lastmonth',
|
|
|
|
`thisyear', `lastyear' or `untilnow'. If set to `interactive',
|
|
|
|
user is prompted for range boundaries. It can be a string or an
|
|
|
|
integer.
|
|
|
|
|
|
|
|
By default, a week starts Monday 0:00 and ends Sunday 24:00. The
|
|
|
|
range is determined relative to TIME, which defaults to current
|
|
|
|
time.
|
|
|
|
|
|
|
|
The return value is a list containing two internal times, one for
|
|
|
|
the beginning of the range and one for its end, like the ones
|
|
|
|
returned by `current time' or `encode-time' and a string used to
|
|
|
|
display information. If AS-STRINGS is non-nil, the returned
|
|
|
|
times will be formatted strings.
|
|
|
|
|
|
|
|
If WSTART is non-nil, use this number to specify the starting day
|
|
|
|
of a week (monday is 1). If MSTART is non-nil, use this number
|
|
|
|
to specify the starting day of a month (1 is the first day of the
|
|
|
|
month). If you can combine both, the month starting day will
|
|
|
|
have priority."
|
2014-10-28 21:42:51 -04:00
|
|
|
(let* ((tm (decode-time time))
|
2015-02-20 05:35:16 -05:00
|
|
|
(m (nth 1 tm))
|
|
|
|
(h (nth 2 tm))
|
|
|
|
(d (nth 3 tm))
|
|
|
|
(month (nth 4 tm))
|
|
|
|
(y (nth 5 tm))
|
2008-04-03 11:58:13 -04:00
|
|
|
(dow (nth 6 tm))
|
2015-02-20 05:35:16 -05:00
|
|
|
(skey (format "%s" key))
|
2008-04-03 11:58:13 -04:00
|
|
|
(shift 0)
|
2015-02-20 05:35:16 -05:00
|
|
|
(q (cond ((>= month 10) 4)
|
|
|
|
((>= month 7) 3)
|
|
|
|
((>= month 4) 2)
|
|
|
|
(t 1)))
|
|
|
|
m1 h1 d1 month1 y1 shiftedy shiftedm shiftedq)
|
2008-04-03 11:58:13 -04:00
|
|
|
(cond
|
2015-02-20 05:35:16 -05:00
|
|
|
((string-match "\\`[0-9]+\\'" skey)
|
|
|
|
(setq y (string-to-number skey) month 1 d 1 key 'year))
|
|
|
|
((string-match "\\`\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)\\'" skey)
|
2008-04-03 11:58:13 -04:00
|
|
|
(setq y (string-to-number (match-string 1 skey))
|
|
|
|
month (string-to-number (match-string 2 skey))
|
2015-02-20 05:35:16 -05:00
|
|
|
d 1
|
|
|
|
key 'month))
|
|
|
|
((string-match "\\`\\([0-9]+\\)-[wW]\\([0-9]\\{1,2\\}\\)\\'" skey)
|
2008-04-03 11:58:13 -04:00
|
|
|
(require 'cal-iso)
|
2015-02-20 05:35:16 -05:00
|
|
|
(let ((date (calendar-gregorian-from-absolute
|
|
|
|
(calendar-iso-to-absolute
|
|
|
|
(list (string-to-number (match-string 2 skey))
|
|
|
|
1
|
|
|
|
(string-to-number (match-string 1 skey)))))))
|
|
|
|
(setq d (nth 1 date)
|
|
|
|
month (car date)
|
|
|
|
y (nth 2 date)
|
|
|
|
dow 1
|
|
|
|
key 'week)))
|
|
|
|
((string-match "\\`\\([0-9]+\\)-[qQ]\\([1-4]\\)\\'" skey)
|
2012-08-11 13:10:44 -04:00
|
|
|
(require 'cal-iso)
|
2015-10-14 18:03:36 -04:00
|
|
|
(setq q (string-to-number (match-string 2 skey)))
|
2015-02-20 05:35:16 -05:00
|
|
|
(let ((date (calendar-gregorian-from-absolute
|
|
|
|
(calendar-iso-to-absolute
|
|
|
|
(org-quarter-to-date
|
2015-10-14 18:03:36 -04:00
|
|
|
q (string-to-number (match-string 1 skey)))))))
|
2015-02-20 05:35:16 -05:00
|
|
|
(setq d (nth 1 date)
|
|
|
|
month (car date)
|
|
|
|
y (nth 2 date)
|
|
|
|
dow 1
|
|
|
|
key 'quarter)))
|
|
|
|
((string-match
|
|
|
|
"\\`\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\\{1,2\\}\\)\\'"
|
|
|
|
skey)
|
2008-04-03 11:58:13 -04:00
|
|
|
(setq y (string-to-number (match-string 1 skey))
|
|
|
|
month (string-to-number (match-string 2 skey))
|
|
|
|
d (string-to-number (match-string 3 skey))
|
|
|
|
key 'day))
|
2015-02-20 05:35:16 -05:00
|
|
|
((string-match "\\([-+][0-9]+\\)\\'" skey)
|
2008-04-03 11:58:13 -04:00
|
|
|
(setq shift (string-to-number (match-string 1 skey))
|
2015-02-20 05:35:16 -05:00
|
|
|
key (intern (substring skey 0 (match-beginning 1))))
|
|
|
|
(when (and (memq key '(quarter thisq)) (> shift 0))
|
|
|
|
(error "Looking forward with quarters isn't implemented"))))
|
2008-06-22 23:46:33 -04:00
|
|
|
(when (= shift 0)
|
2015-02-20 05:35:16 -05:00
|
|
|
(case key
|
|
|
|
(yesterday (setq key 'today shift -1))
|
|
|
|
(lastweek (setq key 'week shift -1))
|
|
|
|
(lastmonth (setq key 'month shift -1))
|
|
|
|
(lastyear (setq key 'year shift -1))
|
|
|
|
(lastq (setq key 'quarter shift -1))))
|
|
|
|
;; Prepare start and end times depending on KEY's type.
|
|
|
|
(case key
|
|
|
|
((day today) (setq m 0 h 0 h1 24 d (+ d shift)))
|
|
|
|
((week thisweek)
|
|
|
|
(let* ((ws (or wstart 1))
|
|
|
|
(diff (+ (* -7 shift) (if (= dow 0) (- 7 ws) (- dow ws)))))
|
|
|
|
(setq m 0 h 0 d (- d diff) d1 (+ 7 d))))
|
|
|
|
((month thismonth)
|
|
|
|
(setq h 0 m 0 d (or mstart 1) month (+ month shift) month1 (1+ month)))
|
|
|
|
((quarter thisq)
|
|
|
|
;; Compute if this shift remains in this year. If not, compute
|
|
|
|
;; how many years and quarters we have to shift (via floor*) and
|
|
|
|
;; compute the shifted years, months and quarters.
|
|
|
|
(cond
|
|
|
|
((< (+ (- q 1) shift) 0) ; Shift not in this year.
|
|
|
|
(let* ((interval (* -1 (+ (- q 1) shift)))
|
|
|
|
;; Set tmp to ((years to shift) (quarters to shift)).
|
|
|
|
(tmp (org-floor* interval 4)))
|
|
|
|
;; Due to the use of floor, 0 quarters actually means 4.
|
|
|
|
(if (= 0 (nth 1 tmp))
|
|
|
|
(setq shiftedy (- y (nth 0 tmp))
|
|
|
|
shiftedm 1
|
|
|
|
shiftedq 1)
|
|
|
|
(setq shiftedy (- y (+ 1 (nth 0 tmp)))
|
|
|
|
shiftedm (- 13 (* 3 (nth 1 tmp)))
|
|
|
|
shiftedq (- 5 (nth 1 tmp)))))
|
|
|
|
(setq m 0 h 0 d 1 month shiftedm month1 (+ 3 shiftedm) y shiftedy))
|
|
|
|
((> (+ q shift) 0) ; Shift is within this year.
|
|
|
|
(setq shiftedq (+ q shift))
|
|
|
|
(setq shiftedy y)
|
|
|
|
(let ((qshift (* 3 (1- (+ q shift)))))
|
|
|
|
(setq m 0 h 0 d 1 month (+ 1 qshift) month1 (+ 4 qshift))))))
|
|
|
|
((year thisyear)
|
|
|
|
(setq m 0 h 0 d 1 month 1 y (+ y shift) y1 (1+ y)))
|
|
|
|
((interactive untilnow)) ; Special cases, ignore them.
|
|
|
|
(t (user-error "No such time block %s" key)))
|
|
|
|
;; Format start and end times according to AS-STRINGS.
|
|
|
|
(let* ((start (case key
|
|
|
|
(interactive (org-read-date nil t nil "Range start? "))
|
|
|
|
(untilnow org-clock--oldest-date)
|
|
|
|
(t (encode-time 0 m h d month y))))
|
|
|
|
(end (case key
|
|
|
|
(interactive (org-read-date nil t nil "Range end? "))
|
|
|
|
(untilnow (current-time))
|
|
|
|
(t (encode-time 0
|
|
|
|
(or m1 m)
|
|
|
|
(or h1 h)
|
|
|
|
(or d1 d)
|
|
|
|
(or month1 month)
|
|
|
|
(or y1 y)))))
|
|
|
|
(text
|
|
|
|
(case key
|
|
|
|
((day today) (format-time-string "%A, %B %d, %Y" start))
|
|
|
|
((week thisweek) (format-time-string "week %G-W%V" start))
|
|
|
|
((month thismonth) (format-time-string "%B %Y" start))
|
|
|
|
((year thisyear) (format-time-string "the year %Y" start))
|
|
|
|
((quarter thisq)
|
|
|
|
(concat (org-count-quarter shiftedq)
|
|
|
|
" quarter of " (number-to-string shiftedy)))
|
|
|
|
(interactive "(Range interactively set)")
|
|
|
|
(untilnow "now"))))
|
|
|
|
(if (not as-strings) (list start end text)
|
|
|
|
(let ((f (cdr org-time-stamp-formats)))
|
|
|
|
(list (format-time-string f start)
|
|
|
|
(format-time-string f end)
|
|
|
|
text))))))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
2010-11-29 05:27:47 -05:00
|
|
|
(defun org-count-quarter (n)
|
|
|
|
(cond
|
|
|
|
((= n 1) "1st")
|
|
|
|
((= n 2) "2nd")
|
|
|
|
((= n 3) "3rd")
|
|
|
|
((= n 4) "4th")))
|
|
|
|
|
2013-11-15 00:53:59 -05:00
|
|
|
;;;###autoload
|
2008-04-03 11:58:13 -04:00
|
|
|
(defun org-clocktable-shift (dir n)
|
|
|
|
"Try to shift the :block date of the clocktable at point.
|
|
|
|
Point must be in the #+BEGIN: line of a clocktable, or this function
|
|
|
|
will throw an error.
|
|
|
|
DIR is a direction, a symbol `left', `right', `up', or `down'.
|
|
|
|
Both `left' and `down' shift the block toward the past, `up' and `right'
|
|
|
|
push it toward the future.
|
|
|
|
N is the number of shift steps to take. The size of the step depends on
|
|
|
|
the currently selected interval size."
|
|
|
|
(setq n (prefix-numeric-value n))
|
|
|
|
(and (memq dir '(left down)) (setq n (- n)))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-at-bol))
|
2010-11-20 05:43:45 -05:00
|
|
|
(if (not (looking-at "^[ \t]*#\\+BEGIN:[ \t]+clocktable\\>.*?:block[ \t]+\\(\\S-+\\)"))
|
2008-04-10 08:50:39 -04:00
|
|
|
(error "Line needs a :block definition before this command works")
|
2008-04-03 11:58:13 -04:00
|
|
|
(let* ((b (match-beginning 1)) (e (match-end 1))
|
|
|
|
(s (match-string 1))
|
|
|
|
block shift ins y mw d date wp m)
|
2008-06-22 23:46:33 -04:00
|
|
|
(cond
|
|
|
|
((equal s "yesterday") (setq s "today-1"))
|
|
|
|
((equal s "lastweek") (setq s "thisweek-1"))
|
|
|
|
((equal s "lastmonth") (setq s "thismonth-1"))
|
2010-11-29 05:27:47 -05:00
|
|
|
((equal s "lastyear") (setq s "thisyear-1"))
|
|
|
|
((equal s "lastq") (setq s "thisq-1")))
|
|
|
|
|
2012-08-11 13:10:44 -04:00
|
|
|
(cond
|
|
|
|
((string-match "^\\(today\\|thisweek\\|thismonth\\|thisyear\\|thisq\\)\\([-+][0-9]+\\)?$" s)
|
|
|
|
(setq block (match-string 1 s)
|
|
|
|
shift (if (match-end 2)
|
|
|
|
(string-to-number (match-string 2 s))
|
|
|
|
0))
|
|
|
|
(setq shift (+ shift n))
|
|
|
|
(setq ins (if (= shift 0) block (format "%s%+d" block shift))))
|
|
|
|
((string-match "\\([0-9]+\\)\\(-\\([wWqQ]?\\)\\([0-9]\\{1,2\\}\\)\\(-\\([0-9]\\{1,2\\}\\)\\)?\\)?" s)
|
|
|
|
;; 1 1 2 3 3 4 4 5 6 6 5 2
|
|
|
|
(setq y (string-to-number (match-string 1 s))
|
|
|
|
wp (and (match-end 3) (match-string 3 s))
|
|
|
|
mw (and (match-end 4) (string-to-number (match-string 4 s)))
|
|
|
|
d (and (match-end 6) (string-to-number (match-string 6 s))))
|
|
|
|
(cond
|
|
|
|
(d (setq ins (format-time-string
|
|
|
|
"%Y-%m-%d"
|
|
|
|
(encode-time 0 0 0 (+ d n) m y))))
|
|
|
|
((and wp (string-match "w\\|W" wp) mw (> (length wp) 0))
|
|
|
|
(require 'cal-iso)
|
|
|
|
(setq date (calendar-gregorian-from-absolute
|
2015-01-12 06:35:10 -05:00
|
|
|
(calendar-iso-to-absolute (list (+ mw n) 1 y))))
|
2012-08-11 13:10:44 -04:00
|
|
|
(setq ins (format-time-string
|
|
|
|
"%G-W%V"
|
|
|
|
(encode-time 0 0 0 (nth 1 date) (car date) (nth 2 date)))))
|
|
|
|
((and wp (string-match "q\\|Q" wp) mw (> (length wp) 0))
|
|
|
|
(require 'cal-iso)
|
|
|
|
; if the 4th + 1 quarter is requested we flip to the 1st quarter of the next year
|
|
|
|
(if (> (+ mw n) 4)
|
|
|
|
(setq mw 0
|
|
|
|
y (+ 1 y))
|
|
|
|
())
|
|
|
|
; if the 1st - 1 quarter is requested we flip to the 4th quarter of the previous year
|
|
|
|
(if (= (+ mw n) 0)
|
|
|
|
(setq mw 5
|
|
|
|
y (- y 1))
|
|
|
|
())
|
|
|
|
(setq date (calendar-gregorian-from-absolute
|
2015-01-12 06:35:10 -05:00
|
|
|
(calendar-iso-to-absolute (org-quarter-to-date (+ mw n) y))))
|
2012-08-11 13:10:44 -04:00
|
|
|
(setq ins (format-time-string
|
|
|
|
(concat (number-to-string y) "-Q" (number-to-string (+ mw n)))
|
|
|
|
(encode-time 0 0 0 (nth 1 date) (car date) (nth 2 date)))))
|
|
|
|
(mw
|
|
|
|
(setq ins (format-time-string
|
|
|
|
"%Y-%m"
|
|
|
|
(encode-time 0 0 0 1 (+ mw n) y))))
|
|
|
|
(y
|
|
|
|
(setq ins (number-to-string (+ y n))))))
|
|
|
|
(t (error "Cannot shift clocktable block")))
|
|
|
|
(when ins
|
|
|
|
(goto-char b)
|
|
|
|
(insert ins)
|
|
|
|
(delete-region (point) (+ (point) (- e b)))
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(org-update-dblock)
|
|
|
|
t)))))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
;;;###autoload
|
2008-04-03 11:58:13 -04:00
|
|
|
(defun org-dblock-write:clocktable (params)
|
|
|
|
"Write the standard clocktable."
|
2010-11-01 08:30:44 -04:00
|
|
|
(setq params (org-combine-plists org-clocktable-defaults params))
|
2008-04-03 11:58:13 -04:00
|
|
|
(catch 'exit
|
2010-11-01 08:30:44 -04:00
|
|
|
(let* ((scope (plist-get params :scope))
|
|
|
|
(block (plist-get params :block))
|
2008-04-03 11:58:13 -04:00
|
|
|
(ts (plist-get params :tstart))
|
|
|
|
(te (plist-get params :tend))
|
|
|
|
(link (plist-get params :link))
|
2010-11-01 08:30:44 -04:00
|
|
|
(maxlevel (or (plist-get params :maxlevel) 3))
|
2012-12-29 06:35:18 -05:00
|
|
|
(ws (plist-get params :wstart))
|
2013-03-15 06:17:12 -04:00
|
|
|
(ms (plist-get params :mstart))
|
2010-11-01 08:30:44 -04:00
|
|
|
(step (plist-get params :step))
|
|
|
|
(timestamp (plist-get params :timestamp))
|
|
|
|
(formatter (or (plist-get params :formatter)
|
|
|
|
org-clock-clocktable-formatter
|
|
|
|
'org-clocktable-write-default))
|
|
|
|
cc range-text ipos pos one-file-with-archives
|
2010-11-11 11:43:52 -05:00
|
|
|
scope-is-list tbls level)
|
2010-11-01 08:30:44 -04:00
|
|
|
;; Check if we need to do steps
|
|
|
|
(when block
|
|
|
|
;; Get the range text for the header
|
2013-03-15 06:17:12 -04:00
|
|
|
(setq cc (org-clock-special-range block nil t ws ms)
|
2010-11-01 08:30:44 -04:00
|
|
|
ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
|
2008-04-03 11:58:13 -04:00
|
|
|
(when step
|
2010-11-01 08:30:44 -04:00
|
|
|
;; Write many tables, in steps
|
2008-04-24 10:44:12 -04:00
|
|
|
(unless (or block (and ts te))
|
|
|
|
(error "Clocktable `:step' can only be used with `:block' or `:tstart,:end'"))
|
2008-04-03 11:58:13 -04:00
|
|
|
(org-clocktable-steps params)
|
|
|
|
(throw 'exit nil))
|
2010-11-01 08:30:44 -04:00
|
|
|
|
|
|
|
(setq ipos (point)) ; remember the insertion position
|
2008-04-03 11:58:13 -04:00
|
|
|
|
|
|
|
;; Get the right scope
|
|
|
|
(setq pos (point))
|
2008-04-18 03:50:50 -04:00
|
|
|
(cond
|
|
|
|
((and scope (listp scope) (symbolp (car scope)))
|
|
|
|
(setq scope (eval scope)))
|
|
|
|
((eq scope 'agenda)
|
|
|
|
(setq scope (org-agenda-files t)))
|
|
|
|
((eq scope 'agenda-with-archives)
|
|
|
|
(setq scope (org-agenda-files t))
|
|
|
|
(setq scope (org-add-archive-files scope)))
|
|
|
|
((eq scope 'file-with-archives)
|
2015-08-10 12:19:39 -04:00
|
|
|
(setq scope (and buffer-file-name
|
|
|
|
(org-add-archive-files (list buffer-file-name)))
|
2010-11-01 08:30:44 -04:00
|
|
|
one-file-with-archives t)))
|
2008-04-18 09:24:58 -04:00
|
|
|
(setq scope-is-list (and scope (listp scope)))
|
2010-11-01 08:30:44 -04:00
|
|
|
(if scope-is-list
|
|
|
|
;; we collect from several files
|
2008-04-18 03:50:50 -04:00
|
|
|
(let* ((files scope)
|
2008-04-03 11:58:13 -04:00
|
|
|
file)
|
2012-08-28 07:11:12 -04:00
|
|
|
(org-agenda-prepare-buffers files)
|
2008-04-03 11:58:13 -04:00
|
|
|
(while (setq file (pop files))
|
|
|
|
(with-current-buffer (find-buffer-visiting file)
|
2010-11-01 08:30:44 -04:00
|
|
|
(save-excursion
|
|
|
|
(save-restriction
|
|
|
|
(push (org-clock-get-table-data file params) tbls))))))
|
|
|
|
;; Just from the current file
|
|
|
|
(save-restriction
|
|
|
|
;; get the right range into the restriction
|
2015-08-09 21:29:14 -04:00
|
|
|
(org-agenda-prepare-buffers (list (or (buffer-file-name)
|
|
|
|
(current-buffer))))
|
2010-11-01 08:30:44 -04:00
|
|
|
(cond
|
|
|
|
((not scope)) ; use the restriction as it is now
|
|
|
|
((eq scope 'file) (widen))
|
|
|
|
((eq scope 'subtree) (org-narrow-to-subtree))
|
|
|
|
((eq scope 'tree)
|
|
|
|
(while (org-up-heading-safe))
|
|
|
|
(org-narrow-to-subtree))
|
|
|
|
((and (symbolp scope) (string-match "^tree\\([0-9]+\\)$"
|
|
|
|
(symbol-name scope)))
|
|
|
|
(setq level (string-to-number (match-string 1 (symbol-name scope))))
|
|
|
|
(catch 'exit
|
|
|
|
(while (org-up-heading-safe)
|
Don't use `outline-regexp' anymore.
Use `org-outline-regexp' instead or `outline-regexp'. Also use the
new defconst `org-outline-regexp-bol' to match `org-outline-regexp'
at the beginning of line.
* org.el (org-outline-regexp-bol): New defconst.
(org-outline-level, org-set-font-lock-defaults, org-cycle)
(org-overview, org-content, org-flag-drawer)
(org-first-headline-recenter, org-insert-todo-heading)
(org-map-region, org-move-subtree-down, org-paste-subtree)
(org-kill-is-subtree-p, org-context-p, org-refile)
(org-refile-new-child, org-toggle-comment, org-todo)
(org-add-planning-info, org-add-log-setup, org-scan-tags)
(org-set-tags, org-insert-property-drawer)
(org-prepare-agenda-buffers, org-preview-latex-fragment)
(org-speed-command-default-hook, org-check-for-hidden)
(org-toggle-item, org-toggle-heading)
(org-indent-line-function, org-set-autofill-regexps)
(org-fill-paragraph, org-toggle-fixed-width-section)
(org-yank-generic, org-yank-folding-would-swallow-text)
(org-first-sibling-p, org-goto-sibling)
(org-goto-first-child, org-show-entry): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-remember.el (org-remember-handler): Use
`org-outline-regexp-bol'.
* org-mouse.el (org-mouse-match-todo-keyword, org-mode-hook)
(org-mouse-move-tree, org-mouse-transform-to-outline): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-macs.el (org-with-limited-levels)
(org-get-limited-outline-regexp): Use `org-outline-regexp'.
* org-indent.el (org-indent-outline-re)
(org-indent-refresh-section, org-indent-refresh-to): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-html.el (org-export-as-html): Use
`org-outline-regexp-bol'.
* org-footnote.el (org-footnote-at-definition-p)
(org-footnote-normalize): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-exp.el (org-export-preprocess-string): Don't redefine
`outline-regexp'.
* org-docbook.el (org-export-as-docbook): Use
`org-outline-regexp-bol'.
* org-colview.el (org-columns, org-columns-compute): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
* org-colview-xemacs.el (org-columns, org-columns-compute):
Use `org-outline-regexp-bol'.
* org-clock.el (org-clock-insert-selection-line)
(org-clock-in, org-clock-out, org-dblock-write:clocktable):
Use `org-outline-regexp' and `org-outline-regexp-bol'.
* org-ascii.el (org-export-as-ascii)
(org-export-ascii-push-links): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-archive.el (org-archive-to-archive-sibling)
(org-archive-all-done): Use `org-outline-regexp' and
`org-outline-regexp-bol'.
* org-agenda.el (org-agenda, org-search-view)
(org-agenda-list-stuck-projects, org-agenda-get-timestamps)
(org-agenda-get-progress, org-agenda-get-blocks): Use
`org-outline-regexp' and `org-outline-regexp-bol'.
2011-07-17 15:17:08 -04:00
|
|
|
(looking-at org-outline-regexp)
|
2010-11-01 08:30:44 -04:00
|
|
|
(if (<= (org-reduced-level (funcall outline-level)) level)
|
|
|
|
(throw 'exit nil))))
|
|
|
|
(org-narrow-to-subtree)))
|
|
|
|
;; do the table, with no file name.
|
|
|
|
(push (org-clock-get-table-data nil params) tbls)))
|
|
|
|
|
|
|
|
;; OK, at this point we tbls as a list of tables, one per file
|
|
|
|
(setq tbls (nreverse tbls))
|
|
|
|
|
|
|
|
(setq params (plist-put params :multifile scope-is-list))
|
|
|
|
(setq params (plist-put params :one-file-with-archives
|
|
|
|
one-file-with-archives))
|
|
|
|
|
2011-08-18 03:00:20 -04:00
|
|
|
(funcall formatter ipos tbls params))))
|
2010-11-01 08:30:44 -04:00
|
|
|
|
|
|
|
(defun org-clocktable-write-default (ipos tables params)
|
2010-11-11 11:43:52 -05:00
|
|
|
"Write out a clock table at position IPOS in the current buffer.
|
2010-11-01 08:30:44 -04:00
|
|
|
TABLES is a list of tables with clocking data as produced by
|
|
|
|
`org-clock-get-table-data'. PARAMS is the parameter property list obtained
|
2012-01-10 05:56:15 -05:00
|
|
|
from the dynamic block definition."
|
2011-02-22 09:57:50 -05:00
|
|
|
;; This function looks quite complicated, mainly because there are a
|
|
|
|
;; lot of options which can add or remove columns. I have massively
|
|
|
|
;; commented this function, the I hope it is understandable. If
|
|
|
|
;; someone wants to write their own special formatter, this maybe
|
|
|
|
;; much easier because there can be a fixed format with a
|
|
|
|
;; well-defined number of columns...
|
2010-11-01 08:30:44 -04:00
|
|
|
(let* ((hlchars '((1 . "*") (2 . "/")))
|
2011-07-09 12:12:18 -04:00
|
|
|
(lwords (assoc (or (plist-get params :lang)
|
2013-01-27 18:02:51 -05:00
|
|
|
(org-bound-and-true-p org-export-default-language)
|
|
|
|
"en")
|
2011-02-13 07:57:06 -05:00
|
|
|
org-clock-clocktable-language-setup))
|
2010-11-01 08:30:44 -04:00
|
|
|
(multifile (plist-get params :multifile))
|
|
|
|
(block (plist-get params :block))
|
2014-04-16 12:23:47 -04:00
|
|
|
(sort (plist-get params :sort))
|
2010-11-01 08:30:44 -04:00
|
|
|
(ts (plist-get params :tstart))
|
|
|
|
(te (plist-get params :tend))
|
|
|
|
(header (plist-get params :header))
|
|
|
|
(narrow (plist-get params :narrow))
|
2012-12-29 06:35:18 -05:00
|
|
|
(ws (or (plist-get params :wstart) 1))
|
2013-03-15 06:17:12 -04:00
|
|
|
(ms (or (plist-get params :mstart) 1))
|
2010-11-06 16:16:49 -04:00
|
|
|
(link (plist-get params :link))
|
2010-11-01 08:30:44 -04:00
|
|
|
(maxlevel (or (plist-get params :maxlevel) 3))
|
|
|
|
(emph (plist-get params :emphasize))
|
|
|
|
(level-p (plist-get params :level))
|
2013-01-05 12:21:55 -05:00
|
|
|
(org-time-clocksum-use-effort-durations
|
|
|
|
(plist-get params :effort-durations))
|
2010-11-01 08:30:44 -04:00
|
|
|
(timestamp (plist-get params :timestamp))
|
2011-05-31 08:20:14 -04:00
|
|
|
(properties (plist-get params :properties))
|
2010-11-01 08:30:44 -04:00
|
|
|
(ntcol (max 1 (or (plist-get params :tcolumns) 100)))
|
|
|
|
(rm-file-column (plist-get params :one-file-with-archives))
|
|
|
|
(indent (plist-get params :indent))
|
2012-04-21 09:36:04 -04:00
|
|
|
(case-fold-search t)
|
2010-11-06 16:16:49 -04:00
|
|
|
range-text total-time tbl level hlc formula pcol
|
2010-11-02 04:24:06 -04:00
|
|
|
file-time entries entry headline
|
2010-12-03 04:20:41 -05:00
|
|
|
recalc content narrow-cut-p tcol)
|
2010-11-01 08:30:44 -04:00
|
|
|
|
|
|
|
;; Implement abbreviations
|
|
|
|
(when (plist-get params :compact)
|
|
|
|
(setq level nil indent t narrow (or narrow '40!) ntcol 1))
|
|
|
|
|
|
|
|
;; Some consistency test for parameters
|
2012-08-11 13:10:44 -04:00
|
|
|
(unless (integerp ntcol)
|
|
|
|
(setq params (plist-put params :tcolumns (setq ntcol 100))))
|
2010-11-01 08:30:44 -04:00
|
|
|
|
2012-08-11 13:10:44 -04:00
|
|
|
(when (and narrow (integerp narrow) link)
|
|
|
|
;; We cannot have both integer narrow and link
|
|
|
|
(message
|
|
|
|
"Using hard narrowing in clocktable to allow for links")
|
|
|
|
(setq narrow (intern (format "%d!" narrow))))
|
2010-11-01 08:30:44 -04:00
|
|
|
|
2012-08-11 13:10:44 -04:00
|
|
|
(when narrow
|
|
|
|
(cond
|
|
|
|
((integerp narrow))
|
|
|
|
((and (symbolp narrow)
|
|
|
|
(string-match "\\`[0-9]+!\\'" (symbol-name narrow)))
|
|
|
|
(setq narrow-cut-p t
|
|
|
|
narrow (string-to-number (substring (symbol-name narrow)
|
|
|
|
0 -1))))
|
|
|
|
(t
|
|
|
|
(error "Invalid value %s of :narrow property in clock table"
|
|
|
|
narrow))))
|
2010-11-01 08:30:44 -04:00
|
|
|
|
2012-08-11 13:10:44 -04:00
|
|
|
(when block
|
|
|
|
;; Get the range text for the header
|
2013-03-15 06:17:12 -04:00
|
|
|
(setq range-text (nth 2 (org-clock-special-range block nil t ws ms))))
|
2012-08-11 13:10:44 -04:00
|
|
|
|
|
|
|
;; Compute the total time
|
|
|
|
(setq total-time (apply '+ (mapcar 'cadr tables)))
|
|
|
|
|
|
|
|
;; Now we need to output this tsuff
|
|
|
|
(goto-char ipos)
|
|
|
|
|
|
|
|
;; Insert the text *before* the actual table
|
|
|
|
(insert-before-markers
|
|
|
|
(or header
|
|
|
|
;; Format the standard header
|
|
|
|
(concat
|
2012-10-02 16:20:36 -04:00
|
|
|
"#+CAPTION: "
|
2012-08-11 13:10:44 -04:00
|
|
|
(nth 9 lwords) " ["
|
|
|
|
(substring
|
|
|
|
(format-time-string (cdr org-time-stamp-formats))
|
|
|
|
1 -1)
|
|
|
|
"]"
|
|
|
|
(if block (concat ", for " range-text ".") "")
|
2012-10-02 16:20:36 -04:00
|
|
|
"\n")))
|
2012-08-11 13:10:44 -04:00
|
|
|
|
|
|
|
;; Insert the narrowing line
|
|
|
|
(when (and narrow (integerp narrow) (not narrow-cut-p))
|
2010-11-01 08:30:44 -04:00
|
|
|
(insert-before-markers
|
2012-08-11 13:10:44 -04:00
|
|
|
"|" ; table line starter
|
|
|
|
(if multifile "|" "") ; file column, maybe
|
|
|
|
(if level-p "|" "") ; level column, maybe
|
|
|
|
(if timestamp "|" "") ; timestamp column, maybe
|
|
|
|
(if properties (make-string (length properties) ?|) "") ;properties columns, maybe
|
|
|
|
(format "<%d>| |\n" narrow))) ; headline and time columns
|
|
|
|
|
|
|
|
;; Insert the table header line
|
|
|
|
(insert-before-markers
|
|
|
|
"|" ; table line starter
|
|
|
|
(if multifile (concat (nth 1 lwords) "|") "") ; file column, maybe
|
|
|
|
(if level-p (concat (nth 2 lwords) "|") "") ; level column, maybe
|
|
|
|
(if timestamp (concat (nth 3 lwords) "|") "") ; timestamp column, maybe
|
|
|
|
(if properties (concat (mapconcat 'identity properties "|") "|") "") ;properties columns, maybe
|
|
|
|
(concat (nth 4 lwords) "|"
|
|
|
|
(nth 5 lwords) "|\n")) ; headline and time columns
|
|
|
|
|
|
|
|
;; Insert the total time in the table
|
|
|
|
(insert-before-markers
|
|
|
|
"|-\n" ; a hline
|
|
|
|
"|" ; table line starter
|
|
|
|
(if multifile (concat "| " (nth 6 lwords) " ") "")
|
|
|
|
; file column, maybe
|
|
|
|
(if level-p "|" "") ; level column, maybe
|
|
|
|
(if timestamp "|" "") ; timestamp column, maybe
|
|
|
|
(if properties (make-string (length properties) ?|) "") ; properties columns, maybe
|
|
|
|
(concat (format org-clock-total-time-cell-format (nth 7 lwords)) "| ") ; instead of a headline
|
|
|
|
(format org-clock-total-time-cell-format
|
2012-11-11 17:20:24 -05:00
|
|
|
(org-minutes-to-clocksum-string (or total-time 0))) ; the time
|
2012-08-11 13:10:44 -04:00
|
|
|
"|\n") ; close line
|
|
|
|
|
|
|
|
;; Now iterate over the tables and insert the data
|
|
|
|
;; but only if any time has been collected
|
|
|
|
(when (and total-time (> total-time 0))
|
|
|
|
|
|
|
|
(while (setq tbl (pop tables))
|
|
|
|
;; now tbl is the table resulting from one file.
|
|
|
|
(setq file-time (nth 1 tbl))
|
|
|
|
(when (or (and file-time (> file-time 0))
|
|
|
|
(not (plist-get params :fileskip0)))
|
|
|
|
(insert-before-markers "|-\n") ; a hline because a new file starts
|
|
|
|
;; First the file time, if we have multiple files
|
|
|
|
(when multifile
|
|
|
|
;; Summarize the time collected from this file
|
|
|
|
(insert-before-markers
|
|
|
|
(format (concat "| %s %s | %s%s"
|
|
|
|
(format org-clock-file-time-cell-format (nth 8 lwords))
|
|
|
|
" | *%s*|\n")
|
|
|
|
(file-name-nondirectory (car tbl))
|
|
|
|
(if level-p "| " "") ; level column, maybe
|
|
|
|
(if timestamp "| " "") ; timestamp column, maybe
|
|
|
|
(if properties (make-string (length properties) ?|) "") ;properties columns, maybe
|
2012-11-11 17:20:24 -05:00
|
|
|
(org-minutes-to-clocksum-string (nth 1 tbl))))) ; the time
|
2012-08-11 13:10:44 -04:00
|
|
|
|
|
|
|
;; Get the list of node entries and iterate over it
|
|
|
|
(setq entries (nth 2 tbl))
|
|
|
|
(while (setq entry (pop entries))
|
|
|
|
(setq level (car entry)
|
|
|
|
headline (nth 1 entry)
|
|
|
|
hlc (if emph (or (cdr (assoc level hlchars)) "") ""))
|
|
|
|
(when narrow-cut-p
|
|
|
|
(if (and (string-match (concat "\\`" org-bracket-link-regexp
|
|
|
|
"\\'")
|
|
|
|
headline)
|
|
|
|
(match-end 3))
|
|
|
|
(setq headline
|
|
|
|
(format "[[%s][%s]]"
|
|
|
|
(match-string 1 headline)
|
|
|
|
(org-shorten-string (match-string 3 headline)
|
|
|
|
narrow)))
|
|
|
|
(setq headline (org-shorten-string headline narrow))))
|
|
|
|
(insert-before-markers
|
|
|
|
"|" ; start the table line
|
|
|
|
(if multifile "|" "") ; free space for file name column?
|
|
|
|
(if level-p (format "%d|" (car entry)) "") ; level, maybe
|
|
|
|
(if timestamp (concat (nth 2 entry) "|") "") ; timestamp, maybe
|
|
|
|
(if properties
|
|
|
|
(concat
|
|
|
|
(mapconcat
|
|
|
|
(lambda (p) (or (cdr (assoc p (nth 4 entry))) ""))
|
|
|
|
properties "|") "|") "") ;properties columns, maybe
|
|
|
|
(if indent (org-clocktable-indent-string level) "") ; indentation
|
|
|
|
hlc headline hlc "|" ; headline
|
|
|
|
(make-string (min (1- ntcol) (or (- level 1))) ?|)
|
2010-11-01 08:30:44 -04:00
|
|
|
; empty fields for higher levels
|
2012-11-11 17:20:24 -05:00
|
|
|
hlc (org-minutes-to-clocksum-string (nth 3 entry)) hlc ; time
|
2012-08-11 13:10:44 -04:00
|
|
|
"|\n" ; close line
|
|
|
|
)))))
|
|
|
|
;; When exporting subtrees or regions the region might be
|
|
|
|
;; activated, so let's disable ̀delete-active-region'
|
2012-12-23 11:26:45 -05:00
|
|
|
(let ((delete-active-region nil)) (backward-delete-char 1))
|
2012-08-11 13:10:44 -04:00
|
|
|
(if (setq formula (plist-get params :formula))
|
|
|
|
(cond
|
|
|
|
((eq formula '%)
|
|
|
|
;; compute the column where the % numbers need to go
|
|
|
|
(setq pcol (+ 2
|
|
|
|
(if multifile 1 0)
|
|
|
|
(if level-p 1 0)
|
|
|
|
(if timestamp 1 0)
|
|
|
|
(min maxlevel (or ntcol 100))))
|
|
|
|
;; compute the column where the total time is
|
|
|
|
(setq tcol (+ 2
|
|
|
|
(if multifile 1 0)
|
|
|
|
(if level-p 1 0)
|
|
|
|
(if timestamp 1 0)))
|
|
|
|
(insert
|
|
|
|
(format
|
|
|
|
"\n#+TBLFM: $%d='(org-clock-time%% @%d$%d $%d..$%d);%%.1f"
|
|
|
|
pcol ; the column where the % numbers should go
|
|
|
|
(if (and narrow (not narrow-cut-p)) 3 2) ; row of the total time
|
|
|
|
tcol ; column of the total time
|
|
|
|
tcol (1- pcol) ; range of columns where times can be found
|
|
|
|
))
|
|
|
|
(setq recalc t))
|
|
|
|
((stringp formula)
|
|
|
|
(insert "\n#+TBLFM: " formula)
|
|
|
|
(setq recalc t))
|
2012-08-12 23:59:44 -04:00
|
|
|
(t (error "Invalid formula in clocktable")))
|
2012-08-11 13:10:44 -04:00
|
|
|
;; Should we rescue an old formula?
|
|
|
|
(when (stringp (setq content (plist-get params :content)))
|
|
|
|
(when (string-match "^\\([ \t]*#\\+tblfm:.*\\)" content)
|
|
|
|
(setq recalc t)
|
|
|
|
(insert "\n" (match-string 1 (plist-get params :content)))
|
|
|
|
(beginning-of-line 0))))
|
|
|
|
;; Back to beginning, align the table, recalculate if necessary
|
|
|
|
(goto-char ipos)
|
|
|
|
(skip-chars-forward "^|")
|
|
|
|
(org-table-align)
|
|
|
|
(when org-hide-emphasis-markers
|
|
|
|
;; we need to align a second time
|
|
|
|
(org-table-align))
|
2014-04-16 12:23:47 -04:00
|
|
|
(when sort
|
|
|
|
(save-excursion
|
|
|
|
(org-table-goto-line 3)
|
|
|
|
(org-table-goto-column (car sort))
|
|
|
|
(org-table-sort-lines nil (cdr sort))))
|
2012-08-11 13:10:44 -04:00
|
|
|
(when recalc
|
|
|
|
(if (eq formula '%)
|
|
|
|
(save-excursion
|
|
|
|
(if (and narrow (not narrow-cut-p)) (beginning-of-line 2))
|
|
|
|
(org-table-goto-column pcol nil 'force)
|
|
|
|
(insert "%")))
|
|
|
|
(org-table-recalculate 'all))
|
|
|
|
(when rm-file-column
|
|
|
|
;; The file column is actually not wanted
|
|
|
|
(forward-char 1)
|
|
|
|
(org-table-delete-column))
|
|
|
|
total-time))
|
2010-11-01 08:30:44 -04:00
|
|
|
|
|
|
|
(defun org-clocktable-indent-string (level)
|
2015-03-21 20:53:42 -04:00
|
|
|
"Return indentation string according to LEVEL.
|
|
|
|
LEVEL is an integer. Indent by two spaces per level above 1."
|
2014-07-25 05:02:55 -04:00
|
|
|
(if (= level 1) ""
|
2015-03-22 16:45:00 -04:00
|
|
|
(concat "\\_" (make-string (* 2 (1- level)) ?\s))))
|
2008-04-03 11:58:13 -04:00
|
|
|
|
|
|
|
(defun org-clocktable-steps (params)
|
2010-11-01 08:30:44 -04:00
|
|
|
"Step through the range to make a number of clock tables."
|
2008-04-03 11:58:13 -04:00
|
|
|
(let* ((p1 (copy-sequence params))
|
|
|
|
(ts (plist-get p1 :tstart))
|
|
|
|
(te (plist-get p1 :tend))
|
2012-12-29 06:35:18 -05:00
|
|
|
(ws (plist-get p1 :wstart))
|
2013-03-15 06:17:12 -04:00
|
|
|
(ms (plist-get p1 :mstart))
|
2008-04-03 11:58:13 -04:00
|
|
|
(step0 (plist-get p1 :step))
|
|
|
|
(step (cdr (assoc step0 '((day . 86400) (week . 604800)))))
|
2010-05-22 02:18:20 -04:00
|
|
|
(stepskip0 (plist-get p1 :stepskip0))
|
2008-04-03 11:58:13 -04:00
|
|
|
(block (plist-get p1 :block))
|
2013-03-15 06:17:12 -04:00
|
|
|
cc range-text step-time tsb)
|
2008-04-03 11:58:13 -04:00
|
|
|
(when block
|
2013-03-15 06:17:12 -04:00
|
|
|
(setq cc (org-clock-special-range block nil t ws ms)
|
2008-04-03 11:58:13 -04:00
|
|
|
ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
|
2010-08-27 12:40:31 -04:00
|
|
|
(cond
|
|
|
|
((numberp ts)
|
|
|
|
;; If ts is a number, it's an absolute day number from org-agenda.
|
|
|
|
(destructuring-bind (month day year) (calendar-gregorian-from-absolute ts)
|
|
|
|
(setq ts (org-float-time (encode-time 0 0 0 day month year)))))
|
|
|
|
(ts
|
|
|
|
(setq ts (org-float-time
|
|
|
|
(apply 'encode-time (org-parse-time-string ts))))))
|
|
|
|
(cond
|
|
|
|
((numberp te)
|
|
|
|
;; Likewise for te.
|
|
|
|
(destructuring-bind (month day year) (calendar-gregorian-from-absolute te)
|
|
|
|
(setq te (org-float-time (encode-time 0 0 0 day month year)))))
|
|
|
|
(te
|
|
|
|
(setq te (org-float-time
|
|
|
|
(apply 'encode-time (org-parse-time-string te))))))
|
2013-03-15 06:17:12 -04:00
|
|
|
(setq tsb
|
|
|
|
(if (eq step0 'week)
|
2013-03-15 06:43:27 -04:00
|
|
|
(- ts (* 86400 (- (nth 6 (decode-time (seconds-to-time ts))) ws)))
|
2013-03-15 06:17:12 -04:00
|
|
|
ts))
|
2008-04-25 02:18:49 -04:00
|
|
|
(setq p1 (plist-put p1 :header ""))
|
|
|
|
(setq p1 (plist-put p1 :step nil))
|
|
|
|
(setq p1 (plist-put p1 :block nil))
|
2013-03-15 06:17:12 -04:00
|
|
|
(while (< tsb te)
|
2008-04-03 11:58:13 -04:00
|
|
|
(or (bolp) (insert "\n"))
|
2008-04-25 02:18:49 -04:00
|
|
|
(setq p1 (plist-put p1 :tstart (format-time-string
|
2009-03-05 10:11:57 -05:00
|
|
|
(org-time-stamp-format nil t)
|
2013-03-15 06:17:12 -04:00
|
|
|
(seconds-to-time (max tsb ts)))))
|
2008-04-25 02:18:49 -04:00
|
|
|
(setq p1 (plist-put p1 :tend (format-time-string
|
2009-03-05 10:11:57 -05:00
|
|
|
(org-time-stamp-format nil t)
|
2013-03-15 06:17:12 -04:00
|
|
|
(seconds-to-time (min te (setq tsb (+ tsb step)))))))
|
2010-11-01 08:30:44 -04:00
|
|
|
(insert "\n" (if (eq step0 'day) "Daily report: "
|
|
|
|
"Weekly report starting on: ")
|
2008-04-03 11:58:13 -04:00
|
|
|
(plist-get p1 :tstart) "\n")
|
2010-05-22 02:18:20 -04:00
|
|
|
(setq step-time (org-dblock-write:clocktable p1))
|
2010-11-20 05:43:45 -05:00
|
|
|
(re-search-forward "^[ \t]*#\\+END:")
|
2010-05-22 02:18:20 -04:00
|
|
|
(when (and (equal step-time 0) stepskip0)
|
|
|
|
;; Remove the empty table
|
|
|
|
(delete-region (point-at-bol)
|
|
|
|
(save-excursion
|
2010-11-01 08:30:44 -04:00
|
|
|
(re-search-backward "^\\(Daily\\|Weekly\\) report"
|
|
|
|
nil t)
|
2010-05-22 02:18:20 -04:00
|
|
|
(point))))
|
2008-04-03 11:58:13 -04:00
|
|
|
(end-of-line 0))))
|
|
|
|
|
2010-11-01 08:30:44 -04:00
|
|
|
(defun org-clock-get-table-data (file params)
|
|
|
|
"Get the clocktable data for file FILE, with parameters PARAMS.
|
|
|
|
FILE is only for identification - this function assumes that
|
|
|
|
the correct buffer is current, and that the wanted restriction is
|
|
|
|
in place.
|
|
|
|
The return value will be a list with the file name and the total
|
|
|
|
file time (in minutes) as 1st and 2nd elements. The third element
|
|
|
|
of this list will be a list of headline entries. Each entry has the
|
|
|
|
following structure:
|
|
|
|
|
|
|
|
(LEVEL HEADLINE TIMESTAMP TIME)
|
|
|
|
|
|
|
|
LEVEL: The level of the headline, as an integer. This will be
|
|
|
|
the reduced leve, so 1,2,3,... even if only odd levels
|
|
|
|
are being used.
|
|
|
|
HEADLINE: The text of the headline. Depending on PARAMS, this may
|
|
|
|
already be formatted like a link.
|
|
|
|
TIMESTAMP: If PARAMS require it, this will be a time stamp found in the
|
|
|
|
entry, any of SCHEDULED, DEADLINE, NORMAL, or first inactive,
|
|
|
|
in this sequence.
|
|
|
|
TIME: The sum of all time spend in this tree, in minutes. This time
|
|
|
|
will of cause be restricted to the time block and tags match
|
|
|
|
specified in PARAMS."
|
|
|
|
(let* ((maxlevel (or (plist-get params :maxlevel) 3))
|
|
|
|
(timestamp (plist-get params :timestamp))
|
|
|
|
(ts (plist-get params :tstart))
|
|
|
|
(te (plist-get params :tend))
|
2012-12-29 06:35:18 -05:00
|
|
|
(ws (plist-get params :wstart))
|
2013-03-15 06:17:12 -04:00
|
|
|
(ms (plist-get params :mstart))
|
2010-11-01 08:30:44 -04:00
|
|
|
(block (plist-get params :block))
|
|
|
|
(link (plist-get params :link))
|
|
|
|
(tags (plist-get params :tags))
|
2011-05-31 08:20:14 -04:00
|
|
|
(properties (plist-get params :properties))
|
|
|
|
(inherit-property-p (plist-get params :inherit-props))
|
2012-03-21 19:49:07 -04:00
|
|
|
todo-only
|
2010-11-01 08:30:44 -04:00
|
|
|
(matcher (if tags (cdr (org-make-tags-matcher tags))))
|
|
|
|
cc range-text st p time level hdl props tsp tbl)
|
|
|
|
|
|
|
|
(setq org-clock-file-total-minutes nil)
|
|
|
|
(when block
|
2013-03-15 06:17:12 -04:00
|
|
|
(setq cc (org-clock-special-range block nil t ws ms)
|
2010-11-01 08:30:44 -04:00
|
|
|
ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
|
|
|
|
(when (integerp ts) (setq ts (calendar-gregorian-from-absolute ts)))
|
|
|
|
(when (integerp te) (setq te (calendar-gregorian-from-absolute te)))
|
|
|
|
(when (and ts (listp ts))
|
|
|
|
(setq ts (format "%4d-%02d-%02d" (nth 2 ts) (car ts) (nth 1 ts))))
|
|
|
|
(when (and te (listp te))
|
|
|
|
(setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
|
|
|
|
;; Now the times are strings we can parse.
|
2014-10-28 21:42:51 -04:00
|
|
|
(if ts (setq ts (org-matcher-time ts)))
|
|
|
|
(if te (setq te (org-matcher-time te)))
|
2010-11-01 08:30:44 -04:00
|
|
|
(save-excursion
|
|
|
|
(org-clock-sum ts te
|
|
|
|
(unless (null matcher)
|
|
|
|
(lambda ()
|
2012-03-19 16:38:12 -04:00
|
|
|
(let* ((tags-list (org-get-tags-at))
|
|
|
|
(org-scanner-tags tags-list)
|
|
|
|
(org-trust-scanner-tags t))
|
2010-11-01 08:30:44 -04:00
|
|
|
(eval matcher)))))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(setq st t)
|
|
|
|
(while (or (and (bobp) (prog1 st (setq st nil))
|
|
|
|
(get-text-property (point) :org-clock-minutes)
|
|
|
|
(setq p (point-min)))
|
|
|
|
(setq p (next-single-property-change
|
|
|
|
(point) :org-clock-minutes)))
|
|
|
|
(goto-char p)
|
|
|
|
(when (setq time (get-text-property p :org-clock-minutes))
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(when (and (looking-at (org-re "\\(\\*+\\)[ \t]+\\(.*?\\)\\([ \t]+:[[:alnum:]_@#%:]+:\\)?[ \t]*$"))
|
|
|
|
(setq level (org-reduced-level
|
|
|
|
(- (match-end 1) (match-beginning 1))))
|
|
|
|
(<= level maxlevel))
|
|
|
|
(setq hdl (if (not link)
|
|
|
|
(match-string 2)
|
|
|
|
(org-make-link-string
|
|
|
|
(format "file:%s::%s"
|
|
|
|
(buffer-file-name)
|
|
|
|
(save-match-data
|
2014-03-19 05:48:44 -04:00
|
|
|
(match-string 2)))
|
|
|
|
(org-make-org-heading-search-string
|
2014-03-24 01:29:14 -04:00
|
|
|
(replace-regexp-in-string
|
|
|
|
org-bracket-link-regexp
|
|
|
|
(lambda (m) (or (match-string 3 m)
|
|
|
|
(match-string 1 m)))
|
|
|
|
(match-string 2)))))
|
2010-11-01 08:30:44 -04:00
|
|
|
tsp (when timestamp
|
|
|
|
(setq props (org-entry-properties (point)))
|
|
|
|
(or (cdr (assoc "SCHEDULED" props))
|
|
|
|
(cdr (assoc "DEADLINE" props))
|
|
|
|
(cdr (assoc "TIMESTAMP" props))
|
2011-05-31 08:20:14 -04:00
|
|
|
(cdr (assoc "TIMESTAMP_IA" props))))
|
2012-08-11 13:10:44 -04:00
|
|
|
props (when properties
|
|
|
|
(remove nil
|
|
|
|
(mapcar
|
|
|
|
(lambda (p)
|
|
|
|
(when (org-entry-get (point) p inherit-property-p)
|
|
|
|
(cons p (org-entry-get (point) p inherit-property-p))))
|
|
|
|
properties))))
|
2011-05-31 08:20:14 -04:00
|
|
|
(when (> time 0) (push (list level hdl tsp time props) tbl))))))
|
2010-11-01 08:30:44 -04:00
|
|
|
(setq tbl (nreverse tbl))
|
|
|
|
(list file org-clock-file-total-minutes tbl))))
|
|
|
|
|
2008-11-10 14:57:48 -05:00
|
|
|
(defun org-clock-time% (total &rest strings)
|
|
|
|
"Compute a time fraction in percent.
|
|
|
|
TOTAL s a time string like 10:21 specifying the total times.
|
|
|
|
STRINGS is a list of strings that should be checked for a time.
|
|
|
|
The first string that does have a time will be used.
|
|
|
|
This function is made for clock tables."
|
|
|
|
(let ((re "\\([0-9]+\\):\\([0-9]+\\)")
|
|
|
|
tot s)
|
|
|
|
(save-match-data
|
|
|
|
(catch 'exit
|
|
|
|
(if (not (string-match re total))
|
|
|
|
(throw 'exit 0.)
|
|
|
|
(setq tot (+ (string-to-number (match-string 2 total))
|
|
|
|
(* 60 (string-to-number (match-string 1 total)))))
|
|
|
|
(if (= tot 0.) (throw 'exit 0.)))
|
|
|
|
(while (setq s (pop strings))
|
|
|
|
(if (string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
|
|
|
|
(throw 'exit
|
|
|
|
(/ (* 100.0 (+ (string-to-number (match-string 2 s))
|
2010-11-01 08:30:44 -04:00
|
|
|
(* 60 (string-to-number
|
|
|
|
(match-string 1 s)))))
|
2008-11-10 14:57:48 -05:00
|
|
|
tot))))
|
|
|
|
0))))
|
|
|
|
|
2011-04-19 18:13:31 -04:00
|
|
|
;; Saving and loading the clock
|
|
|
|
|
2009-10-26 02:43:49 -04:00
|
|
|
(defvar org-clock-loaded nil
|
|
|
|
"Was the clock file loaded?")
|
|
|
|
|
2013-11-15 00:53:59 -05:00
|
|
|
;;;###autoload
|
Update autoloads.
* org.el: Don't dynamically autoload already autoloaded
functions.
(org-clock-update-time-maybe): Move to org-clock.el.
* org-exp.el (org-insert-export-options-template): Remove
autoload cookie.
* org-clock.el (org-resolve-clocks, org-clock-in)
(org-clock-out, org-clock-cancel, org-clock-goto)
(org-clock-sum, org-clock-display, org-clock-report)
(org-dblock-write:clocktable): Add autoload cookie.
(org-clock-update-time-maybe): Moved from org.el.
* org-beamer.el (org-beamer-sectioning, org-beamer-mode): Ditto.
* org-ascii.el (org-export-ascii-preprocess): Ditto.
* org-archive.el (org-archive-subtree)
(org-archive-to-archive-sibling, org-toggle-archive-tag): Add
autoload cookie.
* org-colview.el (org-columns, org-dblock-write:columnview)
(org-insert-columns-dblock, org-agenda-columns): Ditto.
* org-table.el (org-table-create-with-table.el)
(org-table-create-or-convert-from-region, org-table-create)
(org-table-convert-region, org-table-import)
(org-table-export, org-table-align)
(org-table-justify-field-maybe, org-table-next-field)
(org-table-previous-field, org-table-next-row)
(org-table-copy-down, org-table-field-info)
(org-table-current-dline, org-table-goto-column)
(org-table-insert-column, org-table-delete-column)
(org-table-move-column-right, org-table-move-column-left)
(org-table-move-column, org-table-move-row-down)
(org-table-move-row-up, org-table-move-row)
(org-table-insert-row, org-table-insert-hline)
(org-table-hline-and-move, org-table-kill-row)
(org-table-sort-lines, org-table-cut-region)
(org-table-copy-region, org-table-paste-rectangle)
(org-table-convert, org-table-wrap-region)
(org-table-edit-field, org-table-sum)
(org-table-get-stored-formulas)
(org-table-maybe-eval-formula)
(org-table-rotate-recalc-marks)
(org-table-maybe-recalculate-line, org-table-eval-formula)
(org-table-recalculate, org-table-iterate)
(org-table-edit-formulas)
(org-table-toggle-coordinate-overlays)
(org-table-toggle-formula-debugger, orgtbl-to-generic)
(orgtbl-to-tsv, orgtbl-to-csv, orgtbl-to-latex)
(orgtbl-to-html, orgtbl-to-texinfo, orgtbl-to-orgtbl): Ditto.
2012-10-02 04:52:17 -04:00
|
|
|
(defun org-clock-update-time-maybe ()
|
|
|
|
"If this is a CLOCK line, update it and return t.
|
|
|
|
Otherwise, return nil."
|
|
|
|
(interactive)
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(skip-chars-forward " \t")
|
|
|
|
(when (looking-at org-clock-string)
|
|
|
|
(let ((re (concat "[ \t]*" org-clock-string
|
|
|
|
" *[[<]\\([^]>]+\\)[]>]\\(-+[[<]\\([^]>]+\\)[]>]"
|
|
|
|
"\\([ \t]*=>.*\\)?\\)?"))
|
|
|
|
ts te h m s neg)
|
|
|
|
(cond
|
|
|
|
((not (looking-at re))
|
|
|
|
nil)
|
|
|
|
((not (match-end 2))
|
|
|
|
(when (and (equal (marker-buffer org-clock-marker) (current-buffer))
|
|
|
|
(> org-clock-marker (point))
|
|
|
|
(<= org-clock-marker (point-at-eol)))
|
|
|
|
;; The clock is running here
|
|
|
|
(setq org-clock-start-time
|
|
|
|
(apply 'encode-time
|
|
|
|
(org-parse-time-string (match-string 1))))
|
|
|
|
(org-clock-update-mode-line)))
|
|
|
|
(t
|
|
|
|
(and (match-end 4) (delete-region (match-beginning 4) (match-end 4)))
|
|
|
|
(end-of-line 1)
|
|
|
|
(setq ts (match-string 1)
|
|
|
|
te (match-string 3))
|
|
|
|
(setq s (- (org-float-time
|
|
|
|
(apply 'encode-time (org-parse-time-string te)))
|
|
|
|
(org-float-time
|
|
|
|
(apply 'encode-time (org-parse-time-string ts))))
|
|
|
|
neg (< s 0)
|
|
|
|
s (abs s)
|
|
|
|
h (floor (/ s 3600))
|
|
|
|
s (- s (* 3600 h))
|
|
|
|
m (floor (/ s 60))
|
|
|
|
s (- s (* 60 s)))
|
|
|
|
(insert " => " (format (if neg "-%d:%02d" "%2d:%02d") h m))
|
|
|
|
t))))))
|
|
|
|
|
2008-10-22 21:35:58 -04:00
|
|
|
(defun org-clock-save ()
|
2008-11-20 11:54:26 -05:00
|
|
|
"Persist various clock-related data to disk.
|
|
|
|
The details of what will be saved are regulated by the variable
|
|
|
|
`org-clock-persist'."
|
2009-10-25 02:48:05 -04:00
|
|
|
(when (and org-clock-persist
|
|
|
|
(or org-clock-loaded
|
|
|
|
org-clock-has-been-used
|
|
|
|
(not (file-exists-p org-clock-persist-file))))
|
2008-11-20 11:54:26 -05:00
|
|
|
(let (b)
|
|
|
|
(with-current-buffer (find-file (expand-file-name org-clock-persist-file))
|
|
|
|
(progn
|
|
|
|
(delete-region (point-min) (point-max))
|
|
|
|
;;Store clock
|
|
|
|
(insert (format ";; org-persist.el - %s at %s\n"
|
2014-12-29 15:37:53 -05:00
|
|
|
(system-name) (format-time-string
|
|
|
|
(cdr org-time-stamp-formats))))
|
2009-10-24 08:36:19 -04:00
|
|
|
(if (and (memq org-clock-persist '(t clock))
|
2010-03-09 11:10:15 -05:00
|
|
|
(setq b (org-clocking-buffer))
|
2008-11-20 11:54:26 -05:00
|
|
|
(setq b (or (buffer-base-buffer b) b))
|
|
|
|
(buffer-live-p b)
|
|
|
|
(buffer-file-name b)
|
|
|
|
(or (not org-clock-persist-query-save)
|
|
|
|
(y-or-n-p (concat "Save current clock ("
|
2013-02-19 06:59:46 -05:00
|
|
|
org-clock-heading ") "))))
|
2008-11-20 11:54:26 -05:00
|
|
|
(insert "(setq resume-clock '(\""
|
2010-03-09 11:10:15 -05:00
|
|
|
(buffer-file-name (org-clocking-buffer))
|
2008-11-20 11:54:26 -05:00
|
|
|
"\" . " (int-to-string (marker-position org-clock-marker))
|
|
|
|
"))\n"))
|
2012-08-11 13:10:44 -04:00
|
|
|
;; Store clocked task history. Tasks are stored reversed to make
|
2008-11-20 11:54:26 -05:00
|
|
|
;; reading simpler
|
2009-10-24 08:36:19 -04:00
|
|
|
(when (and (memq org-clock-persist '(t history))
|
|
|
|
org-clock-history)
|
2008-11-20 11:54:26 -05:00
|
|
|
(insert
|
|
|
|
"(setq stored-clock-history '("
|
|
|
|
(mapconcat
|
|
|
|
(lambda (m)
|
|
|
|
(when (and (setq b (marker-buffer m))
|
|
|
|
(setq b (or (buffer-base-buffer b) b))
|
|
|
|
(buffer-live-p b)
|
|
|
|
(buffer-file-name b))
|
|
|
|
(concat "(\"" (buffer-file-name b)
|
|
|
|
"\" . " (int-to-string (marker-position m))
|
|
|
|
")")))
|
|
|
|
(reverse org-clock-history) " ") "))\n"))
|
|
|
|
(save-buffer)
|
|
|
|
(kill-buffer (current-buffer)))))))
|
|
|
|
|
2008-10-22 21:35:58 -04:00
|
|
|
(defun org-clock-load ()
|
2009-04-14 03:50:05 -04:00
|
|
|
"Load clock-related data from disk, maybe resuming a stored clock."
|
2008-11-20 11:54:26 -05:00
|
|
|
(when (and org-clock-persist (not org-clock-loaded))
|
|
|
|
(let ((filename (expand-file-name org-clock-persist-file))
|
2008-11-23 02:07:56 -05:00
|
|
|
(org-clock-in-resume 'auto-restart)
|
2008-11-21 00:19:29 -05:00
|
|
|
resume-clock stored-clock-history)
|
|
|
|
(if (not (file-readable-p filename))
|
|
|
|
(message "Not restoring clock data; %s not found"
|
|
|
|
org-clock-persist-file)
|
|
|
|
(message "%s" "Restoring clock data")
|
|
|
|
(setq org-clock-loaded t)
|
|
|
|
(load-file filename)
|
|
|
|
;; load history
|
|
|
|
(when stored-clock-history
|
|
|
|
(save-window-excursion
|
|
|
|
(mapc (lambda (task)
|
|
|
|
(if (file-exists-p (car task))
|
|
|
|
(org-clock-history-push (cdr task)
|
|
|
|
(find-file (car task)))))
|
|
|
|
stored-clock-history)))
|
|
|
|
;; resume clock
|
|
|
|
(when (and resume-clock org-clock-persist
|
|
|
|
(file-exists-p (car resume-clock))
|
|
|
|
(or (not org-clock-persist-query-resume)
|
2008-12-04 09:33:43 -05:00
|
|
|
(y-or-n-p
|
2008-11-21 00:19:29 -05:00
|
|
|
(concat
|
|
|
|
"Resume clock ("
|
|
|
|
(with-current-buffer (find-file (car resume-clock))
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (cdr resume-clock))
|
|
|
|
(org-back-to-heading t)
|
|
|
|
(and (looking-at org-complex-heading-regexp)
|
|
|
|
(match-string 4))))
|
|
|
|
") "))))
|
|
|
|
(when (file-exists-p (car resume-clock))
|
|
|
|
(with-current-buffer (find-file (car resume-clock))
|
|
|
|
(goto-char (cdr resume-clock))
|
2009-10-24 08:36:19 -04:00
|
|
|
(let ((org-clock-auto-clock-resolution nil))
|
|
|
|
(org-clock-in)
|
2011-01-26 10:21:25 -05:00
|
|
|
(if (outline-invisible-p)
|
2009-10-24 08:36:19 -04:00
|
|
|
(org-show-context))))))))))
|
2008-10-22 21:35:58 -04:00
|
|
|
|
2009-06-16 03:42:05 -04:00
|
|
|
;; Suggested bindings
|
2009-06-17 01:40:09 -04:00
|
|
|
(org-defkey org-mode-map "\C-c\C-x\C-e" 'org-clock-modify-effort-estimate)
|
2009-06-16 03:42:05 -04:00
|
|
|
|
2008-04-03 11:58:13 -04:00
|
|
|
(provide 'org-clock)
|
|
|
|
|
2012-10-02 02:50:46 -04:00
|
|
|
;; Local variables:
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
;; End:
|
|
|
|
|
2008-04-29 01:15:41 -04:00
|
|
|
;;; org-clock.el ends here
|