1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-17 17:58:46 +00:00
emacs/lisp/org/org-clock.el
Carsten Dominik c8d0cf5ca0 2009-08-06 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-create-formula-image): Remove the -E option for
	dvipng.

	* org-exp.el (org-default-export-plist): Respect #+BIND.
	(org-export-confirm-letbind): New function.

	* org.el (org-paste-subtree): Test the kill ring entry if it is
	going to be used.
	(org-copy-subtree): Use `org-forward-same-level'.
	(org-forward-same-level): Respect the `invisibe-ok' arg for
	back-to-heading.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-table-map-tables): Make sure cursor is back at table
	beginning after funcall.

	* org-agenda.el (org-agenda-bulk-action): Make sure parents are
	handled before children, and do not error if an entry is not
	found, probably because it hase been remove when the parent was
	archived or refiled.

	* org.el (org-ido-completing-read): Accept straight lists for
	completion as well as alists.

	* org-timer.el (org-timer-cancel-timers): Renamed from
	`org-timer-cancel-timers'.

	* org.el (org-cycle-internal-local): Fix problem with finding next
	invisible line.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-list.el (org-list-send-list): Call
	`org-list-goto-true-beginning' instead of
	`org-list-find-true-beginning', which does not exist.

	* org-timer.el (org-timer-reset-timers): Use `mapc'.
	(org-timer-set-timer): Do not assign to heading.

	* org-id.el (org-id-open): Quote function name.

	* org-macs.el (org-unmodified): Turn off recording undo
	information while running inside the macro.

	* org-table.el (org-table-export): Also work in file-less
	buffers.

	* org.el (org-startup-indented): New option.
	(org-startup-options): Add new options indent and noindent.
	(org-unfontify-region): Remove line-prefix and wrap-prefix
	properties.
	(org-after-demote-entry-hook, org-after-promote-entry-hook): New
	hooks.
	(org-promote, org-demote): Run the new hooks.

	* org-table.el (org-table-align): Replace leading \n as well.

	* org-exp.el (org-export-push-to-kill-ring): Remove `line-prefix'
	and `line-wrap' text properties.

	* org-compat.el (org-kill-new): New function.

	* org-agenda.el (org-format-agenda-item): Remove `line-prefix' and
	`line-wrap' text properties.

	* org-indent.el: New file.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-provide-todo-statistics): Tweak docstring.

	* org-id.el (org-id-open): Honor `org-link-frame-setup'.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-as-org): Insert the "-source" string
	before the extension.

	* org.el (org-read-date): Make sure the calendar is in the current
	frame.
	(org-set-emph-re): Remove the ? from the post-match.
	(org-emphasis-regexp-components): Add backslash to the
	postmatch class.
	(org-set-font-lock-defaults): Write \n instead of \xa, and make it
	optional so that also lines at the end of the buffers will still
	be matched as headlines.

	* org-table.el (org-table-error-on-row-ref-crossing-hline):
	Variable made obsolete.
	(org-table-relative-ref-may-cross-hline): New option.
	(org-table-find-row-type): Honow the new option
	`org-table-relative-ref-may-cross-hline'.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-table.el (org-table-cut-region, org-table-copy-region): Work
	on single field if no active region.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-make-header): Only insert title
	if one is defined.

	* org.el (org-make-options-regexp): Allow empty values.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-cycle-internal-local): Improved version of finding
	next visible line.
	(org-cycle-hide-drawers): Only hide drawers if this is really
	necessary.
	(outline-end-of-subtree): Make `outline-end-of-subtree' use the
	org-version of this function in Org-mode.  We use advice to
	implement this change, so that future changes to this function in
	outline.el wil be handled properly.
	(org-forward-same-level, org-backward-same-level): New commands.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-remove-empty-overlays-at)
	(org-clean-visibility-after-subtree-move): New functons.
	(org-move-subtree-down): Simplify cleanup of display.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-mac-message.el (org-mac-message-get-links): Improve
	docstring.  Make argument SELECT-OR-FLAGGED optional, default to
	"s".  Fix the return value.
	(org-mac-message-insert-flagged): Simplify.

	* org.el (org-refile-get-location): Tamper with refile history o
	that history contains compete matches instead of the entered
	string.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-store-link): Never store a link to an inline task.

	* org-footnote.el (org-footnote-goto-local-insertion-point): Skip
	inline tasks when positioning footnotes.

	* org.el (org-refile): Remove the END line when archiving an
	inline task that does have an END line.

	* org-archive.el (org-archive-subtree): Remove the END line when
	archiving an inline task that does have an END line.

	* org-macs.el (org-with-limited-levels): New macro.
	(org-get-limited-outline-regexp): New function.

	* org-exp.el (org-export-format-source-code-or-example): Fix bug
	that did not enumerate first line.
	(org-export-mark-radio-links): Skip matches in links.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-activate-plain-links): Make single-match.
	(org-adapt-indentation): Fix docstring.

	* org-macs.el (org-unmodified): Turn of modification hooks while
	running this macro.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org.el (org-adapt-indentation): Slightly improve the docstring.
	(org-occur): Sends an error when the user inputs an empty string.
	(org-priority): Bugfix: the tag alignement should happen within
	save-excursion.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org.el (org-make-link-regexps): Don't exclude parentheses from
	`org-plain-link-re'
	(org-cycle-internal-local): When locally cycling, switch directly
	from CHILDREN to FOLDED if there is no subtree
	(org-cycle): Update the docstring to document the new behavior of
	`org-cycle-internal-local'.

2009-08-06  Nicolas Goaziou <n.goaziou@neuf.fr>  (tiny change)

	* org-clock.el (org-clock-in): Bugfix: recognize timestamps with
	an abbreviated format for days.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org-protocol.el (org-protocol-default-template-key): New
	option.

	* org.el (org-refile): Bugfix: save-excursion before reading the
	refile target, otherwise cursor moves might confuse `org-refile'.

	* org.el (org-toggle-heading): Bugfix: correctly convert list
	items before the first headline.

	* org.el (org-provide-todo-statistics): Allow a list of TODO
	keywords to compute statistics against headlines containing a
	keyword from this list.
	(org-update-parent-todo-statistics): Possibly use the new allowed
	value of `org-provide-todo-statistics'.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org-timer.el: Add autoload cookie.

	* org.el (org-occur-link-in-agenda-files): New function.

	* org-timer.el (org-timer-last-timer): New variable.

	* org-agenda.el (org-agenda-mode-map): New key for
	org-timer-set-timer called from the agenda.

	* org.el (org-mode-map): New key for org-timer-set-timer.

	* org-timer.el (org-timer-reset-timers)
	(org-timer-show-remaining-time, org-timer-set-timer): New
	functions.

	* org-clock.el (org-show-notification): Update the docstring.

	* org.el (org-provide-todo-statistics): Allow new value
	'all-headlines for this option, which includes entries with no
	TODO keywords in the todo statistics.
	(org-update-parent-todo-statistics): Possibly use the new
	'all-headline value from `org-provide-todo-statistics'.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org-clock.el (org-dblock-write:clocktable): Add a new option
	:timestamp which allows display of timestamps in clock reports.

	* org.el (org-mode-map): Define new key `C-c C-*': convert a plain
	list to a subtree, preserving the structure of the list.
	(org-set-emph-re): Make the last element optional in the regexp.
	This regexp now matches an emphasized string at the end of a line.

	* org-list.el (org-list-goto-true-beginning)
	(org-list-make-subtree, org-list-make-subtrees): New functions.

	* org.el (org-eval-in-calendar): Select the right frame.
	(org-save-frame-excursion): Remove this macro.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org-list.el (org-list-beginning-re): Bugfix: don't use * when
	trying to find the beginning of a list.

	* org-exp.el (org-get-file-contents): Use a new argument: markup.
	When present, tell org-get-file-contents not to protect org-like
	lines.

	* org-id.el (org-id-uuid-program): New option to set the name of
	the uuidgen program.
	(org-id-method): Use `org-id-uuid-program'.
	(org-id-new): Use `org-id-uuid-program'.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org-exp.el (org-export-number-lines): Allow whitespace in code
	references.  Allow the -r switch to remove the references in the
	source code even when the lines are not numbered: the labels can
	be explicit enough.

	* org.el (org-fontify-whole-heading-line): New option.
	(org-set-font-lock-defaults): Use the new option.

	* org-clock.el (org-show-notification-handler): New option.
	(org-show-notification): Use the new option.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org.el (org-eval-in-calendar): Fix a bug about calendar
	navigation when `calendar-setup' value is 'calendar-only.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org.el (orgstruct++-mode): Fix typo in docstring.
	(org-insert-link): Clean up: (or (...)) => (...)
	(org-insert-link): Use TAB for stored links completion.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org.el (org-get-refile-targets): Fix bug: don't ignore case when
	building the list of targets.

	* org-remember.el (org-remember-delete-empty-lines-at-end): New
	option.
	(org-remember-handler): Use the new option.

2009-08-06  James TD Smith  <ahktenzero@mohorovi.cc>

	* org.el (org-tags-sort-function): New option for sorting tags.
	(org-set-tags): Use the new option to sort tags.

	* org-plot.el (org-plot/gnuplot): Run with an idle timer to avoid
	premature deletion of the data when using org-plot in a script.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org-clock.el (org-clock-in-prepare-hook): New hook.
	(org-clock-in): Use this new hook.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org.el (org-special-ctrl-a/e): Explicitely bind the value
	'reversed for this option to the "true line boundary first"
	behavior.
	(org-tags-match-list-sublevels): Document the 'indented value for
	this variable.

	* org-latex.el (org-export-latex-first-lines): Fix problem with
	publishing the region.

	* org-exp.el (org-export-format-source-code-or-example): Fix
	bad line numbering when exporting examples in HTML.

