org-clock.el 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556
  1. ;;; org-clock.el --- The time clocking code for Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  5. ;; Keywords: outlines, hypermedia, calendar, wp
  6. ;; Homepage: http://orgmode.org
  7. ;; Version: 6.29trans
  8. ;;
  9. ;; This file is part of GNU Emacs.
  10. ;;
  11. ;; GNU Emacs is free software: you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation, either version 3 of the License, or
  14. ;; (at your option) any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  21. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  22. ;;
  23. ;;; Commentary:
  24. ;; This file contains the time clocking code for Org-mode
  25. (require 'org)
  26. (eval-when-compile
  27. (require 'cl)
  28. (require 'calendar))
  29. (declare-function calendar-absolute-from-iso "cal-iso" (&optional date))
  30. (defvar org-time-stamp-formats)
  31. (defgroup org-clock nil
  32. "Options concerning clocking working time in Org-mode."
  33. :tag "Org Clock"
  34. :group 'org-progress)
  35. (defcustom org-clock-into-drawer org-log-into-drawer
  36. "Should clocking info be wrapped into a drawer?
  37. When t, clocking info will always be inserted into a :LOGBOOK: drawer.
  38. If necessary, the drawer will be created.
  39. When nil, the drawer will not be created, but used when present.
  40. When an integer and the number of clocking entries in an item
  41. reaches or exceeds this number, a drawer will be created.
  42. When a string, it names the drawer to be used.
  43. The default for this variable is the value of `org-log-into-drawer',
  44. which see."
  45. :group 'org-todo
  46. :group 'org-clock
  47. :type '(choice
  48. (const :tag "Always" t)
  49. (const :tag "Only when drawer exists" nil)
  50. (integer :tag "When at least N clock entries")
  51. (const :tag "Into LOGBOOK drawer" "LOGBOOK")
  52. (string :tag "Into Drawer named...")))
  53. (defcustom org-clock-out-when-done t
  54. "When non-nil, clock will be stopped when the clocked entry is marked DONE.
  55. A nil value means, clock will keep running until stopped explicitly with
  56. `C-c C-x C-o', or until the clock is started in a different item."
  57. :group 'org-clock
  58. :type 'boolean)
  59. (defcustom org-clock-out-remove-zero-time-clocks nil
  60. "Non-nil means, remove the clock line when the resulting time is zero."
  61. :group 'org-clock
  62. :type 'boolean)
  63. (defcustom org-clock-in-switch-to-state nil
  64. "Set task to a special todo state while clocking it.
  65. The value should be the state to which the entry should be
  66. switched. If the value is a function, it must take one
  67. parameter (the current TODO state of the item) and return the
  68. state to switch it to."
  69. :group 'org-clock
  70. :group 'org-todo
  71. :type '(choice
  72. (const :tag "Don't force a state" nil)
  73. (string :tag "State")
  74. (symbol :tag "Function")))
  75. (defcustom org-clock-out-switch-to-state nil
  76. "Set task to a special todo state after clocking out.
  77. The value should be the state to which the entry should be
  78. switched. If the value is a function, it must take one
  79. parameter (the current TODO state of the item) and return the
  80. state to switch it to."
  81. :group 'org-clock
  82. :group 'org-todo
  83. :type '(choice
  84. (const :tag "Don't force a state" nil)
  85. (string :tag "State")
  86. (symbol :tag "Function")))
  87. (defcustom org-clock-history-length 5
  88. "Number of clock tasks to remember in history."
  89. :group 'org-clock
  90. :type 'integer)
  91. (defcustom org-clock-goto-may-find-recent-task t
  92. "Non-nil means, `org-clock-goto' can go to recent task if no active clock."
  93. :group 'org-clock
  94. :type 'boolean)
  95. (defcustom org-clock-heading-function nil
  96. "When non-nil, should be a function to create `org-clock-heading'.
  97. This is the string shown in the mode line when a clock is running.
  98. The function is called with point at the beginning of the headline."
  99. :group 'org-clock
  100. :type 'function)
  101. (defcustom org-clock-string-limit 0
  102. "Maximum length of clock strings in the modeline. 0 means no limit."
  103. :group 'org-clock
  104. :type 'integer)
  105. (defcustom org-clock-in-resume nil
  106. "If non-nil, resume clock when clocking into task with open clock.
  107. When clocking into a task with a clock entry which has not been closed,
  108. the clock can be resumed from that point."
  109. :group 'org-clock
  110. :type 'boolean)
  111. (defcustom org-clock-persist nil
  112. "When non-nil, save the running clock when emacs is closed.
  113. The clock is resumed when emacs restarts.
  114. When this is t, both the running clock, and the entire clock
  115. history are saved. When this is the symbol `clock', only the
  116. running clock is saved.
  117. When Emacs restarts with saved clock information, the file containing the
  118. running clock as well as all files mentioned in the clock history will
  119. be visited.
  120. All this depends on running `org-clock-persistence-insinuate' in .emacs"
  121. :group 'org-clock
  122. :type '(choice
  123. (const :tag "Just the running clock" clock)
  124. (const :tag "Clock and history" t)
  125. (const :tag "No persistence" nil)))
  126. (defcustom org-clock-persist-file (convert-standard-filename
  127. "~/.emacs.d/org-clock-save.el")
  128. "File to save clock data to."
  129. :group 'org-clock
  130. :type 'string)
  131. (defcustom org-clock-persist-query-save nil
  132. "When non-nil, ask before saving the current clock on exit."
  133. :group 'org-clock
  134. :type 'boolean)
  135. (defcustom org-clock-persist-query-resume t
  136. "When non-nil, ask before resuming any stored clock during load."
  137. :group 'org-clock
  138. :type 'boolean)
  139. (defcustom org-clock-sound nil
  140. "Sound that will used for notifications.
  141. Possible values:
  142. nil no sound played.
  143. t standard Emacs beep
  144. file name play this sound file. If not possible, fall back to beep"
  145. :group 'org-clock
  146. :type '(choice
  147. (const :tag "No sound" nil)
  148. (const :tag "Standard beep" t)
  149. (file :tag "Play sound file")))
  150. (defcustom org-clock-modeline-total 'auto
  151. "Default setting for the time included for the modeline clock.
  152. This can be overruled locally using the CLOCK_MODELINE_TOTAL property.
  153. Allowed values are:
  154. current Only the time in the current instance of the clock
  155. today All time clocked inot this task today
  156. repeat All time clocked into this task since last repeat
  157. all All time ever recorded for this task
  158. auto Automtically, either `all', or `repeat' for repeating tasks"
  159. :group 'org-clock
  160. :type '(choice
  161. (const :tag "Current clock" current)
  162. (const :tag "Today's task time" today)
  163. (const :tag "Since last repeat" repeat)
  164. (const :tag "All task time" all)
  165. (const :tag "Automatically, `all' or since `repeat'" auto)))
  166. (defcustom org-show-notification-handler nil
  167. "Function or program to send notification with.
  168. The function or program will be called with the notification
  169. string as argument."
  170. :group 'org-clock
  171. :type '(choice
  172. (string :tag "Program")
  173. (function :tag "Function")))
  174. (defvar org-clock-in-prepare-hook nil
  175. "Hook run when preparing the clock.
  176. This hook is run before anything happens to the task that
  177. you want to clock in. For example, you can use this hook
  178. to add an effort property.")
  179. (defvar org-clock-in-hook nil
  180. "Hook run when starting the clock.")
  181. (defvar org-clock-out-hook nil
  182. "Hook run when stopping the current clock.")
  183. (defvar org-clock-cancel-hook nil
  184. "Hook run when cancelling the current clock.")
  185. (defvar org-clock-goto-hook nil
  186. "Hook run when selecting the currently clocked-in entry.")
  187. ;;; The clock for measuring work time.
  188. (defvar org-mode-line-string "")
  189. (put 'org-mode-line-string 'risky-local-variable t)
  190. (defvar org-clock-mode-line-timer nil)
  191. (defvar org-clock-heading "")
  192. (defvar org-clock-heading-for-remember "")
  193. (defvar org-clock-start-time "")
  194. (defvar org-clock-effort ""
  195. "Effort estimate of the currently clocking task")
  196. (defvar org-clock-total-time nil
  197. "Holds total time, spent previously on currently clocked item.
  198. This does not include the time in the currently running clock.")
  199. (defvar org-clock-history nil
  200. "List of marker pointing to recent clocked tasks.")
  201. (defvar org-clock-default-task (make-marker)
  202. "Marker pointing to the default task that should clock time.
  203. The clock can be made to switch to this task after clocking out
  204. of a different task.")
  205. (defvar org-clock-interrupted-task (make-marker)
  206. "Marker pointing to the task that has been interrupted by the current clock.")
  207. (defvar org-clock-mode-line-map (make-sparse-keymap))
  208. (define-key org-clock-mode-line-map [mode-line mouse-2] 'org-clock-goto)
  209. (define-key org-clock-mode-line-map [mode-line mouse-1] 'org-clock-menu)
  210. (defun org-clock-menu ()
  211. (interactive)
  212. (popup-menu
  213. '("Clock"
  214. ["Clock out" org-clock-out t]
  215. ["Change effort estimate" org-clock-modify-effort-estimate t]
  216. ["Go to clock entry" org-clock-goto t]
  217. ["Switch task" (lambda () (interactive) (org-clock-in '(4))) :active t :keys "C-u C-c C-x C-i"])))
  218. (defun org-clock-history-push (&optional pos buffer)
  219. "Push a marker to the clock history."
  220. (setq org-clock-history-length (max 1 (min 35 org-clock-history-length)))
  221. (let ((m (move-marker (make-marker) (or pos (point)) buffer)) n l)
  222. (while (setq n (member m org-clock-history))
  223. (move-marker (car n) nil))
  224. (setq org-clock-history
  225. (delq nil
  226. (mapcar (lambda (x) (if (marker-buffer x) x nil))
  227. org-clock-history)))
  228. (when (>= (setq l (length org-clock-history)) org-clock-history-length)
  229. (setq org-clock-history
  230. (nreverse
  231. (nthcdr (- l org-clock-history-length -1)
  232. (nreverse org-clock-history)))))
  233. (push m org-clock-history)))
  234. (defun org-clock-save-markers-for-cut-and-paste (beg end)
  235. "Save relative positions of markers in region."
  236. (org-check-and-save-marker org-clock-marker beg end)
  237. (org-check-and-save-marker org-clock-hd-marker beg end)
  238. (org-check-and-save-marker org-clock-default-task beg end)
  239. (org-check-and-save-marker org-clock-interrupted-task beg end)
  240. (mapc (lambda (m) (org-check-and-save-marker m beg end))
  241. org-clock-history))
  242. (defun org-clock-select-task (&optional prompt)
  243. "Select a task that recently was associated with clocking."
  244. (interactive)
  245. (let (sel-list rpl (i 0) s)
  246. (save-window-excursion
  247. (org-switch-to-buffer-other-window
  248. (get-buffer-create "*Clock Task Select*"))
  249. (erase-buffer)
  250. (when (marker-buffer org-clock-default-task)
  251. (insert (org-add-props "Default Task\n" nil 'face 'bold))
  252. (setq s (org-clock-insert-selection-line ?d org-clock-default-task))
  253. (push s sel-list))
  254. (when (marker-buffer org-clock-interrupted-task)
  255. (insert (org-add-props "The task interrupted by starting the last one\n" nil 'face 'bold))
  256. (setq s (org-clock-insert-selection-line ?i org-clock-interrupted-task))
  257. (push s sel-list))
  258. (when (marker-buffer org-clock-marker)
  259. (insert (org-add-props "Current Clocking Task\n" nil 'face 'bold))
  260. (setq s (org-clock-insert-selection-line ?c org-clock-marker))
  261. (push s sel-list))
  262. (insert (org-add-props "Recent Tasks\n" nil 'face 'bold))
  263. (mapc
  264. (lambda (m)
  265. (when (marker-buffer m)
  266. (setq i (1+ i)
  267. s (org-clock-insert-selection-line
  268. (if (< i 10)
  269. (+ i ?0)
  270. (+ i (- ?A 10))) m))
  271. (push s sel-list)))
  272. org-clock-history)
  273. (org-fit-window-to-buffer)
  274. (message (or prompt "Select task for clocking:"))
  275. (setq rpl (read-char-exclusive))
  276. (cond
  277. ((eq rpl ?q) nil)
  278. ((eq rpl ?x) nil)
  279. ((assoc rpl sel-list) (cdr (assoc rpl sel-list)))
  280. (t (error "Invalid task choice %c" rpl))))))
  281. (defun org-clock-insert-selection-line (i marker)
  282. "Insert a line for the clock selection menu.
  283. And return a cons cell with the selection character integer and the marker
  284. pointing to it."
  285. (when (marker-buffer marker)
  286. (let (file cat task heading prefix)
  287. (with-current-buffer (org-base-buffer (marker-buffer marker))
  288. (save-excursion
  289. (save-restriction
  290. (widen)
  291. (goto-char marker)
  292. (setq file (buffer-file-name (marker-buffer marker))
  293. cat (or (org-get-category)
  294. (progn (org-refresh-category-properties)
  295. (org-get-category)))
  296. heading (org-get-heading 'notags)
  297. prefix (save-excursion
  298. (org-back-to-heading t)
  299. (looking-at "\\*+ ")
  300. (match-string 0))
  301. task (substring
  302. (org-fontify-like-in-org-mode
  303. (concat prefix heading)
  304. org-odd-levels-only)
  305. (length prefix))))))
  306. (when (and cat task)
  307. (insert (format "[%c] %-15s %s\n" i cat task))
  308. (cons i marker)))))
  309. (defun org-clock-get-clock-string ()
  310. "Form a clock-string, that will be show in the mode line.
  311. If an effort estimate was defined for current item, use
  312. 01:30/01:50 format (clocked/estimated).
  313. If not, show simply the clocked time like 01:50."
  314. (let* ((clocked-time (org-clock-get-clocked-time))
  315. (h (floor clocked-time 60))
  316. (m (- clocked-time (* 60 h))))
  317. (if (and org-clock-effort)
  318. (let* ((effort-in-minutes (org-hh:mm-string-to-minutes org-clock-effort))
  319. (effort-h (floor effort-in-minutes 60))
  320. (effort-m (- effort-in-minutes (* effort-h 60))))
  321. (format (concat "-[" org-time-clocksum-format "/" org-time-clocksum-format " (%s)]")
  322. h m effort-h effort-m org-clock-heading))
  323. (format (concat "-[" org-time-clocksum-format " (%s)]")
  324. h m org-clock-heading))))
  325. (defun org-clock-update-mode-line ()
  326. (setq org-mode-line-string
  327. (org-propertize
  328. (let ((clock-string (org-clock-get-clock-string))
  329. (help-text "Org-mode clock is running.\nmouse-1 shows a menu\nmouse-2 will jump to task"))
  330. (if (and (> org-clock-string-limit 0)
  331. (> (length clock-string) org-clock-string-limit))
  332. (org-propertize (substring clock-string 0 org-clock-string-limit)
  333. 'help-echo (concat help-text ": " org-clock-heading))
  334. (org-propertize clock-string 'help-echo help-text)))
  335. 'local-map org-clock-mode-line-map
  336. 'mouse-face (if (featurep 'xemacs) 'highlight 'mode-line-highlight)
  337. 'face 'org-mode-line-clock))
  338. (if org-clock-effort (org-clock-notify-once-if-expired))
  339. (force-mode-line-update))
  340. (defun org-clock-get-clocked-time ()
  341. "Get the clocked time for the current item in minutes.
  342. The time returned includes the the time spent on this task in
  343. previous clocking intervals."
  344. (let ((currently-clocked-time
  345. (floor (- (time-to-seconds (current-time))
  346. (time-to-seconds org-clock-start-time)) 60)))
  347. (+ currently-clocked-time (or org-clock-total-time 0))))
  348. (defun org-clock-modify-effort-estimate (&optional value)
  349. "Add to or set the effort estimate of the item currently being clocked.
  350. VALUE can be a number of minutes, or a string with forat hh:mm or mm.
  351. WHen the strig starts with a + or a - sign, the current value of the effort
  352. property will be changed by that amount.
  353. This will update the \"Effort\" property of currently clocked item, and
  354. the mode line."
  355. (interactive)
  356. (when (org-clock-is-active)
  357. (let ((current org-clock-effort) sign)
  358. (unless value
  359. ;; Prompt user for a value or a change
  360. (setq value
  361. (read-string
  362. (format "Set effort (hh:mm or mm%s): "
  363. (if current
  364. (format ", prefix + to add to %s" org-clock-effort)
  365. "")))))
  366. (when (stringp value)
  367. ;; A string. See if it is a delta
  368. (setq sign (string-to-char value))
  369. (if (member sign '(?- ?+))
  370. (setq current (org-hh:mm-string-to-minutes (substring current 1)))
  371. (setq current 0))
  372. (setq value (org-hh:mm-string-to-minutes value))
  373. (if (equal ?- sign)
  374. (setq value (- current value))
  375. (if (equal ?+ sign) (setq value (+ current value)))))
  376. (setq value (max 0 value)
  377. org-clock-effort (org-minutes-to-hh:mm-string value))
  378. (org-entry-put org-clock-marker "Effort" org-clock-effort)
  379. (org-clock-update-mode-line))))
  380. (defvar org-clock-notification-was-shown nil
  381. "Shows if we have shown notification already.")
  382. (defun org-clock-notify-once-if-expired ()
  383. "Show notification if we spent more time than we estimated before.
  384. Notification is shown only once."
  385. (when (marker-buffer org-clock-marker)
  386. (let ((effort-in-minutes (org-hh:mm-string-to-minutes org-clock-effort))
  387. (clocked-time (org-clock-get-clocked-time)))
  388. (if (>= clocked-time effort-in-minutes)
  389. (unless org-clock-notification-was-shown
  390. (setq org-clock-notification-was-shown t)
  391. (org-clock-play-sound)
  392. (org-show-notification
  393. (format "Task '%s' should be finished by now. (%s)"
  394. org-clock-heading org-clock-effort)))
  395. (setq org-clock-notification-was-shown nil)))))
  396. (defun org-show-notification (notification)
  397. "Show notification.
  398. Use `org-show-notification-handler' if defined,
  399. use libnotify if available, or fall back on a message."
  400. (cond ((functionp org-show-notification-handler)
  401. (funcall org-show-notification-handler notification))
  402. ((stringp org-show-notification-handler)
  403. (start-process "emacs-timer-notification" nil
  404. org-show-notification-handler notification))
  405. ((org-program-exists "notify-send")
  406. (start-process "emacs-timer-notification" nil
  407. "notify-send" notification))
  408. ;; Maybe the handler will send a message, so only use message as
  409. ;; a fall back option
  410. (t (message notification))))
  411. (defun org-clock-play-sound ()
  412. "Play sound as configured by `org-clock-sound'.
  413. Use alsa's aplay tool if available."
  414. (cond
  415. ((not org-clock-sound))
  416. ((eq org-clock-sound t) (beep t) (beep t))
  417. ((stringp org-clock-sound)
  418. (if (file-exists-p org-clock-sound)
  419. (if (org-program-exists "aplay")
  420. (start-process "org-clock-play-notification" nil
  421. "aplay" org-clock-sound)
  422. (condition-case nil
  423. (play-sound-file org-clock-sound)
  424. (error (beep t) (beep t))))))))
  425. (defun org-program-exists (program-name)
  426. "Checks whenever we can locate program and launch it."
  427. (if (eq system-type 'gnu/linux)
  428. (= 0 (call-process "which" nil nil nil program-name))))
  429. (defvar org-clock-mode-line-entry nil
  430. "Information for the modeline about the running clock.")
  431. (defun org-clock-in (&optional select)
  432. "Start the clock on the current item.
  433. If necessary, clock-out of the currently active clock.
  434. With prefix arg SELECT, offer a list of recently clocked tasks to
  435. clock into. When SELECT is `C-u C-u', clock into the current task and mark
  436. is as the default task, a special task that will always be offered in
  437. the clocking selection, associated with the letter `d'."
  438. (interactive "P")
  439. (setq org-clock-notification-was-shown nil)
  440. (catch 'abort
  441. (let ((interrupting (marker-buffer org-clock-marker))
  442. ts selected-task target-pos (msg-extra ""))
  443. (when (equal select '(4))
  444. (setq selected-task (org-clock-select-task "Clock-in on task: "))
  445. (if selected-task
  446. (setq selected-task (copy-marker selected-task))
  447. (error "Abort")))
  448. (when interrupting
  449. ;; We are interrupting the clocking of a different task.
  450. ;; Save a marker to this task, so that we can go back.
  451. (move-marker org-clock-interrupted-task
  452. (marker-position org-clock-marker)
  453. (marker-buffer org-clock-marker))
  454. (org-clock-out t))
  455. (when (equal select '(16))
  456. ;; Mark as default clocking task
  457. (org-clock-mark-default-task))
  458. (setq target-pos (point)) ;; we want to clock in at this location
  459. (run-hooks 'org-clock-in-prepare-hook)
  460. (save-excursion
  461. (when (and selected-task (marker-buffer selected-task))
  462. ;; There is a selected task, move to the correct buffer
  463. ;; and set the new target position.
  464. (set-buffer (org-base-buffer (marker-buffer selected-task)))
  465. (setq target-pos (marker-position selected-task))
  466. (move-marker selected-task nil))
  467. (save-excursion
  468. (save-restriction
  469. (widen)
  470. (goto-char target-pos)
  471. (org-back-to-heading t)
  472. (or interrupting (move-marker org-clock-interrupted-task nil))
  473. (org-clock-history-push)
  474. (cond ((functionp org-clock-in-switch-to-state)
  475. (looking-at org-complex-heading-regexp)
  476. (let ((newstate (funcall org-clock-in-switch-to-state
  477. (match-string 2))))
  478. (if newstate (org-todo newstate))))
  479. ((and org-clock-in-switch-to-state
  480. (not (looking-at (concat outline-regexp "[ \t]*"
  481. org-clock-in-switch-to-state
  482. "\\>"))))
  483. (org-todo org-clock-in-switch-to-state)))
  484. (setq org-clock-heading-for-remember
  485. (and (looking-at org-complex-heading-regexp)
  486. (match-end 4)
  487. (org-trim (buffer-substring (match-end 1)
  488. (match-end 4)))))
  489. (setq org-clock-heading
  490. (cond ((and org-clock-heading-function
  491. (functionp org-clock-heading-function))
  492. (funcall org-clock-heading-function))
  493. ((looking-at org-complex-heading-regexp)
  494. (match-string 4))
  495. (t "???")))
  496. (setq org-clock-heading (org-propertize org-clock-heading
  497. 'face nil))
  498. (org-clock-find-position org-clock-in-resume)
  499. (cond
  500. ((and org-clock-in-resume
  501. (looking-at
  502. (concat "^[ \t]* " org-clock-string
  503. " \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"
  504. " +\\sw+\.? +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$")))
  505. (message "Matched %s" (match-string 1))
  506. (setq ts (concat "[" (match-string 1) "]"))
  507. (goto-char (match-end 1))
  508. (setq org-clock-start-time
  509. (apply 'encode-time
  510. (org-parse-time-string (match-string 1))))
  511. (setq org-clock-effort (org-get-effort))
  512. (setq org-clock-total-time (org-clock-sum-current-item
  513. (org-clock-get-sum-start))))
  514. ((eq org-clock-in-resume 'auto-restart)
  515. ;; called from org-clock-load during startup,
  516. ;; do not interrupt, but warn!
  517. (message "Cannot restart clock because task does not contain unfinished clock")
  518. (ding)
  519. (sit-for 2)
  520. (throw 'abort nil))
  521. (t
  522. (insert-before-markers "\n")
  523. (backward-char 1)
  524. (org-indent-line-function)
  525. (when (and (save-excursion
  526. (end-of-line 0)
  527. (org-in-item-p)))
  528. (beginning-of-line 1)
  529. (org-indent-line-to (- (org-get-indentation) 2)))
  530. (insert org-clock-string " ")
  531. (setq org-clock-effort (org-get-effort))
  532. (setq org-clock-total-time (org-clock-sum-current-item
  533. (org-clock-get-sum-start)))
  534. (setq org-clock-start-time (current-time))
  535. (setq ts (org-insert-time-stamp org-clock-start-time
  536. 'with-hm 'inactive))))
  537. (move-marker org-clock-marker (point) (buffer-base-buffer))
  538. (move-marker org-clock-hd-marker
  539. (save-excursion (org-back-to-heading t) (point))
  540. (buffer-base-buffer))
  541. (or global-mode-string (setq global-mode-string '("")))
  542. (or (memq 'org-mode-line-string global-mode-string)
  543. (setq global-mode-string
  544. (append global-mode-string '(org-mode-line-string))))
  545. (org-clock-update-mode-line)
  546. (setq org-clock-mode-line-timer
  547. (run-with-timer 60 60 'org-clock-update-mode-line))
  548. (message "Clock starts at %s - %s" ts msg-extra)
  549. (run-hooks 'org-clock-in-hook)))))))
  550. (defun org-clock-mark-default-task ()
  551. "Mark current task as default task."
  552. (interactive)
  553. (save-excursion
  554. (org-back-to-heading t)
  555. (move-marker org-clock-default-task (point))))
  556. (defvar msg-extra)
  557. (defun org-clock-get-sum-start ()
  558. "Return the time from which clock times should be counted.
  559. This is for the currently running clock as it is displayed
  560. in the mode line. This function looks at the properties
  561. LAST_REPEAT and in particular CLOCK_MODELINE_TOTAL and the
  562. corresponding variable `org-clock-modeline-total' and then
  563. decides which time to use."
  564. (let ((cmt (or (org-entry-get nil "CLOCK_MODELINE_TOTAL")
  565. (symbol-name org-clock-modeline-total)))
  566. (lr (org-entry-get nil "LAST_REPEAT")))
  567. (cond
  568. ((equal cmt "current")
  569. (setq msg-extra "showing time in current clock instance")
  570. (current-time))
  571. ((equal cmt "today")
  572. (setq msg-extra "showing today's task time.")
  573. (let* ((dt (decode-time (current-time))))
  574. (setq dt (append (list 0 0 0) (nthcdr 3 dt)))
  575. (if org-extend-today-until
  576. (setf (nth 2 dt) org-extend-today-until))
  577. (apply 'encode-time dt)))
  578. ((or (equal cmt "all")
  579. (and (or (not cmt) (equal cmt "auto"))
  580. (not lr)))
  581. (setq msg-extra "showing entire task time.")
  582. nil)
  583. ((or (equal cmt "repeat")
  584. (and (or (not cmt) (equal cmt "auto"))
  585. lr))
  586. (setq msg-extra "showing task time since last repeat.")
  587. (if (not lr)
  588. nil
  589. (org-time-string-to-time lr)))
  590. (t nil))))
  591. (defun org-clock-find-position (find-unclosed)
  592. "Find the location where the next clock line should be inserted.
  593. When FIND-UNCLOSED is non-nil, first check if there is an unclosed clock
  594. line and position cursor in that line."
  595. (org-back-to-heading t)
  596. (catch 'exit
  597. (let ((beg (save-excursion
  598. (beginning-of-line 2)
  599. (or (bolp) (newline))
  600. (point)))
  601. (end (progn (outline-next-heading) (point)))
  602. (re (concat "^[ \t]*" org-clock-string))
  603. (cnt 0)
  604. (drawer (if (stringp org-clock-into-drawer)
  605. org-clock-into-drawer "LOGBOOK"))
  606. first last ind-last)
  607. (goto-char beg)
  608. (when (and find-unclosed
  609. (re-search-forward
  610. (concat "^[ \t]* " org-clock-string
  611. " \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"
  612. " +\\sw+ +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$")
  613. end t))
  614. (beginning-of-line 1)
  615. (throw 'exit t))
  616. (when (eobp) (newline) (setq end (max (point) end)))
  617. (when (re-search-forward (concat "^[ \t]*:" drawer ":") end t)
  618. ;; we seem to have a CLOCK drawer, so go there.
  619. (beginning-of-line 2)
  620. (or org-log-states-order-reversed
  621. (and (re-search-forward org-property-end-re nil t)
  622. (goto-char (match-beginning 0))))
  623. (throw 'exit t))
  624. ;; Lets count the CLOCK lines
  625. (goto-char beg)
  626. (while (re-search-forward re end t)
  627. (setq first (or first (match-beginning 0))
  628. last (match-beginning 0)
  629. cnt (1+ cnt)))
  630. (when (and (integerp org-clock-into-drawer)
  631. last
  632. (>= (1+ cnt) org-clock-into-drawer))
  633. ;; Wrap current entries into a new drawer
  634. (goto-char last)
  635. (setq ind-last (org-get-indentation))
  636. (beginning-of-line 2)
  637. (if (and (>= (org-get-indentation) ind-last)
  638. (org-at-item-p))
  639. (org-end-of-item))
  640. (insert ":END:\n")
  641. (beginning-of-line 0)
  642. (org-indent-line-to ind-last)
  643. (goto-char first)
  644. (insert ":" drawer ":\n")
  645. (beginning-of-line 0)
  646. (org-indent-line-function)
  647. (org-flag-drawer t)
  648. (beginning-of-line 2)
  649. (or org-log-states-order-reversed
  650. (and (re-search-forward org-property-end-re nil t)
  651. (goto-char (match-beginning 0))))
  652. (throw 'exit nil))
  653. (goto-char beg)
  654. (while (and (looking-at (concat "[ \t]*" org-keyword-time-regexp))
  655. (not (equal (match-string 1) org-clock-string)))
  656. ;; Planning info, skip to after it
  657. (beginning-of-line 2)
  658. (or (bolp) (newline)))
  659. (when (or (eq org-clock-into-drawer t)
  660. (stringp org-clock-into-drawer)
  661. (and (integerp org-clock-into-drawer)
  662. (< org-clock-into-drawer 2)))
  663. (insert ":" drawer ":\n:END:\n")
  664. (beginning-of-line -1)
  665. (org-indent-line-function)
  666. (org-flag-drawer t)
  667. (beginning-of-line 2)
  668. (org-indent-line-function)
  669. (beginning-of-line)
  670. (or org-log-states-order-reversed
  671. (and (re-search-forward org-property-end-re nil t)
  672. (goto-char (match-beginning 0))))))))
  673. (defun org-clock-out (&optional fail-quietly)
  674. "Stop the currently running clock.
  675. If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
  676. (interactive)
  677. (catch 'exit
  678. (if (not (marker-buffer org-clock-marker))
  679. (if fail-quietly (throw 'exit t) (error "No active clock")))
  680. (let (ts te s h m remove)
  681. (save-excursion
  682. (set-buffer (marker-buffer org-clock-marker))
  683. (save-restriction
  684. (widen)
  685. (goto-char org-clock-marker)
  686. (beginning-of-line 1)
  687. (if (and (looking-at (concat "[ \t]*" org-keyword-time-regexp))
  688. (equal (match-string 1) org-clock-string))
  689. (setq ts (match-string 2))
  690. (if fail-quietly (throw 'exit nil) (error "Clock start time is gone")))
  691. (goto-char (match-end 0))
  692. (delete-region (point) (point-at-eol))
  693. (insert "--")
  694. (setq te (org-insert-time-stamp (current-time) 'with-hm 'inactive))
  695. (setq s (- (time-to-seconds (apply 'encode-time (org-parse-time-string te)))
  696. (time-to-seconds (apply 'encode-time (org-parse-time-string ts))))
  697. h (floor (/ s 3600))
  698. s (- s (* 3600 h))
  699. m (floor (/ s 60))
  700. s (- s (* 60 s)))
  701. (insert " => " (format "%2d:%02d" h m))
  702. (when (setq remove (and org-clock-out-remove-zero-time-clocks
  703. (= (+ h m) 0)))
  704. (beginning-of-line 1)
  705. (delete-region (point) (point-at-eol))
  706. (and (looking-at "\n") (> (point-max) (1+ (point)))
  707. (delete-char 1)))
  708. (move-marker org-clock-marker nil)
  709. (move-marker org-clock-hd-marker nil)
  710. (when org-log-note-clock-out
  711. (org-add-log-setup 'clock-out nil nil nil nil
  712. (concat "# Task: " (org-get-heading t) "\n\n")))
  713. (when org-clock-mode-line-timer
  714. (cancel-timer org-clock-mode-line-timer)
  715. (setq org-clock-mode-line-timer nil))
  716. (setq global-mode-string
  717. (delq 'org-mode-line-string global-mode-string))
  718. (when org-clock-out-switch-to-state
  719. (save-excursion
  720. (org-back-to-heading t)
  721. (let ((org-inhibit-logging t))
  722. (cond
  723. ((functionp org-clock-out-switch-to-state)
  724. (looking-at org-complex-heading-regexp)
  725. (let ((newstate (funcall org-clock-out-switch-to-state
  726. (match-string 2))))
  727. (if newstate (org-todo newstate))))
  728. ((and org-clock-out-switch-to-state
  729. (not (looking-at (concat outline-regexp "[ \t]*"
  730. org-clock-out-switch-to-state
  731. "\\>"))))
  732. (org-todo org-clock-out-switch-to-state))))))
  733. (force-mode-line-update)
  734. (message (concat "Clock stopped at %s after HH:MM = " org-time-clocksum-format "%s") te h m
  735. (if remove " => LINE REMOVED" ""))
  736. (run-hooks 'org-clock-out-hook))))))
  737. (defun org-clock-cancel ()
  738. "Cancel the running clock be removing the start timestamp."
  739. (interactive)
  740. (if (not (marker-buffer org-clock-marker))
  741. (error "No active clock"))
  742. (save-excursion
  743. (set-buffer (marker-buffer org-clock-marker))
  744. (goto-char org-clock-marker)
  745. (delete-region (1- (point-at-bol)) (point-at-eol)))
  746. (move-marker 'org-clock-marker nil)
  747. (move-marker 'org-clock-hd-marker nil)
  748. (setq global-mode-string
  749. (delq 'org-mode-line-string global-mode-string))
  750. (force-mode-line-update)
  751. (message "Clock canceled")
  752. (run-hooks 'org-clock-cancel-hook))
  753. (defun org-clock-goto (&optional select)
  754. "Go to the currently clocked-in entry, or to the most recently clocked one.
  755. With prefix arg SELECT, offer recently clocked tasks for selection."
  756. (interactive "@P")
  757. (let* ((recent nil)
  758. (m (cond
  759. (select
  760. (or (org-clock-select-task "Select task to go to: ")
  761. (error "No task selected")))
  762. ((marker-buffer org-clock-marker) org-clock-marker)
  763. ((and org-clock-goto-may-find-recent-task
  764. (car org-clock-history)
  765. (marker-buffer (car org-clock-history)))
  766. (setq recent t)
  767. (car org-clock-history))
  768. (t (error "No active or recent clock task")))))
  769. (switch-to-buffer (marker-buffer m))
  770. (if (or (< m (point-min)) (> m (point-max))) (widen))
  771. (goto-char m)
  772. (org-show-entry)
  773. (org-back-to-heading t)
  774. (org-cycle-hide-drawers 'children)
  775. (recenter)
  776. (if recent
  777. (message "No running clock, this is the most recently clocked task"))
  778. (run-hooks 'org-clock-goto-hook)))
  779. (defvar org-clock-file-total-minutes nil
  780. "Holds the file total time in minutes, after a call to `org-clock-sum'.")
  781. (make-variable-buffer-local 'org-clock-file-total-minutes)
  782. (defun org-clock-sum (&optional tstart tend)
  783. "Sum the times for each subtree.
  784. Puts the resulting times in minutes as a text property on each headline.
  785. TSTART and TEND can mark a time range to be considered."
  786. (interactive)
  787. (let* ((bmp (buffer-modified-p))
  788. (re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*"
  789. org-clock-string
  790. "[ \t]*\\(?:\\(\\[.*?\\]\\)-+\\(\\[.*?\\]\\)\\|=>[ \t]+\\([0-9]+\\):\\([0-9]+\\)\\)"))
  791. (lmax 30)
  792. (ltimes (make-vector lmax 0))
  793. (t1 0)
  794. (level 0)
  795. ts te dt
  796. time)
  797. (if (stringp tstart) (setq tstart (org-time-string-to-seconds tstart)))
  798. (if (stringp tend) (setq tend (org-time-string-to-seconds tend)))
  799. (if (consp tstart) (setq tstart (time-to-seconds tstart)))
  800. (if (consp tend) (setq tend (time-to-seconds tend)))
  801. (remove-text-properties (point-min) (point-max) '(:org-clock-minutes t))
  802. (save-excursion
  803. (goto-char (point-max))
  804. (while (re-search-backward re nil t)
  805. (cond
  806. ((match-end 2)
  807. ;; Two time stamps
  808. (setq ts (match-string 2)
  809. te (match-string 3)
  810. ts (time-to-seconds
  811. (apply 'encode-time (org-parse-time-string ts)))
  812. te (time-to-seconds
  813. (apply 'encode-time (org-parse-time-string te)))
  814. ts (if tstart (max ts tstart) ts)
  815. te (if tend (min te tend) te)
  816. dt (- te ts)
  817. t1 (if (> dt 0) (+ t1 (floor (/ dt 60))) t1)))
  818. ((match-end 4)
  819. ;; A naked time
  820. (setq t1 (+ t1 (string-to-number (match-string 5))
  821. (* 60 (string-to-number (match-string 4))))))
  822. (t ;; A headline
  823. (setq level (- (match-end 1) (match-beginning 1)))
  824. (when (or (> t1 0) (> (aref ltimes level) 0))
  825. (loop for l from 0 to level do
  826. (aset ltimes l (+ (aref ltimes l) t1)))
  827. (setq t1 0 time (aref ltimes level))
  828. (loop for l from level to (1- lmax) do
  829. (aset ltimes l 0))
  830. (goto-char (match-beginning 0))
  831. (put-text-property (point) (point-at-eol) :org-clock-minutes time)))))
  832. (setq org-clock-file-total-minutes (aref ltimes 0)))
  833. (set-buffer-modified-p bmp)))
  834. (defun org-clock-sum-current-item (&optional tstart)
  835. "Returns time, clocked on current item in total"
  836. (save-excursion
  837. (save-restriction
  838. (org-narrow-to-subtree)
  839. (org-clock-sum tstart)
  840. org-clock-file-total-minutes)))
  841. (defun org-clock-display (&optional total-only)
  842. "Show subtree times in the entire buffer.
  843. If TOTAL-ONLY is non-nil, only show the total time for the entire file
  844. in the echo area."
  845. (interactive)
  846. (org-clock-remove-overlays)
  847. (let (time h m p)
  848. (org-clock-sum)
  849. (unless total-only
  850. (save-excursion
  851. (goto-char (point-min))
  852. (while (or (and (equal (setq p (point)) (point-min))
  853. (get-text-property p :org-clock-minutes))
  854. (setq p (next-single-property-change
  855. (point) :org-clock-minutes)))
  856. (goto-char p)
  857. (when (setq time (get-text-property p :org-clock-minutes))
  858. (org-clock-put-overlay time (funcall outline-level))))
  859. (setq h (/ org-clock-file-total-minutes 60)
  860. m (- org-clock-file-total-minutes (* 60 h)))
  861. ;; Arrange to remove the overlays upon next change.
  862. (when org-remove-highlights-with-change
  863. (org-add-hook 'before-change-functions 'org-clock-remove-overlays
  864. nil 'local))))
  865. (message (concat "Total file time: " org-time-clocksum-format " (%d hours and %d minutes)") h m h m)))
  866. (defvar org-clock-overlays nil)
  867. (make-variable-buffer-local 'org-clock-overlays)
  868. (defun org-clock-put-overlay (time &optional level)
  869. "Put an overlays on the current line, displaying TIME.
  870. If LEVEL is given, prefix time with a corresponding number of stars.
  871. This creates a new overlay and stores it in `org-clock-overlays', so that it
  872. will be easy to remove."
  873. (let* ((c 60) (h (floor (/ time 60))) (m (- time (* 60 h)))
  874. (l (if level (org-get-valid-level level 0) 0))
  875. (fmt (concat "%s " org-time-clocksum-format "%s"))
  876. (off 0)
  877. ov tx)
  878. (org-move-to-column c)
  879. (unless (eolp) (skip-chars-backward "^ \t"))
  880. (skip-chars-backward " \t")
  881. (setq ov (org-make-overlay (1- (point)) (point-at-eol))
  882. tx (concat (buffer-substring (1- (point)) (point))
  883. (make-string (+ off (max 0 (- c (current-column)))) ?.)
  884. (org-add-props (format fmt
  885. (make-string l ?*) h m
  886. (make-string (- 16 l) ?\ ))
  887. (list 'face 'org-clock-overlay))
  888. ""))
  889. (if (not (featurep 'xemacs))
  890. (org-overlay-put ov 'display tx)
  891. (org-overlay-put ov 'invisible t)
  892. (org-overlay-put ov 'end-glyph (make-glyph tx)))
  893. (push ov org-clock-overlays)))
  894. (defun org-clock-remove-overlays (&optional beg end noremove)
  895. "Remove the occur highlights from the buffer.
  896. BEG and END are ignored. If NOREMOVE is nil, remove this function
  897. from the `before-change-functions' in the current buffer."
  898. (interactive)
  899. (unless org-inhibit-highlight-removal
  900. (mapc 'org-delete-overlay org-clock-overlays)
  901. (setq org-clock-overlays nil)
  902. (unless noremove
  903. (remove-hook 'before-change-functions
  904. 'org-clock-remove-overlays 'local))))
  905. (defvar state) ;; dynamically scoped into this function
  906. (defun org-clock-out-if-current ()
  907. "Clock out if the current entry contains the running clock.
  908. This is used to stop the clock after a TODO entry is marked DONE,
  909. and is only done if the variable `org-clock-out-when-done' is not nil."
  910. (when (and org-clock-out-when-done
  911. (member state org-done-keywords)
  912. (equal (or (buffer-base-buffer (marker-buffer org-clock-marker))
  913. (marker-buffer org-clock-marker))
  914. (or (buffer-base-buffer (current-buffer))
  915. (current-buffer)))
  916. (< (point) org-clock-marker)
  917. (> (save-excursion (outline-next-heading) (point))
  918. org-clock-marker))
  919. ;; Clock out, but don't accept a logging message for this.
  920. (let ((org-log-note-clock-out nil))
  921. (org-clock-out))))
  922. (add-hook 'org-after-todo-state-change-hook
  923. 'org-clock-out-if-current)
  924. ;;;###autoload
  925. (defun org-get-clocktable (&rest props)
  926. "Get a formatted clocktable with parameters according to PROPS.
  927. The table is created in a temporary buffer, fully formatted and
  928. fontified, and then returned."
  929. ;; Set the defaults
  930. (setq props (plist-put props :name "clocktable"))
  931. (unless (plist-member props :maxlevel)
  932. (setq props (plist-put props :maxlevel 2)))
  933. (unless (plist-member props :scope)
  934. (setq props (plist-put props :scope 'agenda)))
  935. (with-temp-buffer
  936. (org-mode)
  937. (org-create-dblock props)
  938. (org-update-dblock)
  939. (font-lock-fontify-buffer)
  940. (forward-line 2)
  941. (buffer-substring (point) (progn
  942. (re-search-forward "^#\\+END" nil t)
  943. (point-at-bol)))))
  944. (defun org-clock-report (&optional arg)
  945. "Create a table containing a report about clocked time.
  946. If the cursor is inside an existing clocktable block, then the table
  947. will be updated. If not, a new clocktable will be inserted.
  948. When called with a prefix argument, move to the first clock table in the
  949. buffer and update it."
  950. (interactive "P")
  951. (org-clock-remove-overlays)
  952. (when arg
  953. (org-find-dblock "clocktable")
  954. (org-show-entry))
  955. (if (org-in-clocktable-p)
  956. (goto-char (org-in-clocktable-p))
  957. (org-create-dblock (list :name "clocktable"
  958. :maxlevel 2 :scope 'file)))
  959. (org-update-dblock))
  960. (defun org-in-clocktable-p ()
  961. "Check if the cursor is in a clocktable."
  962. (let ((pos (point)) start)
  963. (save-excursion
  964. (end-of-line 1)
  965. (and (re-search-backward "^#\\+BEGIN:[ \t]+clocktable" nil t)
  966. (setq start (match-beginning 0))
  967. (re-search-forward "^#\\+END:.*" nil t)
  968. (>= (match-end 0) pos)
  969. start))))
  970. (defun org-clock-special-range (key &optional time as-strings)
  971. "Return two times bordering a special time range.
  972. Key is a symbol specifying the range and can be one of `today', `yesterday',
  973. `thisweek', `lastweek', `thismonth', `lastmonth', `thisyear', `lastyear'.
  974. A week starts Monday 0:00 and ends Sunday 24:00.
  975. The range is determined relative to TIME. TIME defaults to the current time.
  976. The return value is a cons cell with two internal times like the ones
  977. returned by `current time' or `encode-time'. if AS-STRINGS is non-nil,
  978. the returned times will be formatted strings."
  979. (if (integerp key) (setq key (intern (number-to-string key))))
  980. (let* ((tm (decode-time (or time (current-time))))
  981. (s 0) (m (nth 1 tm)) (h (nth 2 tm))
  982. (d (nth 3 tm)) (month (nth 4 tm)) (y (nth 5 tm))
  983. (dow (nth 6 tm))
  984. (skey (symbol-name key))
  985. (shift 0)
  986. s1 m1 h1 d1 month1 y1 diff ts te fm txt w date)
  987. (cond
  988. ((string-match "^[0-9]+$" skey)
  989. (setq y (string-to-number skey) m 1 d 1 key 'year))
  990. ((string-match "^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)$" skey)
  991. (setq y (string-to-number (match-string 1 skey))
  992. month (string-to-number (match-string 2 skey))
  993. d 1 key 'month))
  994. ((string-match "^\\([0-9]+\\)-[wW]\\([0-9]\\{1,2\\}\\)$" skey)
  995. (require 'cal-iso)
  996. (setq y (string-to-number (match-string 1 skey))
  997. w (string-to-number (match-string 2 skey)))
  998. (setq date (calendar-gregorian-from-absolute
  999. (calendar-absolute-from-iso (list w 1 y))))
  1000. (setq d (nth 1 date) month (car date) y (nth 2 date)
  1001. dow 1
  1002. key 'week))
  1003. ((string-match "^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\\{1,2\\}\\)$" skey)
  1004. (setq y (string-to-number (match-string 1 skey))
  1005. month (string-to-number (match-string 2 skey))
  1006. d (string-to-number (match-string 3 skey))
  1007. key 'day))
  1008. ((string-match "\\([-+][0-9]+\\)$" skey)
  1009. (setq shift (string-to-number (match-string 1 skey))
  1010. key (intern (substring skey 0 (match-beginning 1))))))
  1011. (when (= shift 0)
  1012. (cond ((eq key 'yesterday) (setq key 'today shift -1))
  1013. ((eq key 'lastweek) (setq key 'week shift -1))
  1014. ((eq key 'lastmonth) (setq key 'month shift -1))
  1015. ((eq key 'lastyear) (setq key 'year shift -1))))
  1016. (cond
  1017. ((memq key '(day today))
  1018. (setq d (+ d shift) h 0 m 0 h1 24 m1 0))
  1019. ((memq key '(week thisweek))
  1020. (setq diff (+ (* -7 shift) (if (= dow 0) 6 (1- dow)))
  1021. m 0 h 0 d (- d diff) d1 (+ 7 d)))
  1022. ((memq key '(month thismonth))
  1023. (setq d 1 h 0 m 0 d1 1 month (+ month shift) month1 (1+ month) h1 0 m1 0))
  1024. ((memq key '(year thisyear))
  1025. (setq m 0 h 0 d 1 month 1 y (+ y shift) y1 (1+ y)))
  1026. (t (error "No such time block %s" key)))
  1027. (setq ts (encode-time s m h d month y)
  1028. te (encode-time (or s1 s) (or m1 m) (or h1 h)
  1029. (or d1 d) (or month1 month) (or y1 y)))
  1030. (setq fm (cdr org-time-stamp-formats))
  1031. (cond
  1032. ((memq key '(day today))
  1033. (setq txt (format-time-string "%A, %B %d, %Y" ts)))
  1034. ((memq key '(week thisweek))
  1035. (setq txt (format-time-string "week %G-W%V" ts)))
  1036. ((memq key '(month thismonth))
  1037. (setq txt (format-time-string "%B %Y" ts)))
  1038. ((memq key '(year thisyear))
  1039. (setq txt (format-time-string "the year %Y" ts))))
  1040. (if as-strings
  1041. (list (format-time-string fm ts) (format-time-string fm te) txt)
  1042. (list ts te txt))))
  1043. (defun org-clocktable-shift (dir n)
  1044. "Try to shift the :block date of the clocktable at point.
  1045. Point must be in the #+BEGIN: line of a clocktable, or this function
  1046. will throw an error.
  1047. DIR is a direction, a symbol `left', `right', `up', or `down'.
  1048. Both `left' and `down' shift the block toward the past, `up' and `right'
  1049. push it toward the future.
  1050. N is the number of shift steps to take. The size of the step depends on
  1051. the currently selected interval size."
  1052. (setq n (prefix-numeric-value n))
  1053. (and (memq dir '(left down)) (setq n (- n)))
  1054. (save-excursion
  1055. (goto-char (point-at-bol))
  1056. (if (not (looking-at "#\\+BEGIN: clocktable\\>.*?:block[ \t]+\\(\\S-+\\)"))
  1057. (error "Line needs a :block definition before this command works")
  1058. (let* ((b (match-beginning 1)) (e (match-end 1))
  1059. (s (match-string 1))
  1060. block shift ins y mw d date wp m)
  1061. (cond
  1062. ((equal s "yesterday") (setq s "today-1"))
  1063. ((equal s "lastweek") (setq s "thisweek-1"))
  1064. ((equal s "lastmonth") (setq s "thismonth-1"))
  1065. ((equal s "lastyear") (setq s "thisyear-1")))
  1066. (cond
  1067. ((string-match "^\\(today\\|thisweek\\|thismonth\\|thisyear\\)\\([-+][0-9]+\\)?$" s)
  1068. (setq block (match-string 1 s)
  1069. shift (if (match-end 2)
  1070. (string-to-number (match-string 2 s))
  1071. 0))
  1072. (setq shift (+ shift n))
  1073. (setq ins (if (= shift 0) block (format "%s%+d" block shift))))
  1074. ((string-match "\\([0-9]+\\)\\(-\\([wW]?\\)\\([0-9]\\{1,2\\}\\)\\(-\\([0-9]\\{1,2\\}\\)\\)?\\)?" s)
  1075. ;; 1 1 2 3 3 4 4 5 6 6 5 2
  1076. (setq y (string-to-number (match-string 1 s))
  1077. wp (and (match-end 3) (match-string 3 s))
  1078. mw (and (match-end 4) (string-to-number (match-string 4 s)))
  1079. d (and (match-end 6) (string-to-number (match-string 6 s))))
  1080. (cond
  1081. (d (setq ins (format-time-string
  1082. "%Y-%m-%d"
  1083. (encode-time 0 0 0 (+ d n) m y))))
  1084. ((and wp mw (> (length wp) 0))
  1085. (require 'cal-iso)
  1086. (setq date (calendar-gregorian-from-absolute (calendar-absolute-from-iso (list (+ mw n) 1 y))))
  1087. (setq ins (format-time-string
  1088. "%G-W%V"
  1089. (encode-time 0 0 0 (nth 1 date) (car date) (nth 2 date)))))
  1090. (mw
  1091. (setq ins (format-time-string
  1092. "%Y-%m"
  1093. (encode-time 0 0 0 1 (+ mw n) y))))
  1094. (y
  1095. (setq ins (number-to-string (+ y n))))))
  1096. (t (error "Cannot shift clocktable block")))
  1097. (when ins
  1098. (goto-char b)
  1099. (insert ins)
  1100. (delete-region (point) (+ (point) (- e b)))
  1101. (beginning-of-line 1)
  1102. (org-update-dblock)
  1103. t)))))
  1104. (defun org-dblock-write:clocktable (params)
  1105. "Write the standard clocktable."
  1106. (catch 'exit
  1107. (let* ((hlchars '((1 . "*") (2 . "/")))
  1108. (ins (make-marker))
  1109. (total-time nil)
  1110. (scope (plist-get params :scope))
  1111. (tostring (plist-get params :tostring))
  1112. (multifile (plist-get params :multifile))
  1113. (header (plist-get params :header))
  1114. (maxlevel (or (plist-get params :maxlevel) 3))
  1115. (step (plist-get params :step))
  1116. (emph (plist-get params :emphasize))
  1117. (timestamp (plist-get params :timestamp))
  1118. (ts (plist-get params :tstart))
  1119. (te (plist-get params :tend))
  1120. (block (plist-get params :block))
  1121. (link (plist-get params :link))
  1122. ipos time p level hlc hdl tsp props content recalc formula pcol
  1123. cc beg end pos tbl tbl1 range-text rm-file-column scope-is-list st)
  1124. (setq org-clock-file-total-minutes nil)
  1125. (when step
  1126. (unless (or block (and ts te))
  1127. (error "Clocktable `:step' can only be used with `:block' or `:tstart,:end'"))
  1128. (org-clocktable-steps params)
  1129. (throw 'exit nil))
  1130. (when block
  1131. (setq cc (org-clock-special-range block nil t)
  1132. ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
  1133. (when (integerp ts) (setq ts (calendar-gregorian-from-absolute ts)))
  1134. (when (integerp te) (setq te (calendar-gregorian-from-absolute te)))
  1135. (when (and ts (listp ts))
  1136. (setq ts (format "%4d-%02d-%02d" (nth 2 ts) (car ts) (nth 1 ts))))
  1137. (when (and te (listp te))
  1138. (setq te (format "%4d-%02d-%02d" (nth 2 te) (car te) (nth 1 te))))
  1139. ;; Now the times are strings we can parse.
  1140. (if ts (setq ts (time-to-seconds
  1141. (apply 'encode-time (org-parse-time-string ts)))))
  1142. (if te (setq te (time-to-seconds
  1143. (apply 'encode-time (org-parse-time-string te)))))
  1144. (move-marker ins (point))
  1145. (setq ipos (point))
  1146. ;; Get the right scope
  1147. (setq pos (point))
  1148. (cond
  1149. ((and scope (listp scope) (symbolp (car scope)))
  1150. (setq scope (eval scope)))
  1151. ((eq scope 'agenda)
  1152. (setq scope (org-agenda-files t)))
  1153. ((eq scope 'agenda-with-archives)
  1154. (setq scope (org-agenda-files t))
  1155. (setq scope (org-add-archive-files scope)))
  1156. ((eq scope 'file-with-archives)
  1157. (setq scope (org-add-archive-files (list (buffer-file-name)))
  1158. rm-file-column t)))
  1159. (setq scope-is-list (and scope (listp scope)))
  1160. (save-restriction
  1161. (cond
  1162. ((not scope))
  1163. ((eq scope 'file) (widen))
  1164. ((eq scope 'subtree) (org-narrow-to-subtree))
  1165. ((eq scope 'tree)
  1166. (while (org-up-heading-safe))
  1167. (org-narrow-to-subtree))
  1168. ((and (symbolp scope) (string-match "^tree\\([0-9]+\\)$"
  1169. (symbol-name scope)))
  1170. (setq level (string-to-number (match-string 1 (symbol-name scope))))
  1171. (catch 'exit
  1172. (while (org-up-heading-safe)
  1173. (looking-at outline-regexp)
  1174. (if (<= (org-reduced-level (funcall outline-level)) level)
  1175. (throw 'exit nil))))
  1176. (org-narrow-to-subtree))
  1177. (scope-is-list
  1178. (let* ((files scope)
  1179. (scope 'agenda)
  1180. (p1 (copy-sequence params))
  1181. file)
  1182. (setq p1 (plist-put p1 :tostring t))
  1183. (setq p1 (plist-put p1 :multifile t))
  1184. (setq p1 (plist-put p1 :scope 'file))
  1185. (org-prepare-agenda-buffers files)
  1186. (while (setq file (pop files))
  1187. (with-current-buffer (find-buffer-visiting file)
  1188. (setq tbl1 (org-dblock-write:clocktable p1))
  1189. (when tbl1
  1190. (push (org-clocktable-add-file
  1191. file
  1192. (concat "| |*File time*|*"
  1193. (org-minutes-to-hh:mm-string
  1194. org-clock-file-total-minutes)
  1195. "*|\n"
  1196. tbl1)) tbl)
  1197. (setq total-time (+ (or total-time 0)
  1198. org-clock-file-total-minutes))))))))
  1199. (goto-char pos)
  1200. (unless scope-is-list
  1201. (org-clock-sum ts te)
  1202. (goto-char (point-min))
  1203. (setq st t)
  1204. (while (or (and (bobp) (prog1 st (setq st nil))
  1205. (get-text-property (point) :org-clock-minutes)
  1206. (setq p (point-min)))
  1207. (setq p (next-single-property-change (point) :org-clock-minutes)))
  1208. (goto-char p)
  1209. (when (setq time (get-text-property p :org-clock-minutes))
  1210. (save-excursion
  1211. (beginning-of-line 1)
  1212. (when (and (looking-at (org-re "\\(\\*+\\)[ \t]+\\(.*?\\)\\([ \t]+:[[:alnum:]_@:]+:\\)?[ \t]*$"))
  1213. (setq level (org-reduced-level
  1214. (- (match-end 1) (match-beginning 1))))
  1215. (<= level maxlevel))
  1216. (setq hlc (if emph (or (cdr (assoc level hlchars)) "") "")
  1217. hdl (if (not link)
  1218. (match-string 2)
  1219. (org-make-link-string
  1220. (format "file:%s::%s"
  1221. (buffer-file-name)
  1222. (save-match-data
  1223. (org-make-org-heading-search-string
  1224. (match-string 2))))
  1225. (match-string 2)))
  1226. tsp (when timestamp
  1227. (setq props (org-entry-properties (point)))
  1228. (or (cdr (assoc "SCHEDULED" props))
  1229. (cdr (assoc "TIMESTAMP" props))
  1230. (cdr (assoc "DEADLINE" props))
  1231. (cdr (assoc "TIMESTAMP_IA" props)))))
  1232. (if (and (not multifile) (= level 1)) (push "|-" tbl))
  1233. (push (concat
  1234. "| " (int-to-string level) "|"
  1235. (if timestamp (concat tsp "|") "")
  1236. hlc hdl hlc " |"
  1237. (make-string (1- level) ?|)
  1238. hlc (org-minutes-to-hh:mm-string time) hlc
  1239. " |") tbl))))))
  1240. (setq tbl (nreverse tbl))
  1241. (if tostring
  1242. (if tbl (mapconcat 'identity tbl "\n") nil)
  1243. (goto-char ins)
  1244. (insert-before-markers
  1245. (or header
  1246. (concat
  1247. "Clock summary at ["
  1248. (substring
  1249. (format-time-string (cdr org-time-stamp-formats))
  1250. 1 -1)
  1251. "]"
  1252. (if block (concat ", for " range-text ".") "")
  1253. "\n\n"))
  1254. (if scope-is-list "|File" "")
  1255. "|L|" (if timestamp "Timestamp|" "") "Headline|Time|\n")
  1256. (setq total-time (or total-time org-clock-file-total-minutes))
  1257. (insert-before-markers
  1258. "|-\n|"
  1259. (if scope-is-list "|" "")
  1260. (if timestamp "|Timestamp|" "|")
  1261. "*Total time*| *"
  1262. (org-minutes-to-hh:mm-string (or total-time 0))
  1263. "*|\n|-\n")
  1264. (setq tbl (delq nil tbl))
  1265. (if (and (stringp (car tbl)) (> (length (car tbl)) 1)
  1266. (equal (substring (car tbl) 0 2) "|-"))
  1267. (pop tbl))
  1268. (insert-before-markers (mapconcat
  1269. 'identity (delq nil tbl)
  1270. (if scope-is-list "\n|-\n" "\n")))
  1271. (backward-delete-char 1)
  1272. (if (setq formula (plist-get params :formula))
  1273. (cond
  1274. ((eq formula '%)
  1275. (setq pcol (+ (if scope-is-list 1 0) maxlevel 3))
  1276. (insert
  1277. (format
  1278. "\n#+TBLFM: $%d='(org-clock-time%% @%d$%d $%d..$%d);%%.1f"
  1279. pcol
  1280. 2
  1281. (+ 3 (if scope-is-list 1 0))
  1282. (+ (if scope-is-list 1 0) 3)
  1283. (1- pcol)))
  1284. (setq recalc t))
  1285. ((stringp formula)
  1286. (insert "\n#+TBLFM: " formula)
  1287. (setq recalc t))
  1288. (t (error "invalid formula in clocktable")))
  1289. ;; Should we rescue an old formula?
  1290. (when (stringp (setq content (plist-get params :content)))
  1291. (when (string-match "^\\([ \t]*#\\+TBLFM:.*\\)" content)
  1292. (setq recalc t)
  1293. (insert "\n" (match-string 1 (plist-get params :content)))
  1294. (beginning-of-line 0))))
  1295. (goto-char ipos)
  1296. (skip-chars-forward "^|")
  1297. (org-table-align)
  1298. (when recalc
  1299. (if (eq formula '%)
  1300. (save-excursion (org-table-goto-column pcol nil 'force)
  1301. (insert "%")))
  1302. (org-table-recalculate 'all))
  1303. (when rm-file-column
  1304. (forward-char 1)
  1305. (org-table-delete-column)))))))
  1306. (defun org-clocktable-steps (params)
  1307. (let* ((p1 (copy-sequence params))
  1308. (ts (plist-get p1 :tstart))
  1309. (te (plist-get p1 :tend))
  1310. (step0 (plist-get p1 :step))
  1311. (step (cdr (assoc step0 '((day . 86400) (week . 604800)))))
  1312. (block (plist-get p1 :block))
  1313. cc range-text)
  1314. (when block
  1315. (setq cc (org-clock-special-range block nil t)
  1316. ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
  1317. (if ts (setq ts (time-to-seconds
  1318. (apply 'encode-time (org-parse-time-string ts)))))
  1319. (if te (setq te (time-to-seconds
  1320. (apply 'encode-time (org-parse-time-string te)))))
  1321. (setq p1 (plist-put p1 :header ""))
  1322. (setq p1 (plist-put p1 :step nil))
  1323. (setq p1 (plist-put p1 :block nil))
  1324. (while (< ts te)
  1325. (or (bolp) (insert "\n"))
  1326. (setq p1 (plist-put p1 :tstart (format-time-string
  1327. (org-time-stamp-format nil t)
  1328. (seconds-to-time ts))))
  1329. (setq p1 (plist-put p1 :tend (format-time-string
  1330. (org-time-stamp-format nil t)
  1331. (seconds-to-time (setq ts (+ ts step))))))
  1332. (insert "\n" (if (eq step0 'day) "Daily report: " "Weekly report starting on: ")
  1333. (plist-get p1 :tstart) "\n")
  1334. (org-dblock-write:clocktable p1)
  1335. (re-search-forward "#\\+END:")
  1336. (end-of-line 0))))
  1337. (defun org-clocktable-add-file (file table)
  1338. (if table
  1339. (let ((lines (org-split-string table "\n"))
  1340. (ff (file-name-nondirectory file)))
  1341. (mapconcat 'identity
  1342. (mapcar (lambda (x)
  1343. (if (string-match org-table-dataline-regexp x)
  1344. (concat "|" ff x)
  1345. x))
  1346. lines)
  1347. "\n"))))
  1348. (defun org-clock-time% (total &rest strings)
  1349. "Compute a time fraction in percent.
  1350. TOTAL s a time string like 10:21 specifying the total times.
  1351. STRINGS is a list of strings that should be checked for a time.
  1352. The first string that does have a time will be used.
  1353. This function is made for clock tables."
  1354. (let ((re "\\([0-9]+\\):\\([0-9]+\\)")
  1355. tot s)
  1356. (save-match-data
  1357. (catch 'exit
  1358. (if (not (string-match re total))
  1359. (throw 'exit 0.)
  1360. (setq tot (+ (string-to-number (match-string 2 total))
  1361. (* 60 (string-to-number (match-string 1 total)))))
  1362. (if (= tot 0.) (throw 'exit 0.)))
  1363. (while (setq s (pop strings))
  1364. (if (string-match "\\([0-9]+\\):\\([0-9]+\\)" s)
  1365. (throw 'exit
  1366. (/ (* 100.0 (+ (string-to-number (match-string 2 s))
  1367. (* 60 (string-to-number (match-string 1 s)))))
  1368. tot))))
  1369. 0))))
  1370. (defun org-clock-save ()
  1371. "Persist various clock-related data to disk.
  1372. The details of what will be saved are regulated by the variable
  1373. `org-clock-persist'."
  1374. (when org-clock-persist
  1375. (let (b)
  1376. (with-current-buffer (find-file (expand-file-name org-clock-persist-file))
  1377. (progn
  1378. (delete-region (point-min) (point-max))
  1379. ;;Store clock
  1380. (insert (format ";; org-persist.el - %s at %s\n"
  1381. system-name (format-time-string
  1382. (cdr org-time-stamp-formats))))
  1383. (if (and (setq b (marker-buffer org-clock-marker))
  1384. (setq b (or (buffer-base-buffer b) b))
  1385. (buffer-live-p b)
  1386. (buffer-file-name b)
  1387. (or (not org-clock-persist-query-save)
  1388. (y-or-n-p (concat "Save current clock ("
  1389. (substring-no-properties org-clock-heading)
  1390. ") "))))
  1391. (insert "(setq resume-clock '(\""
  1392. (buffer-file-name (marker-buffer org-clock-marker))
  1393. "\" . " (int-to-string (marker-position org-clock-marker))
  1394. "))\n"))
  1395. ;; Store clocked task history. Tasks are stored reversed to make
  1396. ;; reading simpler
  1397. (when (and org-clock-history (eq org-clock-persist t))
  1398. (insert
  1399. "(setq stored-clock-history '("
  1400. (mapconcat
  1401. (lambda (m)
  1402. (when (and (setq b (marker-buffer m))
  1403. (setq b (or (buffer-base-buffer b) b))
  1404. (buffer-live-p b)
  1405. (buffer-file-name b))
  1406. (concat "(\"" (buffer-file-name b)
  1407. "\" . " (int-to-string (marker-position m))
  1408. ")")))
  1409. (reverse org-clock-history) " ") "))\n"))
  1410. (save-buffer)
  1411. (kill-buffer (current-buffer)))))))
  1412. (defvar org-clock-loaded nil
  1413. "Was the clock file loaded?")
  1414. (defun org-clock-load ()
  1415. "Load clock-related data from disk, maybe resuming a stored clock."
  1416. (when (and org-clock-persist (not org-clock-loaded))
  1417. (let ((filename (expand-file-name org-clock-persist-file))
  1418. (org-clock-in-resume 'auto-restart)
  1419. resume-clock stored-clock-history)
  1420. (if (not (file-readable-p filename))
  1421. (message "Not restoring clock data; %s not found"
  1422. org-clock-persist-file)
  1423. (message "%s" "Restoring clock data")
  1424. (setq org-clock-loaded t)
  1425. (load-file filename)
  1426. ;; load history
  1427. (when stored-clock-history
  1428. (save-window-excursion
  1429. (mapc (lambda (task)
  1430. (if (file-exists-p (car task))
  1431. (org-clock-history-push (cdr task)
  1432. (find-file (car task)))))
  1433. stored-clock-history)))
  1434. ;; resume clock
  1435. (when (and resume-clock org-clock-persist
  1436. (file-exists-p (car resume-clock))
  1437. (or (not org-clock-persist-query-resume)
  1438. (y-or-n-p
  1439. (concat
  1440. "Resume clock ("
  1441. (with-current-buffer (find-file (car resume-clock))
  1442. (save-excursion
  1443. (goto-char (cdr resume-clock))
  1444. (org-back-to-heading t)
  1445. (and (looking-at org-complex-heading-regexp)
  1446. (match-string 4))))
  1447. ") "))))
  1448. (when (file-exists-p (car resume-clock))
  1449. (with-current-buffer (find-file (car resume-clock))
  1450. (goto-char (cdr resume-clock))
  1451. (org-clock-in)
  1452. (if (org-invisible-p)
  1453. (org-show-context)))))))))
  1454. ;;;###autoload
  1455. (defun org-clock-persistence-insinuate ()
  1456. "Set up hooks for clock persistence"
  1457. (add-hook 'org-mode-hook 'org-clock-load)
  1458. (add-hook 'kill-emacs-hook 'org-clock-save))
  1459. ;; Suggested bindings
  1460. (org-defkey org-mode-map "\C-c\C-x\C-e" 'org-clock-modify-effort-estimate)
  1461. (provide 'org-clock)
  1462. ;; arch-tag: 7b42c5d4-9b36-48be-97c0-66a869daed4c
  1463. ;;; org-clock.el ends here