2009-08-06  James TD Smith  <ahktenzero@mohorovi.cc>

	* org-colview.el (org-format-time-period): Formats a time in
	fractional days as days, hours, mins, seconds.
	(org-columns-display-here): Add special handling for SINCE and
	SINCE_IA to format for display.

	* org.el (org-time-since): Add a function to get the time since an
	org timestamp.
	(org-entry-properties): Add two new special properties: SINCE and
	SINCE_IA. These give the time since any active or inactive
	timestamp in an entry.
	(org-special-properties): Add SINCE, SINCE_IA.
	(org-tags-sort-function): Add custom declaration for tags
	sorting function.
	(org-set-tags): Sort tags if org-tags-sort-function is set

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-clock.el (org-clock-goto): Find hidden headlines as well.

	* org.el (org-narrow-to-subtree): Find hidden headlines as well.

	* org-plot.el (org-plot/add-options-to-plist): Add timeind
	option.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-publish.el (org-publish-remove-all-timestamps): New function.
	(org-publish-all): Remove all timestamp files if `org-publish-all'
	is called with a prefix argument.

	* org-list.el (org-indent-item): Fix typo.
	(org-item-indent-positions): Normalize ordered bullet.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-macs.el (org-set-local): Make a local variable, do not make
	the variable buffer-local!

	* org-latex.el (org-export-as-latex): Call `org-install-letbind'.

	* org-exp.el (org-infile-export-plist): Read BIND lines.
	(org-install-letbind): New function.
	(org-export-as-org, org-export-preprocess-string): Call
	`org-install-letbind'.

	* org-list.el (org-list-demote-modify-bullet): New option.
	(org-first-list-item-p): Save point.
	(org-fix-bullet-type): New optional argument FORCE-BULLET.
	(org-indent-item): Honor `org-list-demote-modify-bullet'.
	(org-item-indent-positions): Return bullet types along with
	indentation.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-show-entry): Hide drawers.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-footnote.el (org-footnote-auto-adjust): New option.
	(org-footnote-auto-adjust-maybe): New function.
	(org-footnote-new, org-footnote-delete): Call
	`org-footnote-auto-adjust-maybe'.

	* org.el (org-startup-options): Add new footnote-related
	keywords.

	* org-publish.el (org-publish-timestamp-filename): Additional
	arguments PUB-DIR and PUB-FUNC, which are included in the hash.
	(org-publish-needed-p): Additional arguments PUB-DIR PUB-FUNC
	TRUE-PUB-DIR.  Pass them through to
	`org-publish-timestamp-filename'.
	(org-publish-update-timestamp): Additional arguments PUB-DIR and
	PUB-FUNC, which are included in the hash.
	(org-publish-file): Delay timestamp test until the publishing
	function is known.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda-bulk-action): Add scheduling and
	setting the deadline.

	* org.el (org-read-date-final-answer): New variable.
	(org-read-date): Store the final answer string, including the date
	from the calendar, for reuse by agenda bulk commands.

	* org-publish.el (org-publish-attachment): Fix publishing of
	attachments.

	* org-latex.el (org-export-latex-quotation-marks): Fix export of
	quotation makrs in parenthesis.
	(org-remove-initial-hash): New function.
	(org-export-latex-preprocess): Fix bug with infinite loop if
	environment is not properly closed.

	* org-table.el (org-table-get-remote-range): Find #+TBLNAME also
	when indented.

	* org.el (org-fontify-meta-lines-and-blocks): Make #+TBLNAME
	highlight also when indented.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-footnote.el (org-footnote-renumber-fn:N): New command.
	(org-footnote-action): Offer renumbering.

	* org.el (org-cycle): Honor the `integrate' value of
	org-cycle-include-plain-lists'.

	* org-list.el (org-cycle-include-plain-lists): New allowed value
	`internal'.  Improve the docstring.

	* org.el (org-set-autofill-regexps): Improve the paragraph-start
	regexp to work better with LaTeX commands.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-inline-image-extensions): Add ps
	and eps extensions.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-write-agenda): Make sure org-icalendar is
	loaded.

	* org.el (org-map-entries): No longer force
	`org-tags-match-list-sublevels' to t during a todo-only tags
	search.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-low-levels): Allow user-defined
	environment.
	(org-export-latex-subcontent): Handle user-defined environment.

	* org-agenda.el (org-agenda-view-mode-dispatch): Add more keys to
	the View dispatcher.

	* org.el (org-hide-block-toggle): Use `org-make-overlay' instead of
	`make-overlay'.

	* org-latex.el (org-export-as-pdf): Protect match data during call
	to shell-quote-argument.

	* org-agenda.el (org-agenda-mode-map): Modify bulk action keys.
	(org-agenda-view-mode-dispatch): New function.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda-mode): Reset list of marks.
	(org-agenda-mode-map): Define new keys for refile and bulk action.
	(org-agenda-menu): Add menu itesm for refile and bulk action.
	(org-agenda-refile): New function.
	(org-agenda-set-tags): Optional arguments TAG and ONOFF.
	(org-agenda-marked-entries): New variable.
	(org-agenda-bulk-select, org-agenda-remove-bulk-action-overlays)
	(org-agenda-remove-all-bulk-action-marks)
	(org-agenda-bulk-action): New functions/commands.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-get-file-contents): Protect org-like lines in
	included files.
	(org-export-format-source-code-or-example): Remove newlines.

	* org-latex.el (org-export-latex-links): Check for no-description
	marking.

	* org-exp.el (org-export-preprocess-apply-macros): Switch macro
	argument separator back to comma.
	(org-export-normalize-links): Mark links without description.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-infile-export-plist): Fix bug in macro
	processing.

	* org-agenda.el (org-agenda-clock-out): Update line after clocking
	out.
	(org-agenda-highlight-todo): Fix bug with highlighting.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-set-font-lock-defaults): Adapt formatting to capture
	new alignment strings.

	* org-table.el (orgtbl-self-insert-command): Add yas/expand to
	command list.
	(org-table-align): Check for forced align type.

	* org.el (org-self-insert-command): Add yas/expand to command
	list.

	* org-clock.el (org-clock-in-hook): New hook.
	(org-clock-in): Run `org-clock-in-hook.
	(org-clock-out-hook): New hook.
	(org-clock-out): Run `org-clock-out-hook.
	(org-clock-cancel-hook): New hook.
	(org-clock-cancel): Run `org-clock-cancel-hook.
	(org-clock-goto-hook): New hook.
	(org-clock-goto): Run `org-clock-goto-hook.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-store-link): Better default description for link to
	Org-mode headline.

	* org-exp.el (org-export-generic): Autoload the generic exporter
	function.
	(org-export): Implement the `g' key for the generic exporter.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-table.el (orgtbl-setup): Add a binding for `S-iso-lefttab',
	and for zbacktab'.

	* org-exp.el (org-infile-export-plist): Get macros also from
	#+SETUPFILE.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-colview.el (org-columns-capture-view): Protect vertical bars
	in column values.
	(org-columns-capture-view): Exclude comment and archived trees.

	* org-colview-xemacs.el (org-columns-capture-view): Protect
	vertical bars in column values.
	(org-columns-capture-view): Exclude comment and archived trees.

	* org.el (org-quote-vert): New function.

	* org-latex.el (org-export-latex-verbatim-wrap): New option.

	* org-exp.el (org-export-format-source-code-or-example): Use
	`org-export-latex-verbatim-wrap'.

	* org.el (org-clone-subtree-with-time-shift): Also shift inactive
	time stamps.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp-blocks.el: New file.

	* org-remember.el (org-remember-templates): Allow the headline
	element to be a function.
	(org-remember-apply-template): If the headline is a function, call
	it to get the true function.

	* org-clock.el (org-clock-menu): New function.
	(org-clock-update-mode-line): Update help string.
	(org-clock-modify-effort-estimate): New function.
	(org-clock-mark-default-task): New function.

	* org.el (org-hh:mm-string-to-minutes): Also take just a number of
	minutes as input.
	(org-org-menu): Add new clocking stuff.
	(org-clock-is-active): New function.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-open-non-existing-files): Improve docstring.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-icalendar.el (org-icalendar-include-bbdb-anniversaries): New
	option.
	(org-export-icalendar): Call `org-bbdb-anniv-export-ical'.

	* org-bbdb.el (org-bbdb-anniv-export-ical): New function.

	* org-list.el (org-get-checkbox-statistics-face): Use the new
	faces.

	* org-faces.el (org-checkbox-statistics-todo)
	(org-checkbox-statistics-done): New faces.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-use-verb): New variable.
	(org-export-latex-emph-format): Prefer \texttt over \verb when
	org-export-latex-use-verb is set.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-remember.el (org-remember-handler): Abort remember if the
	buffer is empty.

	* org-exp.el (org-export-format-source-code-or-example): Run
	`org-src-mode-hook'.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-indent-line-function): Fix indentation of +#end lines.

2009-08-06  Tassilo Horn  <tassilo@member.fsf.org>

	* org-gnus.el (org-gnus-store-link): Require message.el in
	org-gnus-store-link.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-src.el: New file, split out of org.el

	* org-macs.el (org-replace-match-keep-properties): New function.

	* org-exp.el (org-export-mark-blockquote-verse-center): Better
	preprocessing of center and quote and verse blocks.

	* org-list.el (org-list-end): Respect the stored "original"
	indentation when determining the end of the list.

	* org-exp.el (org-export-replace-src-segments-and-examples):
	Remember indentation correctly.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-clock.el (org-clock-update-mode-line): Apply face
	org-mode-line-clock.

	* org-faces.el (org-mode-line-clock): New face.

2009-08-06  Tassilo Horn  <tassilo@member.fsf.org>

	* org-gnus.el (org-gnus-store-link): Fix bug where
	`org-gnus-store-link' used wrong subject when called in an article
	buffer.  Patch provided by fengli AT gmail DOT com.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-format-source-code-or-example): Remember
	the original indentation of source code snippets and examples.

	* org-latex.el (org-export-as-latex): Relocate the table of
	contents.

	* org.el (org-ctrl-c-ctrl-c): Update clock lines.

	* org-agenda.el (org-run-agenda-series): Scope global options also
	when creating the agenda buffer.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-adapt-indentation): Improve documentation.
	(org-insert-property-drawer): Respect org-adapt-indentation when
	inserting the drawer.
	(org-remove-flyspell-overlays-in): New function.
	(org-do-emphasis-faces, org-activate-plain-links)
	(org-activate-code, org-fontify-meta-lines-and-blocks)
	(org-activate-angle-links, org-activate-footnote-links)
	(org-activate-bracket-links, org-activate-dates)
	(org-activate-target-links, org-activate-tags): Remove flyspell
	overlays.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-edit-src-save): New function.

	* org-clock.el (org-clock-out-switch-to-state): New option.
	(org-clock-out): Honor `org-clock-out-switch-to-state'.

	* org-compat.el (org-compatible-face): Improve macro.

	* org.el (org-global-properties-fixed): Add default for
	CLOCK_MODELINE_TOTAL.

	* org-clock.el (org-clock-sum): Accept lists and strigs as tstart
	andd tend.
	(org-clock-sum-current-item): Optional argument TSTART, pass it to
	org-clock-sum.
	(org-clock-get-sum-start): New function.

	* org.el (org-startup-options): New keywords blockhide and
	blockshow.
	(org-mode): Add new invisibility spec.
	(org-set-startup-visibility): Hide block on startup if so
	desired.
	(org-hide-block-startup): New option.
	(org-block-regexp): New constant.
	(org-hide-block-overlays): New variable.
	(org-block-map, org-hide-block-toggle-all, org-hide-block-all)
	(org-show-block-all, org-hide-block-toggle-maybe)
	(org-hide-block-toggle): New functions.
	(org-edit-src-exit): Do not quote lines starting with # and no +
	behind it.
	(org-auto-repeat-maybe): Add LAST_REPEAT properter for a repeating
	entry.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-buffer-property-keys): Add Effort property for
	completion.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-clock.el (org-clock-sum-current-item): Fix positioning bug
	when retrieving total clocked time in the subtree.

	* org.el (org-quoting-blocks): New variable.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-table.el (org-table-store-formulas)
	(org-table-get-stored-formulas, org-table-fix-formulas)
	(org-table-edit-formulas, orgtbl-ctrl-c-ctrl-c)
	(orgtbl-gather-send-defs): Allow indented #+TBLFM line.

	* org.el (org-fontify-meta-lines, org-ctrl-c-ctrl-c): Allow
	indented #+TBLFM line.

	* org-footnote.el (org-footnote-goto-local-insertion-point): Allow
	indented #+TBLFM line.

	* org-colview.el (org-dblock-write:columnview): Allow indented
	#+TBLFM line.

	* org-colview-xemacs.el (org-dblock-write:columnview): Allow
	indented #+TBLFM line.

	* org-clock.el (org-dblock-write:clocktable): Allow indented
	#+TBLFM line.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-format-source-code-or-example): Make
	editing indented blocks work correctly.

	* org.el (org-edit-src-nindent): New variable.
	(org-edit-src-code, org-edit-fixed-width-region)
	(org-edit-src-find-region-and-lang, org-edit-src-exit): Make
	editing indented blocks work correctly.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-replace-src-segments-and-examples): FInd
	indented blocks.
	(org-export-format-source-code-or-example): Fix indentation of
	blocks.
	(org-export-remove-indentation): New function.
	(org-export-select-backend-specific-text): Allow backend-specific
	code to be indented.
	(org-export-mark-blockquote-verse-center): Allow markers to be
	indented.

	* org.el (org-fontify-meta-lines): New function.
	(org-set-font-lock-defaults): Call the new fontification
	function.

	* org-faces.el (org-meta-line): New face
	(org-block):  New face.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-treat-insert-todo-heading-as-state-change)
	(org-treat-S-cursor-todo-selection-as-state-change): New
	variables.
	(org-insert-todo-heading): Honor
	`org-treat-insert-todo-heading-as-state-change'.
	(org-shiftright, org-shiftleft): Honor
	`org-treat-S-cursor-todo-selection-as-state-change'.
	(org-inhibit-logging): New variable.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-remove-subtree-entries-from-agenda): Reduce
	range for marker position checking.

	* org-latex.el (org-export-latex-first-lines): Fix bug when
	exporting a region.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-push-to-kill-ring): Protect using
	x-set-selection, because that does not always work.

	* org-agenda.el (org-agenda-list): Apply the new face
	`org-agenda-date-today'.

	* org-faces.el (org-agenda-date-today): New face.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda-to-appt): Turn off restriction when
	creating appointments.

	* org-latex.el (org-export-latex-low-levels): Fix customization
	type.

	* org.el (org-priority, org-shiftup, org-shiftdown): Disable
	priority commands.

	* org-agenda.el (org-agenda-priority): Disable priority commands.

	* org.el (org-enable-priority-commands): New option.

	* org-colview-xemacs.el (org-columns-compute)
	(org-columns-number-to-string): Fix problems with empty fields.

	* org-colview.el (org-columns-compute)
	(org-columns-number-to-string): Fix problems with empty fields.

	* org-exp.el (org-export-push-to-kill-ring): New function.
	(org-export-copy-to-kill-ring): New option.

	* org-latex.el (org-export-as-latex): Call
	`org-export-push-to-kill-ring'.

	* org-exp.el (org-export-show-temporary-export-buffer): New
	option.

	* org-latex.el (org-export-as-latex): Use
	`org-export-show-temporary-export-buffer'.

	* org-exp.el (org-export-show-temporary-export-buffer): New
	option.
	(org-export-push-to-kill-ring): New function.

	* org-colview.el (org-columns-compile-map): New variable.
	(org-columns-new, org-columns-compute)
	(org-columns-number-to-string, org-columns-uncompile-format)
	(org-columns-compile-format): Implement new operators.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-plist-vars): Add :xml-declaration.

	* org-list.el (org-update-checkbox-count): Make property
	dependent.

	* org.el (org-hierarchical-todo-statistics): New option.
	(org-update-parent-todo-statistics): Modified to handle recursive
	statistics.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-publish.el (org-publish): Make this function behave
	correctly in interactive use when called with a prefix argument.

	* org.el (org-todo-statistics-hook): New hook.
	(org-update-parent-todo-statistics): Use new hook.
	(org-log-into-drawer): New function.
	(org-add-log-setup): Use the new `org-log-into-drawer' function to
	determine if we should be logging into a drawer.
	(org-log-into-drawer): Update docstring.
	(org-default-properties): Add LOG_INTO_DRAWER as a property.

	* org-list.el (org-checkbox-statistics-hook): New hook.
	(org-update-checkbox-count-maybe): Use new hook.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-edit-src-code, org-edit-fixed-width-region): Use a
	better bufer-generating mechanism.
	(org-edit-src-find-buffer): New function.

	* org-icalendar.el (org-print-icalendar-entries): Don't check for
	archive tag, this is already done by `org-agenda-skip'.
	data while constructing lost of tags.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-preprocess-apply-macros): Use semicolon
	as argument separator in macros.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-after-sorting-entries-or-items-hook): New hook.
	(org-sort-entries-or-items): Run the new hook.
	(org-after-refile-insert-hook): New hook.
	(org-refile): Run `org-after-refile-insert-hook'.

	* org-agenda.el (org-agenda-get-progress): Never take time of day
	from headline when displaying progress.

	* org-latex.el (org-export-latex-complex-heading-re): New variable.
	(org-export-as-latex): Force the correct regexp in the
	preprocessor buffer.
	(org-export-latex-set-initial-vars): Set
	`org-export-latex-complex-heading-re'.

	* org-agenda.el (org-agenda-start-with-log-mode): New option.
	(org-agenda-mode): Use `org-agenda-start-with-log-mode'.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-tables-centered): New option.
	(org-export-latex-tables): Use `org-export-latex-tables-centered'.

	* org-exp.el (org-export-as-org): New command.
	(org-export-as-org): New command.

	* org-publish.el (org-publish-org-to-org): New function.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-yank): Just call `org-yank-generic'.
	(org-yank-generic): New function, containing the formaer
	functionality of `org-yank'.

	* org-latex.el (org-export-latex-not-done-keywords)
	(org-export-latex-done-keywords): New variables.
	(org-export-latex-todo-keyword-markup): New option.
	(org-export-latex-set-initial-vars): Remember the TODO keywords.
	(org-export-latex-keywords-maybe): Apply the TODO markup.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-infile-export-plist): Add more default macros.
	(org-export-preprocess-apply-macros): Process macro arguments.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-icalendar.el (org-icalendar-include-todo): New allowedvalue
	`unblocked'.
	(org-print-icalendar-entries): Respect the new value of
	`org-icalendar-include-todo'.

	* org.el (org-link-try-special-completion)
	(org-file-complete-link): New functions.
	(org-insert-link): Add special completion support for some link
	types.

	* org-bbdb.el (org-bbdb-complete-link): New function.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-list.el (org-update-checkbox-count): Allow recursive
	statistics.
	(org-hierarchical-checkbox-statistics): New option.

	* org.el (org-cycle): Remove erraneous space character.

	* org-icalendar.el (org-icalendar-timezone): Initialize from
	environment.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-autoload): Fix autoloading of ascii export
	functions.
	(org-modules): Add org-special-blocks.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-icalendar.el (org-start-icalendar-file): Use the new option.
	(org-ical-timezone): New option.

	* org-exp.el (org-export-get-coderef-format): Use the description
	is present.

	* org.el (org-sort-entries-or-items): Improve docstring, and make
	better implementation for time sorting.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-edit-src-persistent-message): New option.
	(org-edit-src-code, org-edit-fixed-width-region): Use the new
	option.

	* org-clock.el (org-clock-insert-selection-line): Fix prefious
	patch.

	* org.el (org-edit-src-code, org-edit-fixed-width-region): Use
	separate buffer instead of indirect buffer to edit source code.
	(org-edit-src-exit): Make this function work with the new setup.

	* org-clock.el (org-clock-insert-selection-line): Make sure tasks
	are properly fontified before shown in the selection menu.

	* org.el (org-fontify-like-in-org-mode): New function.

	* org-latex.el (org-export-latex-links): Use the property list to
	retrieve the default image attributes.

	* org-exp.el (org-export-plist-vars): Add a new option.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export, org-export-visible): Support ASCII
	export to buffer
	(org-export-normalize-links): Do not protect the description if it
	is explicitly given.

	* org-list.el (org-reset-checkbox-state-subtree): Moved here from
	org-checklist.el.
	(org-reset-checkbox-state-subtree): Call
	`org-reset-checkbox-state-subtree'.

	* org-remember.el (org-select-remember-template): For the
	selection of a valid template.

	* org-latex.el (org-export-region-as-latex): Supply the
	force-no-subtree argument.
	(org-export-as-latex): Provide better limits when exporting the
	first line.  When exporting to string, we still want the first
	lines.
	(org-export-latex-first-lines): New argument END, to force the end
	of the region.
	(org-export-region-as-latex): Use the property list.
	(org-export-as-latex):

	* org-colview-xemacs.el (org-columns-remove-overlays)
	(org-columns): Fix call to `local-variable-p'.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-after-blockquotes-hook): New hook.
	(org-export-latex-preprocess): Run the new hook.

	* org-exp.el (org-export-preprocess-after-blockquote-hook): New hook.
	(org-export-preprocess-string): Run the new hook.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-macs.el (org-check-external-command): New defsubst.

	* org.el (org-mode-map): New key for reload.
	(org-format-latex): Better error message when external programs
	are not available.

	* org-agenda.el (org-agenda-mode-map): Bind `org-reload'.

	* org.el (org-sort-entries-or-items): Explicit sorting function
	for priorities, needed for XEmacs compatibility.

	* org-remember.el (org-remember-apply-template): Improve auto-save
	behavior.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-preprocess): Also protect
	environments ending in a star.

	* org-list.el (org-at-item-p): Fix regular expression.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-end-of-subtree): Improve speed.

	* org-agenda.el (org-agenda-get-timestamps)
	(org-agenda-get-progress, org-agenda-get-deadlines)
	(org-agenda-get-scheduled, org-agenda-get-blocks): Optimizations,
	in particular, wait as long as possible to collect the tags.
	(org-stuck-projects): Improve docstring.

	* org.el (org-store-link): No errors when getting custom id before
	first headline.
	(org-get-tags-at): Use `org-up-heading-safe' when getting tags.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-prepare-agenda-buffers): Catch a throw to nextfile.

	* org-protocol.el: Remove dependency on url.el.
	(org-protocol-unhex-compound, org-protocol-open-source): Remove
	dependency on url.el.

	* org-latex.el (org-export-as-pdf): Use
	`org-latex-to-pdf-process'.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-latex-to-pdf-process): New option.

	* org-agenda.el (org-agenda-skip-additional-timestamps-same-entry):
	New option.
	(org-agenda-get-timestamps): Honor
	`org-agenda-skip-additional-timestamps-same-entry'.

	* org-clock.el (org-clock-goto-may-find-recent-task): New option.
	(org-clock-goto): Find recent task only if
	`org-clock-goto-may-find-recent-task' allows it.

	* org-exp.el (org-export-remove-or-extract-drawers): Handle empty
	drawers, and drawers that are missing the :END: line.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-clock.el (org-clock-goto): Go to recently clocked task if no
	clock is running.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-update-parent-todo-statistics): Check for
	STATISTICS_FROM property.

	* org-list.el (org-update-checkbox-count): Check for
	STATISTICS_FROM property.

	* org.el (org-tab-first-hook)
	(org-tab-after-check-for-table-hook)
	(org-tab-after-check-for-cycling-hook): New hooks.
	(org-cycle-internal-global, org-cycle-internal-local): New
	functions, split out from `org-cycle'.
	(org-cycle): Call the new hooks.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-preprocess-string): Reset the list of
	preferred targets for each run of the preprocessor.

	* org.el (org-refile-target-verify-function): Improve
	documentation.
	(org-get-refile-targets): Respect point being moved by the
	verification function.

	* org-latex.el (org-export-latex-timestamp-keyword-markup): New
	option.
	(org-export-latex-keywords): Use new option.

	* org.el (org-rear-nonsticky-at): New defsubst.
	(org-activate-plain-links, org-activate-angle-links)
	(org-activate-footnote-links, org-activate-bracket-links)
	(org-activate-dates, org-activate-target-links)
	(org-activate-tags): Place the rear-nonsticky properties at the
	correct location.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-protocol.el (server-edit): Declare `server-edit'.
	(org-protocol-unhex-string, org-protocol-unhex-compound): New
	functions.
	(org-protocol-check-filename-for-protocol): Call `server-edit'.

	* org.el (org-default-properties): New default properteis for
	completion.

	* org-exp.el (org-export-add-subtree-options): Add new properties
	for subtree export.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-id.el (org-id-get-with-outline-path-completion): Turn off
	org-refile-target-verify-function for the duration of the command.

	* org.el (org-link-to-org-use-id): New possible value
	`create-if-interactive-and-no-custom-id'.
	(org-store-link): Use custom IDs.
	(org-link-search): Find custom ID properties from #link.
	(org-default-properties): Add CUSTOM_ID for property completion.
	(org-refile-target-verify-function): New option.
	(org-goto): Turn off org-refile-target-verify-function
	for the duration of the command.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-preferred-target-alist): New variable.
	(org-export-define-heading-targets): Find the new CUSTOM_ID
	property.
	(org-export-target-internal-links): Target the custom ids when
	possible.

	* org-latex.el (org-export-latex-preprocess): Better regexp for
	matching latex macros with arguments.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-remember.el (org-remember-handler): Allow filing to non-org
	files.

2009-08-06  Magnus Henoch <magnus.henoch@gmail.com>

	* org-table.el (org-table-fix-formulas): Do not change references
	to remote tables.
	(org-table-get-remote-range): Convert standard coordinates to RC
	format.

	* org-latex.el (org-export-latex-keywords): Fix regexp bug.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-compat.el (org-sha1-string): Function removed.

	* org.el (org-refile-allow-creating-parent-nodes): New option.
	(org-refile-get-location): New argument NEW-NODES.
	(org-refile): Call `org-refile-get-location' with the new
	argument.
	(org-refile-get-location): Arrange for adding a new child.
	(org-refile-new-child): New function.

	* org-clock.el: Fix a number of docstrings.
	(org-clock-find-position): New argument
	FIND-UNCLOSED to make the function find an unclosed clock in the
	entry.
	(org-clock-in): Call `org-clock-find-position' with the new
	argument if we might be resuming a clock.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-display-custom-times): New variable.
	(org-export-latex-timestamp-markup): New option.
	(org-export-latex-set-initial-vars): Remember the local value of
	`org-display-custom-times'.
	(org-export-latex-content): Process time stamps.
	(org-export-latex-time-stamps): New function.

	* org-macs.el (org-maybe-intangible): Add intangible property
	again to invisible text.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-default-export-plist): Handle undefined
	variables.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-sort-entries-or-items): Match TODO keywrds
	case-sensitively, when sorting.
	(org-priority): Do not match TODO keywords with wrong case.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-todo): Honor the NOBLOCKING property.

	* org-agenda.el (org-agenda-dim-blocked-tasks): Honor the
	NOBLOCKING property.

	* org.el (org-scan-tags): Fix bug in tag scanner

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-modules): Mark obsolete packages.

	* org-html.el: New file, split out from org-exp.el.

	* org-icalendar.el: New file, split out from org-exp.el.

	* org-xoxo.el: New file, split out from org-exp.el.

	* org-ascii.el: New file, split out from org-exp.el.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-compat.el (org-find-library-name): New function.

	* org.el (org-pre-cycle-hook): New hook.
	(org-cycle): Call the new hook in appropriate places.
	(org-reload): Only reload files that have been loaded before.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-set-font-lock-defaults): Enforxe space or line end
	after todo keyword.
	(org-todo): When changing TODO state, do matching
	case-sensitively.
	(org-map-continue-from): New variable.
	(org-scan-tags): Respect values in `org-map-continue-from'.
	(org-reload): Make XEmacs compatible.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-protocol.el (org-protocol-flatten-greedy): New function.
	(org-protocol-flatten): New function.

	* org.el (org-open-link-from-string): Pass reference buffer to
	`org-open-at-point'.
	(org-open-at-point): New optional argument `reference-buffer'.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-scan-tags): Make tag scan find headline in first
	line, 2nd attempt.
	(org-get-refile-targets): Add the naked file name.
	(org-refile): Store as top-level entry when only file name was
	given.

	* org-agenda.el (org-agenda-get-progress): Fix regexp bug.

	* org.el (org-block-todo-from-children-or-siblings-or-parent):
	Renamed from org-block-todo-from-children-or-siblings, and
	enhanced to look for the parent's status as well.

	* org-agenda.el (org-agenda-log-mode-add-notes): New option.
	(org-agenda-get-progress): Add first notes line to log entry if so
	desired.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda-cleanup-fancy-diary-hook): New hook.
	(org-agenda-cleanup-fancy-diary): Call the new hook.

	* org-remember.el (org-remember-apply-template): Take the default
	for the annotation from the :annotation property.

	* org-mac-message.el (org-mac-message-get-link): Remove the
	quotes.
	(org-mac-message-get-link): Return the result.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-refile-get-location): Add file name only if not
	already included in outline path.

	* org-faces.el (org-n-level-faces): Fix customization type from
	number to integer.

	* org-exp.el (org-export-headline-levels): Fix customization type
	from number to integer.

	* org-agenda.el (org-agenda-confirm-kill)
	(org-agenda-custom-commands-local-options)
	(org-timeline-show-empty-dates, org-agenda-ndays)
	(org-agenda-start-on-weekday, org-scheduled-past-days): Fix
	customization type from number to integer.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-protocol.el: Declare some functions.

	* org-agenda.el (org-agenda-compare-effort): Honor
	`org-sort-agenda-noeffort-is-high'.
	(org-agenda-filter-by-tag, org-agenda-filter-make-matcher)
	(org-agenda-compare-effort): Implement the "?" operator for
	finding entries without effort setting.

	* org.el (org-extract-attributes-from-string): New function.

	* org-exp.el (org-export-splice-attributes): New function.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-mouse.el: XEmacs compatibility fixes

	* org.el (org-modules): Add org-inlinetasks.el
	(org-cycle): Implement limiting level on cycling.
	(org-move-subtree-down): Fix bug with swapping subtrees at end of
	buffer.

	* org-inlinetask.el: New file.

	* org-protocol.el: New file.

	* org.el (org-emphasis-regexp-components): Allow braces in
	emphasis pre and post match.

	* org-footnote.el (org-footnote-normalize): When only dorting, do
	not insert inline notes at the end.

	* org.el (org-require-autoloaded-modules): Add org-docbook.el.

	* org-docbook.el: New file.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-reftex-citation): New command.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda-cmp-user-defined): New option.
	(org-sorting-choice, org-agenda-sorting-strategy): Add the new
	sorting options.
	(org-entries-lessp): Apply the new sorting option.

	* org.el (org-block-todo-from-children-or-siblings): Fix bug in
	blocker code, when an older sibling has children.

	* org-mac-message.el (org-mac-message-get-link): Improve getting
	links from multiple selected messages.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-remember.el (org-remember-finalize): Do not set buffer file
	name to nil.
	(org-remember-handler): Mark buffer as unmodified.
	(org-remember-handler): Delete backup file and show message about
	remaining backup files.
	(org-remember-auto-remove-backup-files): New option.

	* org.el (org-store-link): Use buffer name as link description in
	w3-mode buffers.
	(org-ido-switchb): Fix argument bug for completion.

	* org-remember.el (org-remember-apply-template): Set local
	variable `auto-save-visited-file-name' instead of global one.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda-get-todos): Fix bug with match-data.
	(org-agenda-get-todos): Mark file tags as inherited.
	(org-agenda-list): Always search diary lines for a time.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-feed.el: New file.

	* org-exp.el (org-export-as-html): Close local lists depending on
	indentation, also when starting a table.

	* org-remember.el (org-remember-backup-directory)
	(org-remember-backup-name): New internal variable.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-clock.el (org-clock-out-if-current): Make buffer detection
	work in indirect buffers as well.

	* org.el (org-emphasis-regexp-components): Add the exxclamation
	mark to the post-emphasis characters.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-read-date-minibiffer-septup-hook): New hook.
	(org-read-date): Run the new hook.

	* org-mac-message.el (org-mac-flagged-mail): New group.
	(org-mac-mail-account): New variable.
	(org-mac-create-flagged-mail, org-mac-insert-flagged-mail): New
	commands.

	* org-remember.el (org-remember-backup-directory): New variable.
	(org-remember-apply-template): Write file to backup directory.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-mouse.el (org-mouse-todo-menu): New function.
	(org-mouse-todo-keywords): Function removed.
	(org-mouse-context-menu): Use `org-mouse-todo-menu'.

	* org-table.el (org-table-beginning-of-field)
	(org-table-end-of-field): New commands
	(org-table-previous-field, org-table-beginning-of-field): Better
	error messages.
	(orgtbl-setup): Include `M-a' and `M-e'.

	* org.el (org-backward-sentence, org-forward-sentence): New
	commands.

	* org-colview.el (org-colview-initial-truncate-line-value): New
	variable.
	(org-columns-remove-overlays): Restore the value of `truncate-lines'.
	(org-columns): Remember the value of `truncate-lines'.

	* org-colview-xemacs.el (org-colview-initial-truncate-line-value):
	New variable.
	(org-columns-remove-overlays): Restore the value of
	`truncate-lines'.
	(org-columns): Remember the value of `truncate-lines'.

	* org.el (org-columns-skip-arrchived-trees): New option.

	* org-agenda.el (org-agenda-export-html-style): Define color for
	org-agenda-done face.
	(org-search-view, org-agenda-get-todos, org-agenda-get-progress)
	(org-agenda-get-deadlines, org-agenda-get-scheduled): Use new face.

	* org.el (org-scan-tags): Use the new face.

	* org-faces.el (org-agenda-done): New face.

	* org.el (org-scan-tags): Test the value org
	`org-tags-match-list-sublevels'.
	(org-tags-match-list-sublevels): New allowed value: indented.

	* org-latex.el (org-export-latex-make-header): Apply macros
	in header.

	* org-exp.el (org-export-apply-macros-in-string): New function.

	* org-latex.el (org-export-latex-list-parameters): Fix bug
	with the definition of a checked box.

	* org-clock.el (org-clock-find-position): Fix drawer indentations.

	* org-latex.el (org-export-latex-low-levels): More options
	for how to process lower levels in LaTeX.
	(org-export-latex-subcontent): Better treatment for lists as a
	means of publishing lower levels.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-set-font-lock-defaults): Use new checkbox face.

	* org-faces.el (org-checkbox): New face.

	* org-exp.el (org-export-html-preprocess): Only create LaTeX
	fragement images if there is an export file.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-stuck-projects): Document that the subtree of
	projects that are not stuck will now be searched for stuck
	sub-projects.
	(org-agenda-skip-entry-when-regexp-matches)
	(org-agenda-skip-entry-when-regexp-matches-in-subtree): New functions.
	(org-agenda-list-stuck-projects): Use
	`org-agenda-skip-entry-when-regexp-matches-in-subtree'.

	* org-latex.el (org-export-latex-preprocess): Improve
	export of verses.

	* org-exp.el (org-export-as-html): Implement centering as a div
	rather than a paragraph.  Do a better job with line-end in verse
	environments.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-open-at-point): Fix tags searches by mouse click.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-preprocess): Implement the
	centering markup.

	* org-exp.el (org-export-mark-blockquote-verse-center): Renamed
	from `org-export-mark-blockquote-and-verse'.
	(org-export-as-html): Implement the centering markup.

	* org-latex.el (org-export-latex-tables): Fix vertical
	lines in tables.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-read-date-history): New variable.
	(org-read-date): Use new history variable.
	(org-toggle-heading): Fix bug when used before first headline.
	(org-store-log-note): Remove drawer if empty while note is
	aborted.
	(org-remove-empty-drawer-at): New function.
	(org-check-after-date): New command.
	(org-sparse-tree): New sparse tree command "a".

	* org-exp.el (org-export-as-ascii): Improve export of plain lists.

2009-08-06  Bastien Guerry  <bzg@altern.org>

	* org.el (org-toggle-fixed-width-section): Bug fix: insert a
	column and a space, not only a column.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-latex-emphasis-alist): Better
	defaults for verbose emphasis.
	(org-export-latex-emph-format): New function.
	(org-export-latex-fontify): Call `org-export-latex-emph-format'.

	* org-agenda.el (org-agenda-menu): Add new commands to menu.
	(org-agenda-do-date-later, org-agenda-do-date-earlier)
	(org-agenda-date-later-minutes, org-agenda-date-earlier-minutes)
	(org-agenda-date-later-hours, org-agenda-date-earlier-hours): New
	commands.

	* org.el (org-timestamp-change): Move end-time along with start
	time.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-target-internal-links)
	(org-export-as-html): Protect links specified as #name.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-clone-subtree-with-time-shift): New command.

	* org-latex.el (org-export-latex-special-chars)
	(org-export-latex-treat-sub-super-char): Fix subscript export.

	* org-exp.el (org-create-multibrace-regexp): Do not add
	backslashes to the class.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-colview.el (org-columns-map): Better functions for moving up
	and down a row, even if `truncate-line' is nil.

	* org.el (org-insert-todo-heading): Make sure the keyword is
	inserted at the correct position.

	* org-publish.el (org-publish-project-alist)
	(org-publish-projects, org-publish-org-index): Change default anme
	for the index of file names to "sitemap.org".

	* org-latex.el (org-export-latex-tables): Use
	`org-split-string', for Emacs 21 compatibility.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda-log-mode-items): Improve docstring.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-page-description)
	(org-export-page-keywords): New variables.
	(org-export-plist-vars): Add entries for :keywords and
	:description.
	(org-infile-export-plist): Parse for new keywords.
	(org-get-current-options): Add new keywords
	(org-export-as-html): Publish description and keywords.

	* org-agenda.el (org-agenda-add-entry-text-descriptive-links): New
	option.
	(org-agenda-add-entry-text): Honor
	`org-agenda-add-entry-text-descriptive-links'.

	* org-latex.el (org-export-latex-preprocess): Make all
	external preprocess functions use a PARAMETER arg.

	* org-exp.el (org-export-preprocess-string)
	(org-export-select-backend-specific-text)
	(org-export-format-source-code-or-example)
	(org-format-org-table-html): Support docbook export.
	(org-export-preprocess-string): Make all external preprocess
	functions use a PARAMETER arg.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-html-style-include-scripts): New option.
	(org-export-plist-vars): Add new option
	`org-export-html-style-include-scripts'.
	(org-export-as-html): Honor new option
	`org-export-html-style-include-scripts'.
	(org-export-html-scripts, org-export-html-style-default): Fix
	xml issues with the Safari browser.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-publish.el (org-publish-attachment): Only copy file when the
	directories differ.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-clock.el (org-clocktable-steps): Use inactive time stamps
	for clocktable steps.

	* org.el (org-additional-option-like-keywords): Add two more
	keywords.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-format-source-code-or-example): Mark
	temporary buffer unmodified, so that it will be killed even if
	mode like message mode has decided to assign a file name.

	* org.el (org-scan-tags): Improve tag inheritance.
	(org-scan-tags, org-make-tags-matcher): Make tag comparison
	case-sensitive.
	(org-scan-tags): Use the internal tags list instead of creating it
	from scratch.
	(org-trust-scanner-tags, org-scanner-tags): New variables.
	(org-scan-tags): Set `org-scanner-tags'.
	(org-get-tags-at): Take advantage of `org-trust-scanner-tags'.
	(org-map-entries): Document the possible speedup using scanner
	tags.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-add-planning-info): Fix bug with looking for keyword
	only at column 0.

	* org-agenda.el (org-agenda-custom-commands-local-options): Add
	option for tags filter preset.
	(org-prepare-agenda): Store filter preset as a property on the
	filter variable.
	(org-finalize-agenda): Call the filter, if there is a preset.
	(org-agenda-filter-by-tag): Filter again after clearing the
	filter, when there still is a preset.
	(org-agenda-filter-make-matcher, org-agenda-set-mode-name):
	Include the preset filter.
	(org-agenda-redo): Apply the filter again, also the preset filter.

	* org-exp.el (org-export-as-html): Use IDs in the correct way.

	* org.el (org-uuidgen-p): New funtion.

	* org-agenda.el (org-agenda-fontify-priorities): New default value
	`cookies'.
	(org-agenda-fontify-priorities): Renamed from
	org-fontify-priorities.

	* org.el (org-set-font-lock-defaults): Call
	`org-font-lock-add-priority-faces'.
	(org-font-lock-add-priority-faces): New function.

	* org-faces.el: (org-set-tag-faces): New option.
	(org-priority-faces): New variable.

	* org-exp.el (org-export-as-html): Add a "content" div around the
	entire content of the body tag.
	(org-export-html-get-bibliography): New function.
	(org-export-html-validation-link): New variable.
	(org-export-as-html): Add validation link to exported page.

	* org.el (org-match-sparse-tree): Renamed from
	`org-tags-sparse-tree'.
	(org-tags-sparse-tree): New alias.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-get-valid-level): Catch the case where the level
	change is nil.

	* org-clock.el (org-clock-find-position): Better indentation of
	new clock drawers.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda-quit): Delete window only when the
	frame-setup was not `current-window'.

	* org.el (org-tag-persistent-alist): New option.
	(org-startup-options): Add keyword `noptag'.
	(org-fast-todo-selection): Handle :newline correctly.
	(org-set-tags): Handle :newline correctly.
	(org-fast-tag-selection): Handle :newline correctly.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-as-ascii): Reverse link buffer before
	outputting it.
	(org-export-ascii-push-links): Fix bug with pussing links into the
	export buffer.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-archive.el (org-archive-subtree): Do not add 1 to level if
	pasting at top level.

	* org-bbdb.el: Improve documentation.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-list.el (org-insert-item): Only consider insert empty lines
	is `org-empty-line-terminates-plain-lists' is not nil.

	* org.el (org-blank-before-new-entry): Mention the dependence on
	`org-empty-line-terminates-plain-lists' in the docstring.

	* org-publish.el (org-publish-get-project-from-filename): New
	optional argument UP.  Only find the top project if UP is set.
	(org-publish-current-project): Find the top encloding project.

	* org-agenda.el (org-agenda-before-write-hook)
	(org-agenda-add-entry-text-maxlines): New options.
	(org-write-agenda): Run the new hook in the temporary buffer.
	(org-agenda-add-entry-text): New function.
	(org-write-agenda): Implement PDF export, using ps2pdf.

	* org.el (org-global-properties-fixed, org-global-properties):
	Improve documentation string.

	* org-exp.el (org-export-ascii-links-to-notes): New option.
	(org-export-as-ascii): Handle links better.
	(org-export-ascii-wrap, org-export-ascii-push-links): New
	functions.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-agenda.el (org-agenda): Make prefix arg optional.
	(org-agenda-search-headline-for-time): New option.
	(org-format-agenda-item): Honor
	`org-agenda-search-headline-for-time'.

	* org-table.el (orgtbl-self-insert-command): Cluster undo for 20
	characters.

	* org.el (org-self-insert-cluster-for-undo): New option.
	(org-self-insert-command): Cluster undo for 20 characters.
	(org-self-insert-command-undo-counter): New variable.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-exp.el (org-export-as-html): Fix problem with closing colone
	example.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org-latex.el (org-export-as-latex)
	(org-export-latex-first-lines): Avoid modification flag when
	adding or removing text properties.
	(org-export-latex-fontify): Catch error when org-emph-alist has
	entries that are not defined for LaTeX export.

	* org-export-latex.el: renamed to org-latex.el

	* org-latex.el: renamed from org-export-latex.el

	* org.el (orgstruct++-mode): New function.
	(turn-on-orgstruct++): Call `orgstruct++-mode'.
	(org-context-p): Allow detecting item context after the first line
	of an item.
	(orgstruct-make-binding): Detect if item-body context should be
	seen.
	(orgstruct-is-++): New variable.
	(org-add-planning-info): Catch the case when there is no planning
	info yet and the call does not want to add anything, only maybe
	tries to remove something.
	(org-special-ctrl-a/e): All value to be a cons cell with separate
	settings for `C-a. and `C-e'.
	(org-beginning-of-line, org-end-of-line): Honor separate values
	for `C-a' and `C-e'.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.el (org-reload): New command.

2009-08-06  Carsten Dominik  <carsten.dominik@gmail.com>

	* org.texi (Publishing action): Improve documentation of file
	names when publishing to the source directory.
	(Clean view): Document `org-indent-mode'.
	(Clocking work time): Add documentation for the
	new :timetamp option when creating a clock report.
	(Paragraphs): Fix many typos.
	(Plain lists): Remove duplicate explanation about the
	`C-c *' command.
	(Literal examples): Update to reflect the new behavior
	of the -n -r -k switches when exporting source code examples.
	(Structure editing): Add information about `C-c *',
	converting a plain list into a list of Org items.
	(Remember): Small rephrasing of the paragraph
	describing remember.el.  Also mentioned that remember.el is part
	of Emacs 23, not Emacs 22.
	(Clocking work time): Add documentation about
	displaying the current clocking time against the effort estimate.
	Also add a footnote about using `org-clock-in-prepare-hook' to add
	an effort estimate on the fly, just before clocking it.
	(Footnotes): Document automatic renumbering and
	sorting.
	(Agenda commands): Document new bulk commands.
	(Plain lists): Document new behavior of
	`org-cycle-include-plain-lists'.
	 Hyphenation only in TeX.
	(Clocking work time): Document the key to update effort
	estimates.
	(Clocking work time): Document the clock time display.
	(Structure editing, TODO basics): Document new
	variables.
	(Column attributes): Document new colciew operators.
	(Publishing options): Document :xml-declaration.
	(Tracking TODO state changes): Document the
	LOG_INTO_DRAWER property.
	(Literal examples): Document the new implementation for
	editing source code.
	(Publishing action): Mention the new publishing
	function, to publish an Org source file.
	(Publishing links): Mention how to link to an Org source file.
	(Macro replacement): Document new macros.
	(Handling links): Document type-specific completion
	when inserting links.
	(Structure editing, Plain lists): Improve documentation
	on sorting.
	(Internal links): Document custom ids for links.
	(Handling links): Document custom ids for links.
	(CSS support): Document new class.
	(Refiling notes): Document the possibility to create new nodes
	during refiling.
	(Agenda commands): Document the "?" operator to find
	tasks without effort setting.
	(Exporting agenda information): Section moved.
	(RSS Feeds): New section.
	(Built-in table editor): Document M-e and M-a navigate
	inside table field.
	(Stuck projects): Docment that projects identified as
	un-stuck will still be searchd for stuck sub-projects.
	(Paragraphs): Document centering.
	(Creating timestamps, Agenda commands): Document new
	behavior when changing time stamps.
	(Structure editing): Document the new command
	`org-clone-subtree-with-time-shift'.
	(Publishing): Refresh this chapter.
	(Export options, Export options, In-buffer settings):
	Document the new keywords.
	(Matching tags and properties): Collect all
	documentation about tags/property matches here.
	(Setting tags): Document `org-tag-persistent-alist'.
	(Weekly/daily agenda): New section.
	(Orgstruct mode): Describe `orgstruct++-mode'.
	(Drawers): Mention the LOGBOOK drawer.
	(Export options, Sectioning structure): Document the
	#+LEATEX_HEADER in-buffer setting.
	(Bugs): Section removed.
	(Hooks): New section.
	(Add-on packages): Moved here from old location.
	(Context-sensitive commands): New section.
	(Setting tags): Document newline option.
	(Global TODO list, Matching tags and properties):
	Mention more variables.
	(Checkboxes): Update to changed command behavior.
2009-08-06 09:14:10 +00:00

1550 lines
56 KiB
EmacsLisp

;;; org-clock.el --- The time clocking code for Org-mode
;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
;; Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten at orgmode dot org>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 6.29c
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; 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
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;; This file contains the time clocking code for Org-mode
(require 'org)
(eval-when-compile
(require 'cl)
(require 'calendar))
(declare-function calendar-absolute-from-iso "cal-iso" (&optional date))
(defvar org-time-stamp-formats)
(defgroup org-clock nil
"Options concerning clocking working time in Org-mode."
:tag "Org Clock"
:group 'org-progress)
(defcustom org-clock-into-drawer org-log-into-drawer
"Should clocking info be wrapped into a drawer?
When t, clocking info will always be inserted into a :LOGBOOK: drawer.
If necessary, the drawer will be created.
When nil, the drawer will not be created, but used when present.
When an integer and the number of clocking entries in an item
reaches or exceeds this number, a drawer will be created.
When a string, it names the drawer to be used.
The default for this variable is the value of `org-log-into-drawer',
which see."
:group 'org-todo
:group 'org-clock
:type '(choice
(const :tag "Always" t)
(const :tag "Only when drawer exists" nil)
(integer :tag "When at least N clock entries")
(const :tag "Into LOGBOOK drawer" "LOGBOOK")
(string :tag "Into Drawer named...")))
(defcustom org-clock-out-when-done t
"When non-nil, clock will be stopped when the clocked entry is marked DONE.
A nil value means, clock will keep running until stopped explicitly with
`C-c C-x C-o', or until the clock is started in a different item."
:group 'org-clock
:type 'boolean)
(defcustom org-clock-out-remove-zero-time-clocks nil
"Non-nil means, remove the clock line when the resulting time is zero."
:group 'org-clock
:type 'boolean)
(defcustom org-clock-in-switch-to-state nil
"Set task to a special todo state while clocking it.
The value should be the state to which the entry should be
switched. If the value is a function, it must take one
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")))
(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
switched. If the value is a function, it must take one
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")))
(defcustom org-clock-history-length 5
"Number of clock tasks to remember in history."
:group 'org-clock
:type 'integer)
(defcustom org-clock-goto-may-find-recent-task t
"Non-nil means, `org-clock-goto' can go to recent task if no active clock."
:group 'org-clock
:type 'boolean)
(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."
:group 'org-clock
:type 'function)
(defcustom org-clock-string-limit 0
"Maximum length of clock strings in the modeline. 0 means no limit."
:group 'org-clock
:type 'integer)
(defcustom org-clock-in-resume nil
"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."
:group 'org-clock
:type 'boolean)
(defcustom org-clock-persist nil
"When non-nil, save the running clock when emacs is closed.
The clock is resumed when emacs restarts.
When this is t, both the running clock, and the entire clock
history are saved. When this is the symbol `clock', only the
running clock is saved.
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 .emacs"
:group 'org-clock
:type '(choice
(const :tag "Just the running clock" clock)
(const :tag "Clock and history" t)
(const :tag "No persistence" nil)))
(defcustom org-clock-persist-file (convert-standard-filename
"~/.emacs.d/org-clock-save.el")
"File to save clock data to."
:group 'org-clock
:type 'string)
(defcustom org-clock-persist-query-save nil
"When non-nil, ask before saving the current clock on exit."
:group 'org-clock
:type 'boolean)
(defcustom org-clock-persist-query-resume t
"When non-nil, ask before resuming any stored clock during load."
:group 'org-clock
:type 'boolean)
(defcustom org-clock-sound nil
"Sound that will used for notifications.
Possible values:
nil no sound played.
t standard Emacs beep
file name play this sound file. If not possible, fall back to beep"
:group 'org-clock
:type '(choice
(const :tag "No sound" nil)
(const :tag "Standard beep" t)
(file :tag "Play sound file")))
(defcustom org-clock-modeline-total 'auto
"Default setting for the time included for the modeline clock.
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
today All time clocked inot this task today
repeat All time clocked into this task since last repeat
all All time ever recorded for this task
auto Automtically, either `all', or `repeat' for repeating tasks"
: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)))
(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
(string :tag "Program")
(function :tag "Function")))
(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.")
(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
"Hook run when cancelling the current clock.")
(defvar org-clock-goto-hook nil
"Hook run when selecting the currently clocked-in entry.")
;;; The clock for measuring work time.
(defvar org-mode-line-string "")
(put 'org-mode-line-string 'risky-local-variable t)
(defvar org-clock-mode-line-timer nil)
(defvar org-clock-heading "")
(defvar org-clock-heading-for-remember "")
(defvar org-clock-start-time "")
(defvar org-clock-effort ""
"Effort estimate of the currently clocking task")
(defvar org-clock-total-time nil
"Holds total time, spent previously on currently clocked item.
This does not include the time in the currently running clock.")
(defvar org-clock-history nil
"List of marker pointing to recent clocked tasks.")
(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)
"Marker pointing to the task that has been interrupted by the current clock.")
(defvar org-clock-mode-line-map (make-sparse-keymap))
(define-key org-clock-mode-line-map [mode-line mouse-2] 'org-clock-goto)
(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"])))
(defun org-clock-history-push (&optional pos buffer)
"Push a marker to the clock history."
(setq org-clock-history-length (max 1 (min 35 org-clock-history-length)))
(let ((m (move-marker (make-marker) (or pos (point)) buffer)) n l)
(while (setq n (member m org-clock-history))
(move-marker (car n) nil))
(setq org-clock-history
(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)))
(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)
(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))
(defun org-clock-select-task (&optional prompt)
"Select a task that recently was associated with clocking."
(interactive)
(let (sel-list rpl (i 0) s)
(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 (marker-buffer org-clock-marker)
(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))
(push s sel-list)))
org-clock-history)
(org-fit-window-to-buffer)
(message (or prompt "Select task for clocking:"))
(setq rpl (read-char-exclusive))
(cond
((eq rpl ?q) nil)
((eq rpl ?x) nil)
((assoc rpl sel-list) (cdr (assoc rpl sel-list)))
(t (error "Invalid task choice %c" rpl))))))
(defun org-clock-insert-selection-line (i marker)
"Insert a line for the clock selection menu.
And return a cons cell with the selection character integer and the marker
pointing to it."
(when (marker-buffer marker)
(let (file cat task heading prefix)
(with-current-buffer (org-base-buffer (marker-buffer marker))
(save-excursion
(save-restriction
(widen)
(goto-char marker)
(setq file (buffer-file-name (marker-buffer marker))
cat (or (org-get-category)
(progn (org-refresh-category-properties)
(org-get-category)))
heading (org-get-heading 'notags)
prefix (save-excursion
(org-back-to-heading t)
(looking-at "\\*+ ")
(match-string 0))
task (substring
(org-fontify-like-in-org-mode
(concat prefix heading)
org-odd-levels-only)
(length prefix))))))
(when (and cat task)
(insert (format "[%c] %-15s %s\n" i cat task))
(cons i marker)))))
(defun org-clock-get-clock-string ()
"Form a clock-string, that will be show in the mode line.
If an effort estimate was defined for current item, use
01:30/01:50 format (clocked/estimated).
If not, show simply the clocked time like 01:50."
(let* ((clocked-time (org-clock-get-clocked-time))
(h (floor clocked-time 60))
(m (- clocked-time (* 60 h))))
(if (and org-clock-effort)
(let* ((effort-in-minutes (org-hh:mm-string-to-minutes org-clock-effort))
(effort-h (floor effort-in-minutes 60))
(effort-m (- effort-in-minutes (* effort-h 60))))
(format (concat "-[" org-time-clocksum-format "/" org-time-clocksum-format " (%s)]")
h m effort-h effort-m org-clock-heading))
(format (concat "-[" org-time-clocksum-format " (%s)]")
h m org-clock-heading))))
(defun org-clock-update-mode-line ()
(setq org-mode-line-string
(org-propertize
(let ((clock-string (org-clock-get-clock-string))
(help-text "Org-mode clock is running.\nmouse-1 shows a menu\nmouse-2 will jump to task"))
(if (and (> org-clock-string-limit 0)
(> (length clock-string) org-clock-string-limit))
(org-propertize (substring clock-string 0 org-clock-string-limit)
'help-echo (concat help-text ": " org-clock-heading))
(org-propertize clock-string 'help-echo help-text)))
'local-map org-clock-mode-line-map
'mouse-face (if (featurep 'xemacs) 'highlight 'mode-line-highlight)
'face 'org-mode-line-clock))
(if org-clock-effort (org-clock-notify-once-if-expired))
(force-mode-line-update))
(defun org-clock-get-clocked-time ()
"Get the clocked time for the current item in minutes.
The time returned includes the the time spent on this task in
previous clocking intervals."
(let ((currently-clocked-time
(floor (- (time-to-seconds (current-time))
(time-to-seconds org-clock-start-time)) 60)))
(+ currently-clocked-time (or org-clock-total-time 0))))
(defun org-clock-modify-effort-estimate (&optional value)
"Add to or set the effort estimate of the item currently being clocked.
VALUE can be a number of minutes, or a string with forat hh:mm or mm.
WHen the strig starts with a + or a - sign, the current value of the effort
property will be changed by that amount.
This will update the \"Effort\" property of currently clocked item, and
the mode line."
(interactive)
(when (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-hh:mm-string-to-minutes (substring current 1)))
(setq current 0))
(setq value (org-hh:mm-string-to-minutes value))
(if (equal ?- sign)
(setq value (- current value))
(if (equal ?+ sign) (setq value (+ current value)))))
(setq value (max 0 value)
org-clock-effort (org-minutes-to-hh:mm-string value))
(org-entry-put org-clock-marker "Effort" org-clock-effort)
(org-clock-update-mode-line))))
(defvar org-clock-notification-was-shown nil
"Shows if we have shown notification already.")
(defun org-clock-notify-once-if-expired ()
"Show notification if we spent more time than we estimated before.
Notification is shown only once."
(when (marker-buffer org-clock-marker)
(let ((effort-in-minutes (org-hh:mm-string-to-minutes org-clock-effort))
(clocked-time (org-clock-get-clocked-time)))
(if (>= clocked-time effort-in-minutes)
(unless org-clock-notification-was-shown
(setq org-clock-notification-was-shown t)
(org-clock-play-sound)
(org-show-notification
(format "Task '%s' should be finished by now. (%s)"
org-clock-heading org-clock-effort)))
(setq org-clock-notification-was-shown nil)))))
(defun org-show-notification (notification)
"Show notification.
Use `org-show-notification-handler' if defined,
use libnotify if available, or fall back on a message."
(cond ((functionp org-show-notification-handler)
(funcall org-show-notification-handler notification))
((stringp org-show-notification-handler)
(start-process "emacs-timer-notification" nil
org-show-notification-handler notification))
((org-program-exists "notify-send")
(start-process "emacs-timer-notification" nil
"notify-send" notification))
;; Maybe the handler will send a message, so only use message as
;; a fall back option
(t (message notification))))
(defun org-clock-play-sound ()
"Play sound as configured by `org-clock-sound'.
Use alsa's aplay tool if available."
(cond
((not org-clock-sound))
((eq org-clock-sound t) (beep t) (beep t))
((stringp org-clock-sound)
(if (file-exists-p org-clock-sound)
(if (org-program-exists "aplay")
(start-process "org-clock-play-notification" nil
"aplay" org-clock-sound)
(condition-case nil
(play-sound-file org-clock-sound)
(error (beep t) (beep t))))))))
(defun org-program-exists (program-name)
"Checks whenever we can locate program and launch it."
(if (eq system-type 'gnu/linux)
(= 0 (call-process "which" nil nil nil program-name))))
(defvar org-clock-mode-line-entry nil
"Information for the modeline about the running clock.")
(defun org-clock-in (&optional select)
"Start the clock on the current item.
If necessary, clock-out of the currently active clock.
With prefix arg SELECT, offer a list of recently clocked tasks to
clock into. When SELECT is `C-u C-u', clock into the current task and mark
is as the default task, a special task that will always be offered in
the clocking selection, associated with the letter `d'."
(interactive "P")
(setq org-clock-notification-was-shown nil)
(catch 'abort
(let ((interrupting (marker-buffer org-clock-marker))
ts selected-task target-pos (msg-extra ""))
(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")))
(when interrupting
;; We are interrupting the clocking of a different task.
;; Save a marker to this task, so that we can go back.
(move-marker org-clock-interrupted-task
(marker-position org-clock-marker)
(marker-buffer org-clock-marker))
(org-clock-out t))
(when (equal select '(16))
;; Mark as default clocking task
(org-clock-mark-default-task))
(setq target-pos (point)) ;; we want to clock in at this location
(run-hooks 'org-clock-in-prepare-hook)
(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))
(org-clock-history-push)
(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
(not (looking-at (concat outline-regexp "[ \t]*"
org-clock-in-switch-to-state
"\\>"))))
(org-todo org-clock-in-switch-to-state)))
(setq org-clock-heading-for-remember
(and (looking-at org-complex-heading-regexp)
(match-end 4)
(org-trim (buffer-substring (match-end 1)
(match-end 4)))))
(setq org-clock-heading
(cond ((and org-clock-heading-function
(functionp org-clock-heading-function))
(funcall org-clock-heading-function))
((looking-at org-complex-heading-regexp)
(match-string 4))
(t "???")))
(setq org-clock-heading (org-propertize org-clock-heading
'face nil))
(org-clock-find-position org-clock-in-resume)
(cond
((and org-clock-in-resume
(looking-at
(concat "^[ \t]* " org-clock-string
" \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"
" +\\sw+\.? +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$")))
(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
(org-parse-time-string (match-string 1))))
(setq org-clock-effort (org-get-effort))
(setq org-clock-total-time (org-clock-sum-current-item
(org-clock-get-sum-start))))
((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
(insert-before-markers "\n")
(backward-char 1)
(org-indent-line-function)
(when (and (save-excursion
(end-of-line 0)
(org-in-item-p)))
(beginning-of-line 1)
(org-indent-line-to (- (org-get-indentation) 2)))
(insert org-clock-string " ")
(setq org-clock-effort (org-get-effort))
(setq org-clock-total-time (org-clock-sum-current-item
(org-clock-get-sum-start)))
(setq org-clock-start-time (current-time))
(setq ts (org-insert-time-stamp org-clock-start-time
'with-hm 'inactive))))
(move-marker org-clock-marker (point) (buffer-base-buffer))
(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))))
(org-clock-update-mode-line)
(setq org-clock-mode-line-timer
(run-with-timer 60 60 'org-clock-update-mode-line))
(message "Clock starts at %s - %s" ts msg-extra)
(run-hooks 'org-clock-in-hook)))))))
(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))))
(defvar msg-extra)
(defun org-clock-get-sum-start ()
"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
corresponding variable `org-clock-modeline-total' and then
decides which time to use."
(let ((cmt (or (org-entry-get nil "CLOCK_MODELINE_TOTAL")
(symbol-name org-clock-modeline-total)))
(lr (org-entry-get nil "LAST_REPEAT")))
(cond
((equal cmt "current")
(setq msg-extra "showing time in current clock instance")
(current-time))
((equal cmt "today")
(setq msg-extra "showing today's task time.")
(let* ((dt (decode-time (current-time))))
(setq dt (append (list 0 0 0) (nthcdr 3 dt)))
(if org-extend-today-until
(setf (nth 2 dt) org-extend-today-until))
(apply 'encode-time dt)))
((or (equal cmt "all")
(and (or (not cmt) (equal cmt "auto"))
(not lr)))
(setq msg-extra "showing entire task time.")
nil)
((or (equal cmt "repeat")
(and (or (not cmt) (equal cmt "auto"))
lr))
(setq msg-extra "showing task time since last repeat.")
(if (not lr)
nil
(org-time-string-to-time lr)))
(t nil))))
(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."
(org-back-to-heading t)
(catch 'exit
(let ((beg (save-excursion
(beginning-of-line 2)
(or (bolp) (newline))
(point)))
(end (progn (outline-next-heading) (point)))
(re (concat "^[ \t]*" org-clock-string))
(cnt 0)
(drawer (if (stringp org-clock-into-drawer)
org-clock-into-drawer "LOGBOOK"))
first last ind-last)
(goto-char beg)
(when (and find-unclosed
(re-search-forward
(concat "^[ \t]* " org-clock-string
" \\[\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}"
" +\\sw+ +[012][0-9]:[0-5][0-9]\\)\\][ \t]*$")
end t))
(beginning-of-line 1)
(throw 'exit t))
(when (eobp) (newline) (setq end (max (point) end)))
(when (re-search-forward (concat "^[ \t]*:" drawer ":") end t)
;; we seem to have a CLOCK drawer, so go there.
(beginning-of-line 2)
(or org-log-states-order-reversed
(and (re-search-forward org-property-end-re nil t)
(goto-char (match-beginning 0))))
(throw 'exit t))
;; Lets count the CLOCK lines
(goto-char beg)
(while (re-search-forward re end t)
(setq first (or first (match-beginning 0))
last (match-beginning 0)
cnt (1+ cnt)))
(when (and (integerp org-clock-into-drawer)
last
(>= (1+ cnt) org-clock-into-drawer))
;; Wrap current entries into a new drawer
(goto-char last)
(setq ind-last (org-get-indentation))
(beginning-of-line 2)
(if (and (>= (org-get-indentation) ind-last)
(org-at-item-p))
(org-end-of-item))
(insert ":END:\n")
(beginning-of-line 0)
(org-indent-line-to ind-last)
(goto-char first)
(insert ":" drawer ":\n")
(beginning-of-line 0)
(org-indent-line-function)
(org-flag-drawer t)
(beginning-of-line 2)
(or org-log-states-order-reversed
(and (re-search-forward org-property-end-re nil t)
(goto-char (match-beginning 0))))
(throw 'exit nil))
(goto-char beg)
(while (and (looking-at (concat "[ \t]*" org-keyword-time-regexp))
(not (equal (match-string 1) org-clock-string)))
;; Planning info, skip to after it
(beginning-of-line 2)
(or (bolp) (newline)))
(when (or (eq org-clock-into-drawer t)
(stringp org-clock-into-drawer)
(and (integerp org-clock-into-drawer)
(< org-clock-into-drawer 2)))
(insert ":" drawer ":\n:END:\n")
(beginning-of-line -1)
(org-indent-line-function)
(org-flag-drawer t)
(beginning-of-line 2)
(org-indent-line-function)
(beginning-of-line)
(or org-log-states-order-reversed
(and (re-search-forward org-property-end-re nil t)
(goto-char (match-beginning 0))))))))
(defun org-clock-out (&optional fail-quietly)
"Stop the currently running clock.
If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
(interactive)
(catch 'exit
(if (not (marker-buffer org-clock-marker))
(if fail-quietly (throw 'exit t) (error "No active clock")))
(let (ts te s h m remove)
(save-excursion
(set-buffer (marker-buffer org-clock-marker))
(save-restriction
(widen)
(goto-char org-clock-marker)
(beginning-of-line 1)
(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))
(delete-region (point) (point-at-eol))
(insert "--")
(setq te (org-insert-time-stamp (current-time) 'with-hm 'inactive))
(setq s (- (time-to-seconds (apply 'encode-time (org-parse-time-string te)))
(time-to-seconds (apply 'encode-time (org-parse-time-string ts))))
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)))
(move-marker org-clock-marker nil)
(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))
(setq global-mode-string
(delq 'org-mode-line-string global-mode-string))
(when org-clock-out-switch-to-state
(save-excursion
(org-back-to-heading t)
(let ((org-inhibit-logging t))
(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
(not (looking-at (concat outline-regexp "[ \t]*"
org-clock-out-switch-to-state
"\\>"))))
(org-todo org-clock-out-switch-to-state))))))
(force-mode-line-update)
(message (concat "Clock stopped at %s after HH:MM = " org-time-clocksum-format "%s") te h m
(if remove " => LINE REMOVED" ""))
(run-hooks 'org-clock-out-hook))))))
(defun org-clock-cancel ()
"Cancel the running clock be removing the start timestamp."
(interactive)
(if (not (marker-buffer org-clock-marker))
(error "No active clock"))
(save-excursion
(set-buffer (marker-buffer org-clock-marker))
(goto-char org-clock-marker)
(delete-region (1- (point-at-bol)) (point-at-eol)))
(setq global-mode-string
(delq 'org-mode-line-string global-mode-string))
(force-mode-line-update)
(message "Clock canceled")
(run-hooks 'org-clock-cancel-hook))
(defun org-clock-goto (&optional select)
"Go to the currently clocked-in entry, or to the most recently clocked one.
With prefix arg SELECT, offer recently clocked tasks for selection."
(interactive "@P")
(let* ((recent nil)
(m (cond
(select
(or (org-clock-select-task "Select task to go to: ")
(error "No task selected")))
((marker-buffer org-clock-marker) org-clock-marker)
((and org-clock-goto-may-find-recent-task
(car org-clock-history)
(marker-buffer (car org-clock-history)))
(setq recent t)
(car org-clock-history))
(t (error "No active or recent clock task")))))
(switch-to-buffer (marker-buffer m))
(if (or (< m (point-min)) (> m (point-max))) (widen))
(goto-char m)
(org-show-entry)
(org-back-to-heading t)
(org-cycle-hide-drawers 'children)
(recenter)
(if recent
(message "No running clock, this is the most recently clocked task"))
(run-hooks 'org-clock-goto-hook)))
(defvar org-clock-file-total-minutes nil
"Holds the file total time in minutes, after a call to `org-clock-sum'.")
(make-variable-buffer-local 'org-clock-file-total-minutes)
(defun org-clock-sum (&optional tstart tend)
"Sum the times for each subtree.
Puts the resulting times in minutes as a text property on each headline.
TSTART and TEND can mark a time range to be considered."
(interactive)
(let* ((bmp (buffer-modified-p))
(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 (time-to-seconds tstart)))
(if (consp tend) (setq tend (time-to-seconds tend)))
(remove-text-properties (point-min) (point-max) '(:org-clock-minutes 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 (time-to-seconds
(apply 'encode-time (org-parse-time-string ts)))
te (time-to-seconds
(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
(setq level (- (match-end 1) (match-beginning 1)))
(when (or (> t1 0) (> (aref ltimes level) 0))
(loop for l from 0 to level do
(aset ltimes l (+ (aref ltimes l) t1)))
(setq t1 0 time (aref ltimes level))
(loop for l from level to (1- lmax) do
(aset ltimes l 0))
(goto-char (match-beginning 0))
(put-text-property (point) (point-at-eol) :org-clock-minutes time)))))
(setq org-clock-file-total-minutes (aref ltimes 0)))
(set-buffer-modified-p bmp)))
(defun org-clock-sum-current-item (&optional tstart)
"Returns time, clocked on current item in total"
(save-excursion
(save-restriction
(org-narrow-to-subtree)
(org-clock-sum tstart)
org-clock-file-total-minutes)))
(defun org-clock-display (&optional total-only)
"Show subtree times in the entire buffer.
If TOTAL-ONLY is non-nil, only show the total time for the entire file
in the echo area."
(interactive)
(org-clock-remove-overlays)
(let (time h m p)
(org-clock-sum)
(unless total-only
(save-excursion
(goto-char (point-min))
(while (or (and (equal (setq p (point)) (point-min))
(get-text-property p :org-clock-minutes))
(setq p (next-single-property-change
(point) :org-clock-minutes)))
(goto-char p)
(when (setq time (get-text-property p :org-clock-minutes))
(org-clock-put-overlay time (funcall outline-level))))
(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
(org-add-hook 'before-change-functions 'org-clock-remove-overlays
nil 'local))))
(message (concat "Total file time: " org-time-clocksum-format " (%d hours and %d minutes)") h m h m)))
(defvar org-clock-overlays nil)
(make-variable-buffer-local 'org-clock-overlays)
(defun org-clock-put-overlay (time &optional level)
"Put an overlays on the current line, displaying TIME.
If LEVEL is given, prefix time with a corresponding number of stars.
This creates a new overlay and stores it in `org-clock-overlays', so that it
will be easy to remove."
(let* ((c 60) (h (floor (/ time 60))) (m (- time (* 60 h)))
(l (if level (org-get-valid-level level 0) 0))
(fmt (concat "%s " org-time-clocksum-format "%s"))
(off 0)
ov tx)
(org-move-to-column c)
(unless (eolp) (skip-chars-backward "^ \t"))
(skip-chars-backward " \t")
(setq ov (org-make-overlay (1- (point)) (point-at-eol))
tx (concat (buffer-substring (1- (point)) (point))
(make-string (+ off (max 0 (- c (current-column)))) ?.)
(org-add-props (format fmt
(make-string l ?*) h m
(make-string (- 16 l) ?\ ))
(list 'face 'org-clock-overlay))
""))
(if (not (featurep 'xemacs))
(org-overlay-put ov 'display tx)
(org-overlay-put ov 'invisible t)
(org-overlay-put ov 'end-glyph (make-glyph tx)))
(push ov org-clock-overlays)))
(defun org-clock-remove-overlays (&optional beg end noremove)
"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
(mapc 'org-delete-overlay org-clock-overlays)
(setq org-clock-overlays nil)
(unless noremove
(remove-hook 'before-change-functions
'org-clock-remove-overlays 'local))))
(defvar state) ;; dynamically scoped into this function
(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."
(when (and org-clock-out-when-done
(member state org-done-keywords)
(equal (or (buffer-base-buffer (marker-buffer org-clock-marker))
(marker-buffer org-clock-marker))
(or (buffer-base-buffer (current-buffer))
(current-buffer)))
(< (point) org-clock-marker)
(> (save-excursion (outline-next-heading) (point))
org-clock-marker))
;; Clock out, but don't accept a logging message for this.
(let ((org-log-note-clock-out nil))
(org-clock-out))))
(add-hook 'org-after-todo-state-change-hook
'org-clock-out-if-current)
;;;###autoload
(defun org-get-clocktable (&rest props)
"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)
(font-lock-fontify-buffer)
(forward-line 2)
(buffer-substring (point) (progn
(re-search-forward "^#\\+END" nil t)
(point-at-bol)))))
(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
will be updated. If not, a new clocktable will be inserted.
When called with a prefix argument, move to the first clock table in the
buffer and update it."
(interactive "P")
(org-clock-remove-overlays)
(when arg
(org-find-dblock "clocktable")
(org-show-entry))
(if (org-in-clocktable-p)
(goto-char (org-in-clocktable-p))
(org-create-dblock (list :name "clocktable"
:maxlevel 2 :scope 'file)))
(org-update-dblock))
(defun org-in-clocktable-p ()
"Check if the cursor is in a clocktable."
(let ((pos (point)) start)
(save-excursion
(end-of-line 1)
(and (re-search-backward "^#\\+BEGIN:[ \t]+clocktable" nil t)
(setq start (match-beginning 0))
(re-search-forward "^#\\+END:.*" nil t)
(>= (match-end 0) pos)
start))))
(defun org-clock-special-range (key &optional time as-strings)
"Return two times bordering a special time range.
Key is a symbol specifying the range and can be one of `today', `yesterday',
`thisweek', `lastweek', `thismonth', `lastmonth', `thisyear', `lastyear'.
A week starts Monday 0:00 and ends Sunday 24:00.
The range is determined relative to TIME. TIME defaults to the current time.
The return value is a cons cell with two internal times like the ones
returned by `current time' or `encode-time'. if AS-STRINGS is non-nil,
the returned times will be formatted strings."
(if (integerp key) (setq key (intern (number-to-string key))))
(let* ((tm (decode-time (or time (current-time))))
(s 0) (m (nth 1 tm)) (h (nth 2 tm))
(d (nth 3 tm)) (month (nth 4 tm)) (y (nth 5 tm))
(dow (nth 6 tm))
(skey (symbol-name key))
(shift 0)
s1 m1 h1 d1 month1 y1 diff ts te fm txt w date)
(cond
((string-match "^[0-9]+$" skey)
(setq y (string-to-number skey) m 1 d 1 key 'year))
((string-match "^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)$" skey)
(setq y (string-to-number (match-string 1 skey))
month (string-to-number (match-string 2 skey))
d 1 key 'month))
((string-match "^\\([0-9]+\\)-[wW]\\([0-9]\\{1,2\\}\\)$" skey)
(require 'cal-iso)
(setq y (string-to-number (match-string 1 skey))
w (string-to-number (match-string 2 skey)))
(setq date (calendar-gregorian-from-absolute
(calendar-absolute-from-iso (list w 1 y))))
(setq d (nth 1 date) month (car date) y (nth 2 date)
dow 1
key 'week))
((string-match "^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\\{1,2\\}\\)$" skey)
(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))
((string-match "\\([-+][0-9]+\\)$" skey)
(setq shift (string-to-number (match-string 1 skey))
key (intern (substring skey 0 (match-beginning 1))))))
(when (= shift 0)
(cond ((eq key 'yesterday) (setq key 'today shift -1))
((eq key 'lastweek) (setq key 'week shift -1))
((eq key 'lastmonth) (setq key 'month shift -1))
((eq key 'lastyear) (setq key 'year shift -1))))
(cond
((memq key '(day today))
(setq d (+ d shift) h 0 m 0 h1 24 m1 0))
((memq key '(week thisweek))
(setq diff (+ (* -7 shift) (if (= dow 0) 6 (1- dow)))
m 0 h 0 d (- d diff) d1 (+ 7 d)))
((memq key '(month thismonth))
(setq d 1 h 0 m 0 d1 1 month (+ month shift) month1 (1+ month) h1 0 m1 0))
((memq key '(year thisyear))
(setq m 0 h 0 d 1 month 1 y (+ y shift) y1 (1+ y)))
(t (error "No such time block %s" key)))
(setq ts (encode-time s m h d month y)
te (encode-time (or s1 s) (or m1 m) (or h1 h)
(or d1 d) (or month1 month) (or y1 y)))
(setq fm (cdr org-time-stamp-formats))
(cond
((memq key '(day today))
(setq txt (format-time-string "%A, %B %d, %Y" ts)))
((memq key '(week thisweek))
(setq txt (format-time-string "week %G-W%V" ts)))
((memq key '(month thismonth))
(setq txt (format-time-string "%B %Y" ts)))
((memq key '(year thisyear))
(setq txt (format-time-string "the year %Y" ts))))
(if as-strings
(list (format-time-string fm ts) (format-time-string fm te) txt)
(list ts te txt))))
(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))
(if (not (looking-at "#\\+BEGIN: clocktable\\>.*?:block[ \t]+\\(\\S-+\\)"))
(error "Line needs a :block definition before this command works")
(let* ((b (match-beginning 1)) (e (match-end 1))
(s (match-string 1))
block shift ins y mw d date wp m)
(cond
((equal s "yesterday") (setq s "today-1"))
((equal s "lastweek") (setq s "thisweek-1"))
((equal s "lastmonth") (setq s "thismonth-1"))
((equal s "lastyear") (setq s "thisyear-1")))
(cond
((string-match "^\\(today\\|thisweek\\|thismonth\\|thisyear\\)\\([-+][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]+\\)\\(-\\([wW]?\\)\\([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 mw (> (length wp) 0))
(require 'cal-iso)
(setq date (calendar-gregorian-from-absolute (calendar-absolute-from-iso (list (+ mw n) 1 y))))
(setq ins (format-time-string
"%G-W%V"
(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)))))
(defun org-dblock-write:clocktable (params)
"Write the standard clocktable."
(catch 'exit
(let* ((hlchars '((1 . "*") (2 . "/")))
(ins (make-marker))
(total-time nil)
(scope (plist-get params :scope))
(tostring (plist-get params :tostring))
(multifile (plist-get params :multifile))
(header (plist-get params :header))
(maxlevel (or (plist-get params :maxlevel) 3))
(step (plist-get params :step))
(emph (plist-get params :emphasize))
(timestamp (plist-get params :timestamp))
(ts (plist-get params :tstart))
(te (plist-get params :tend))
(block (plist-get params :block))
(link (plist-get params :link))
ipos time p level hlc hdl tsp props content recalc formula pcol
cc beg end pos tbl tbl1 range-text rm-file-column scope-is-list st)
(setq org-clock-file-total-minutes nil)
(when step
(unless (or block (and ts te))
(error "Clocktable `:step' can only be used with `:block' or `:tstart,:end'"))
(org-clocktable-steps params)
(throw 'exit nil))
(when block
(setq cc (org-clock-special-range block nil t)
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.
(if ts (setq ts (time-to-seconds
(apply 'encode-time (org-parse-time-string ts)))))
(if te (setq te (time-to-seconds
(apply 'encode-time (org-parse-time-string te)))))
(move-marker ins (point))
(setq ipos (point))
;; Get the right scope
(setq pos (point))
(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)
(setq scope (org-add-archive-files (list (buffer-file-name)))
rm-file-column t)))
(setq scope-is-list (and scope (listp scope)))
(save-restriction
(cond
((not scope))
((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)
(looking-at outline-regexp)
(if (<= (org-reduced-level (funcall outline-level)) level)
(throw 'exit nil))))
(org-narrow-to-subtree))
(scope-is-list
(let* ((files scope)
(scope 'agenda)
(p1 (copy-sequence params))
file)
(setq p1 (plist-put p1 :tostring t))
(setq p1 (plist-put p1 :multifile t))
(setq p1 (plist-put p1 :scope 'file))
(org-prepare-agenda-buffers files)
(while (setq file (pop files))
(with-current-buffer (find-buffer-visiting file)
(setq tbl1 (org-dblock-write:clocktable p1))
(when tbl1
(push (org-clocktable-add-file
file
(concat "| |*File time*|*"
(org-minutes-to-hh:mm-string
org-clock-file-total-minutes)
"*|\n"
tbl1)) tbl)
(setq total-time (+ (or total-time 0)
org-clock-file-total-minutes))))))))
(goto-char pos)
(unless scope-is-list
(org-clock-sum ts te)
(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 hlc (if emph (or (cdr (assoc level hlchars)) "") "")
hdl (if (not link)
(match-string 2)
(org-make-link-string
(format "file:%s::%s"
(buffer-file-name)
(save-match-data
(org-make-org-heading-search-string
(match-string 2))))
(match-string 2)))
tsp (when timestamp
(setq props (org-entry-properties (point)))
(or (cdr (assoc "SCHEDULED" props))
(cdr (assoc "TIMESTAMP" props))
(cdr (assoc "DEADLINE" props))
(cdr (assoc "TIMESTAMP_IA" props)))))
(if (and (not multifile) (= level 1)) (push "|-" tbl))
(push (concat
"| " (int-to-string level) "|"
(if timestamp (concat tsp "|") "")
hlc hdl hlc " |"
(make-string (1- level) ?|)
hlc (org-minutes-to-hh:mm-string time) hlc
" |") tbl))))))
(setq tbl (nreverse tbl))
(if tostring
(if tbl (mapconcat 'identity tbl "\n") nil)
(goto-char ins)
(insert-before-markers
(or header
(concat
"Clock summary at ["
(substring
(format-time-string (cdr org-time-stamp-formats))
1 -1)
"]"
(if block (concat ", for " range-text ".") "")
"\n\n"))
(if scope-is-list "|File" "")
"|L|" (if timestamp "Timestamp|" "") "Headline|Time|\n")
(setq total-time (or total-time org-clock-file-total-minutes))
(insert-before-markers
"|-\n|"
(if scope-is-list "|" "")
(if timestamp "|Timestamp|" "|")
"*Total time*| *"
(org-minutes-to-hh:mm-string (or total-time 0))
"*|\n|-\n")
(setq tbl (delq nil tbl))
(if (and (stringp (car tbl)) (> (length (car tbl)) 1)
(equal (substring (car tbl) 0 2) "|-"))
(pop tbl))
(insert-before-markers (mapconcat
'identity (delq nil tbl)
(if scope-is-list "\n|-\n" "\n")))
(backward-delete-char 1)
(if (setq formula (plist-get params :formula))
(cond
((eq formula '%)
(setq pcol (+ (if scope-is-list 1 0) maxlevel 3))
(insert
(format
"\n#+TBLFM: $%d='(org-clock-time%% @%d$%d $%d..$%d);%%.1f"
pcol
2
(+ 3 (if scope-is-list 1 0))
(+ (if scope-is-list 1 0) 3)
(1- pcol)))
(setq recalc t))
((stringp formula)
(insert "\n#+TBLFM: " formula)
(setq recalc t))
(t (error "invalid formula in clocktable")))
;; 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))))
(goto-char ipos)
(skip-chars-forward "^|")
(org-table-align)
(when recalc
(if (eq formula '%)
(save-excursion (org-table-goto-column pcol nil 'force)
(insert "%")))
(org-table-recalculate 'all))
(when rm-file-column
(forward-char 1)
(org-table-delete-column)))))))
(defun org-clocktable-steps (params)
(let* ((p1 (copy-sequence params))
(ts (plist-get p1 :tstart))
(te (plist-get p1 :tend))
(step0 (plist-get p1 :step))
(step (cdr (assoc step0 '((day . 86400) (week . 604800)))))
(block (plist-get p1 :block))
cc range-text)
(when block
(setq cc (org-clock-special-range block nil t)
ts (car cc) te (nth 1 cc) range-text (nth 2 cc)))
(if ts (setq ts (time-to-seconds
(apply 'encode-time (org-parse-time-string ts)))))
(if te (setq te (time-to-seconds
(apply 'encode-time (org-parse-time-string te)))))
(setq p1 (plist-put p1 :header ""))
(setq p1 (plist-put p1 :step nil))
(setq p1 (plist-put p1 :block nil))
(while (< ts te)
(or (bolp) (insert "\n"))
(setq p1 (plist-put p1 :tstart (format-time-string
(org-time-stamp-format nil t)
(seconds-to-time ts))))
(setq p1 (plist-put p1 :tend (format-time-string
(org-time-stamp-format nil t)
(seconds-to-time (setq ts (+ ts step))))))
(insert "\n" (if (eq step0 'day) "Daily report: " "Weekly report starting on: ")
(plist-get p1 :tstart) "\n")
(org-dblock-write:clocktable p1)
(re-search-forward "#\\+END:")
(end-of-line 0))))
(defun org-clocktable-add-file (file table)
(if table
(let ((lines (org-split-string table "\n"))
(ff (file-name-nondirectory file)))
(mapconcat 'identity
(mapcar (lambda (x)
(if (string-match org-table-dataline-regexp x)
(concat "|" ff x)
x))
lines)
"\n"))))
(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))
(* 60 (string-to-number (match-string 1 s)))))
tot))))
0))))
(defun org-clock-save ()
"Persist various clock-related data to disk.
The details of what will be saved are regulated by the variable
`org-clock-persist'."
(when org-clock-persist
(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"
system-name (format-time-string
(cdr org-time-stamp-formats))))
(if (and (setq b (marker-buffer org-clock-marker))
(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 ("
(substring-no-properties org-clock-heading)
") "))))
(insert "(setq resume-clock '(\""
(buffer-file-name (marker-buffer org-clock-marker))
"\" . " (int-to-string (marker-position org-clock-marker))
"))\n"))
;; Store clocked task history. Tasks are stored reversed to make
;; reading simpler
(when (and org-clock-history (eq org-clock-persist t))
(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)))))))
(defvar org-clock-loaded nil
"Was the clock file loaded?")
(defun org-clock-load ()
"Load clock-related data from disk, maybe resuming a stored clock."
(when (and org-clock-persist (not org-clock-loaded))
(let ((filename (expand-file-name org-clock-persist-file))
(org-clock-in-resume 'auto-restart)
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)
(y-or-n-p
(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))
(org-clock-in)
(if (org-invisible-p)
(org-show-context)))))))))
;;;###autoload
(defun org-clock-persistence-insinuate ()
"Set up hooks for clock persistence"
(add-hook 'org-mode-hook 'org-clock-load)
(add-hook 'kill-emacs-hook 'org-clock-save))
;; Suggested bindings
(org-defkey org-mode-map "\C-c\C-x\C-e" 'org-clock-modify-effort-estimate)
(provide 'org-clock)
;; arch-tag: 7b42c5d4-9b36-48be-97c0-66a869daed4c
;;; org-clock.el ends here