Jelajahi Sumber

Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode

Carsten Dominik 14 tahun lalu
induk
melakukan
05893b658d

+ 119 - 95
doc/org.texi

@@ -768,8 +768,8 @@ As a project planning environment, Org works by adding metadata to outline
 nodes.  Based on this data, specific entries can be extracted in queries and
 create dynamic @i{agenda views}.
 
-Org mode contains the Org Babel environment which allows to work with
-embedded source code block in a file, to facilitate code evaluation,
+Org mode contains the Org Babel environment which allows you to work with
+embedded source code blocks in a file, to facilitate code evaluation,
 documentation, and tangling.
 
 Org's automatic, context-sensitive table editor with spreadsheet
@@ -1482,7 +1482,7 @@ as bullets.
 @emph{Ordered} list items start with a numeral followed by either a period or
 a right parenthesis@footnote{You can filter out any of them by configuring
 @code{org-plain-list-ordered-item-terminator}.}, such as @samp{1.} or
-@samp{1)}.  If you want a list to start a different value (e.g. 20), start
+@samp{1)}.  If you want a list to start with a different value (e.g. 20), start
 the text of the item with @code{[@@20]}@footnote{If there's a checkbox in the
 item, the cookie must be put @emph{before} the checkbox.}.  Those constructs
 can be used in any item of the list in order to enforce a particular
@@ -1537,7 +1537,7 @@ XEmacs, you should use Kyle E. Jones' @file{filladapt.el}.  To turn this on,
 put into @file{.emacs}: @code{(require 'filladapt)}}, and by exporting them
 properly (@pxref{Exporting}).  Since indentation is what governs the
 structure of these lists, many structural constructs like @code{#+BEGIN_...}
-blocks can be indented to signal that they should be considered of a list
+blocks can be indented to signal that they should be considered as a list
 item.
 
 @vindex org-list-demote-modify-bullet
@@ -1548,7 +1548,7 @@ the current list-level) improves readability, customize the variable
 @vindex org-list-automatic-rules
 The following commands act on items when the cursor is in the first line of
 an item (the line with the bullet or number).  Some of them imply the
-application of automatic rules to keep list structure in tact.  If some of
+application of automatic rules to keep list structure intact.  If some of
 these actions get in your way, configure @code{org-list-automatic-rules}
 to disable them individually.
 
@@ -1557,8 +1557,9 @@ to disable them individually.
 @vindex org-cycle-include-plain-lists
 Items can be folded just like headline levels.  Normally this works only if
 the cursor is on a plain list item.  For more details, see the variable
-@code{org-cycle-include-plain-lists}. to @code{integrate}, plain list items
-will be treated like low-level.  The level of an item is then given by the
+@code{org-cycle-include-plain-lists}.  If this variable is set to
+@code{integrate}, plain list items will be treated like low-level
+headlines.  The level of an item is then given by the
 indentation of the bullet/number.  Items are always subordinate to real
 headlines, however; the hierarchies remain completely separated.
 @orgcmd{M-@key{RET},org-insert-heading}
@@ -1569,7 +1570,7 @@ heading (@pxref{Structure editing}).  If this command is used in the middle
 of a line, the line is @emph{split} and the rest of the line becomes the new
 item@footnote{If you do not want the line to be split, customize the variable
 @code{org-M-RET-may-split-line}.}.  If this command is executed @emph{before
-item's body}, the new item is created @emph{before} the current item.  If the
+an item's body}, the new item is created @emph{before} the current item.  If the
 command is executed in the white space before the text that is part of an
 item but does not contain the bullet, a bullet is added to the current line.
 
@@ -1581,7 +1582,7 @@ the structure, or return an error.
 Insert a new item with a checkbox (@pxref{Checkboxes}).
 @orgcmd{@key{TAB},org-cycle}
 In a new item with no text yet, the first @key{TAB} demotes the item to
-become a child of the previous one.  Subsequents @key{TAB} move the item to
+become a child of the previous one.  Subsequent @key{TAB}s move the item to
 meaningful levels in the list and eventually get it back to its initial
 position.
 @kindex S-@key{down}
@@ -1687,8 +1688,7 @@ press @key{TAB} there.  Org-mode uses the @code{PROPERTIES} drawer for
 storing properties (@pxref{Properties and Columns}), and you can also arrange
 for state change notes (@pxref{Tracking TODO state changes}) and clock times
 (@pxref{Clocking work time}) to be stored in a drawer @code{LOGBOOK}.  If you
-want to store a quick note in the LOGBOOK drawer, in a similar way as this is
-done by state changes, use
+want to store a quick note in the LOGBOOK drawer, in a similar way to state changes, use
 
 @table @kbd
 @kindex C-c C-z
@@ -1843,7 +1843,7 @@ When this mode is active and the cursor is on a line that looks to Org like a
 headline or the first line of a list item, most structure editing commands
 will work, even if the same keys normally have different functionality in the
 major mode you are using.  If the cursor is not in one of those special
-lines, Orgstruct mode lurks silently in the shadow.  When you use
+lines, Orgstruct mode lurks silently in the shadows.  When you use
 @code{orgstruct++-mode}, Org will also export indentation and autofill
 settings into that mode, and detect item context after the first line of an
 item.
@@ -2137,7 +2137,7 @@ on a per-file basis with:
 @end example
 
 If you would like to overrule the automatic alignment of number-rich columns
-to the right and of string-rich column to the left, you and use @samp{<r>},
+to the right and of string-rich column to the left, you can use @samp{<r>},
 @samp{c}@footnote{Centering does not work inside Emacs, but it does have an
 effect when exporting to HTML.} or @samp{<l>} in a similar fashion.  You may
 also combine alignment and field width like this: @samp{<l10>}.
@@ -2470,7 +2470,7 @@ tan($1);Dp3s1        @r{Compute in degrees, precision 3, display SCI 1}
 sin($1);Dp3%.1e      @r{Same, but use printf specifier for display}
 vmean($2..$7)        @r{Compute column range mean, using vector function}
 vmean($2..$7);EN     @r{Same, but treat empty fields as 0}
-taylor($3,x=7,2)     @r{taylor series of $3, at x=7, second degree}
+taylor($3,x=7,2)     @r{Taylor series of $3, at x=7, second degree}
 @end example
 
 Calc also contains a complete set of logical operations.  For example
@@ -3859,7 +3859,7 @@ work time}.
 
 The most basic logging is to keep track of @emph{when} a certain TODO
 item was finished.  This is achieved with@footnote{The corresponding
-in-buffer setting is: @code{#+STARTUP: logdone}}.
+in-buffer setting is: @code{#+STARTUP: logdone}}
 
 @lisp
 (setq org-log-done 'time)
@@ -4759,7 +4759,7 @@ single property:
 Create a sparse tree based on the value of a property.  This first
 prompts for the name of a property, and then for a value.  A sparse tree
 is created with all entries that define this property with the given
-value.  If you enclose the value into curly braces, it is interpreted as
+value.  If you enclose the value in curly braces, it is interpreted as
 a regular expression and matched against the property values.
 @end table
 
@@ -4769,7 +4769,7 @@ a regular expression and matched against the property values.
 @cindex inheritance, of properties
 
 @vindex org-use-property-inheritance
-The outline structure of Org-mode documents lends itself for an
+The outline structure of Org-mode documents lends itself to an
 inheritance model of properties: if the parent in a tree has a certain
 property, the children can inherit this property.  Org-mode does not
 turn this on by default, because it can slow down property searches
@@ -4779,7 +4779,7 @@ useful, you can turn it on by setting the variable
 all properties inherited from the parent, to a list of properties
 that should be inherited, or to a regular expression that matches
 inherited properties.  If a property has the value @samp{nil}, this is
-interpreted as an explicit undefine of he property, so that inheritance
+interpreted as an explicit undefine of the property, so that inheritance
 search will stop at this value and return @code{nil}.
 
 Org-mode has a few properties for which inheritance is hard-coded, at
@@ -4921,7 +4921,7 @@ same summary information.
 The @code{est+} summary type requires further explanation.  It is used for
 combining estimates, expressed as low-high ranges.  For example, instead
 of estimating a particular task will take 5 days, you might estimate it as
-5-6 days if you're fairly confident you know how much woark is required, or
+5-6 days if you're fairly confident you know how much work is required, or
 1-10 days if you don't really know what needs to be done.  Both ranges
 average at 5.5 days, but the first represents a more predictable delivery.
 
@@ -4992,7 +4992,7 @@ Move through the column view from field to field.
 Switch to the next/previous allowed value of the field.  For this, you
 have to have specified allowed values for a property.
 @item 1..9,0
-Directly select the nth allowed value, @kbd{0} selects the 10th value.
+Directly select the Nth allowed value, @kbd{0} selects the 10th value.
 @orgcmdkkcc{n,p,org-columns-next-allowed-value,org-columns-previous-allowed-value}
 Same as @kbd{S-@key{left}/@key{right}}
 @orgcmd{e,org-columns-edit-value}
@@ -5326,7 +5326,7 @@ letter ([dwmy]) to indicate change in days, weeks, months, or years.  With a
 single plus or minus, the date is always relative to today.  With a
 double plus or minus, it is relative to the default date.  If instead of
 a single letter, you use the abbreviation of day name, the date will be
-the nth such day.  E.g.
+the Nth such day.  E.g.
 
 @example
 +0            --> today
@@ -5345,7 +5345,7 @@ you want to use unabbreviated names and/or other languages, configure
 the variables @code{parse-time-months} and @code{parse-time-weekdays}.
 
 You can specify a time range by giving start and end times or by giving a
-start time and a duration (in HH:MM format). Use '-' or '--' as the separator
+start time and a duration (in HH:MM format). Use `-' or `-@{@}-' as the separator
 in the former case and use '+' as the separator in the latter case. E.g.
 
 @example
@@ -5430,7 +5430,7 @@ just like @kbd{S-@key{left}/@key{right}}.  At the end of the stamp, the
 time will be changed by one minute.
 @item
 If the timestamp contains a range of clock times or a repeater, these
-will not be overlayed, but remain in the buffer as they were.
+will not be overlaid, but remain in the buffer as they were.
 @item
 When you delete a timestamp character-by-character, it will only
 disappear from the buffer after @emph{all} (invisible) characters
@@ -5624,7 +5624,7 @@ With the @samp{+1m} cookie, the date shift will always be exactly one
 month.  So if you have not paid the rent for three months, marking this
 entry DONE will still keep it as an overdue deadline.  Depending on the
 task, this may not be the best way to handle it.  For example, if you
-forgot to call you father for 3 weeks, it does not make sense to call
+forgot to call your father for 3 weeks, it does not make sense to call
 him 3 times in a single day to make up for it.  Finally, there are tasks
 like changing batteries which should always repeat a certain time
 @i{after} the last time you did it.  For these tasks, Org-mode has
@@ -5820,6 +5820,7 @@ be selected:
              2007-12-31    @r{New year eve 2007}
              2007-12       @r{December 2007}
              2007-W50      @r{ISO-week 50 in 2007}
+             2007-Q2       @r{2nd quarter in 2007}
              2007          @r{the year 2007}
              today, yesterday, today-@var{N}          @r{a relative day}
              thisweek, lastweek, thisweek-@var{N}     @r{a relative week}
@@ -5854,7 +5855,7 @@ but you can specify your own function using the @code{:formatter} parameter.
              @r{DEADLINE, TIMESTAMP and TIMESTAMP_IA, in this order.}
 :formula     @r{Content of a @code{#+TBLFM} line to be added and evaluated.}
              @r{As a special case, @samp{:formula %} adds a column with % time.}
-             @r{If you do not specify a formula here, any existing formula.}
+             @r{If you do not specify a formula here, any existing formula}
              @r{below the clock table will survive updates and be evaluated.}
 :formatter   @r{A function to format clock data and insert it into the buffer.}
 @end example
@@ -5971,7 +5972,7 @@ for an entry with the following commands:
 @table @kbd
 @orgcmd{C-c C-x e,org-set-effort}
 Set the effort estimate for the current entry.  With a numeric prefix
-argument, set it to the NTH allowed value (see below).  This command is also
+argument, set it to the Nth allowed value (see below).  This command is also
 accessible from the agenda with the @kbd{e} key.
 @orgcmd{C-c C-x C-e,org-clock-modify-effort-estimate}
 Modify the effort estimate of the item currently being clocked.
@@ -6148,17 +6149,20 @@ narrowed to this new node.  You may then insert the information you want.
 @orgcmd{C-c C-c,org-capture-finalize}
 Once you have finished entering information into the capture buffer, @kbd{C-c
 C-c} will return you to the window configuration before the capture process,
-so that you can resume your work without further distraction.
+so that you can resume your work without further distraction.  When called
+with a prefix arg, finalize and then jump to the captured item.
 
 @orgcmd{C-c C-w,org-capture-refile}
 Finalize the capture process by refiling (@pxref{Refiling notes}) the note to
 a different place.  Please realize that this is a normal refiling command
 that will be executed - so the cursor position at the moment you run this
 command is important.  If you have inserted a tree with a parent and
-children, first move the cursor back to the parent.
+children, first move the cursor back to the parent.  Any prefix argument
+given to this command will be passed on to the @code{org-refile} command.
 
 @orgcmd{C-c C-k,org-capture-kill}
 Abort the capture process and return to the previous state.
+
 @end table
 
 You can also call @code{org-capture} in a special way from the agenda, using
@@ -6166,6 +6170,17 @@ the @kbd{k c} key combination.  With this access, any timestamps inserted by
 the selected capture template will default to the cursor date in the agenda,
 rather than to the current date.
 
+To find the locations of the last stored capture, use @code{org-capture} with
+prefix commands:
+
+@table @kbd
+@orgkey{C-u C-c c}
+Visit the target location of a cpature template.  You get to select the
+template in the usual way.
+@orgkey{C-u C-u C-c c}
+Visit the last stored capture item in its buffer.
+@end table
+
 @node Capture templates,  , Using capture, Capture
 @subsection Capture templates
 @cindex templates, for Capture
@@ -6611,7 +6626,7 @@ Refile as the child of the item currently being clocked.
 @orgcmdtkc{C-0 C-c C-w @ @r{or} @ C-u C-u C-u C-c C-w,C-0 C-c C-w,org-refile-cache-clear}
 
 Clear the target cache.  Caching of refile targets can be turned on by
-setting @code{org-refile-use-cache}.  To make the command seen new possible
+setting @code{org-refile-use-cache}.  To make the command see new possible
 targets, you have to clear the cache with this command.
 @end table
 
@@ -6965,16 +6980,22 @@ paper agenda, showing all the tasks for the current week or day.
 @table @kbd
 @cindex org-agenda, command
 @orgcmd{C-c a a,org-agenda-list}
-@vindex org-agenda-ndays
 Compile an agenda for the current week from a list of Org files.  The agenda
 shows the entries for each day.  With a numeric prefix@footnote{For backward
 compatibility, the universal prefix @kbd{C-u} causes all TODO entries to be
 listed before the agenda.  This feature is deprecated, use the dedicated TODO
 list, or a block agenda instead (@pxref{Block agenda}).}  (like @kbd{C-u 2 1
-C-c a a}) you may set the number of days to be displayed (see also the
-variable @code{org-agenda-ndays})
+C-c a a}) you may set the number of days to be displayed.
 @end table
 
+@vindex org-agenda-span
+@vindex org-agenda-ndays
+The default number of days displayed in the agenda is set by the variable
+@code{org-agenda-span} (or the obsolete @code{org-agenda-ndays}).  This
+variable can be set to any number of days you want to see by default in the
+agenda, or to a span name, such a @code{day}, @code{week}, @code{month} or
+@code{year}.
+
 Remote editing from the agenda buffer means, for example, that you can
 change the dates of deadlines and appointments from the agenda buffer.
 The commands available in the Agenda buffer are listed in @ref{Agenda
@@ -7098,7 +7119,7 @@ Like the above, but allows selection of a specific TODO keyword.  You can
 also do this by specifying a prefix argument to @kbd{C-c a t}.  You are
 prompted for a keyword, and you may also specify several keywords by
 separating them with @samp{|} as the boolean OR operator.  With a numeric
-prefix, the nth keyword in @code{org-todo-keywords} is selected.
+prefix, the Nth keyword in @code{org-todo-keywords} is selected.
 @kindex r
 The @kbd{r} key in the agenda buffer regenerates it, and you can give
 a prefix argument to this command to change the selected TODO keyword,
@@ -7120,13 +7141,15 @@ it more compact:
 @item
 @vindex org-agenda-todo-ignore-scheduled
 @vindex org-agenda-todo-ignore-deadlines
+@vindex org-agenda-todo-ignore-timestamp
 @vindex org-agenda-todo-ignore-with-date
 Some people view a TODO item that has been @emph{scheduled} for execution or
 have a @emph{deadline} (@pxref{Timestamps}) as no longer @emph{open}.
 Configure the variables @code{org-agenda-todo-ignore-scheduled},
-@code{org-agenda-todo-ignore-deadlines}, and/or
-@code{org-agenda-todo-ignore-with-date} to exclude such items from the
-global TODO list.
+@code{org-agenda-todo-ignore-deadlines},
+@code{org-agenda-todo-ignore-timestamp} and/or
+@code{org-agenda-todo-ignore-with-date} to exclude such items from the global
+TODO list.
 @item
 @vindex org-agenda-todo-list-sublevels
 TODO items may have sublevels to break up the task into subtasks.  In
@@ -7618,10 +7641,9 @@ argument as well.  For example, @kbd{200712 w} will jump to week 12 in
 be mapped to the interval 1938-2037.
 @c
 @orgcmd{f,org-agenda-later}
-@vindex org-agenda-ndays
-Go forward in time to display the following @code{org-agenda-ndays} days.
+Go forward in time to display the following @code{org-agenda-current-span} days.
 For example, if the display covers a week, switch to the following week.
-With prefix arg, go forward that many times @code{org-agenda-ndays} days.
+With prefix arg, go forward that many times @code{org-agenda-current-span} days.
 @c
 @orgcmd{b,org-agenda-earlier}
 Go backward in time to display earlier dates.
@@ -7725,7 +7747,7 @@ file or subtree (@pxref{Agenda files}).
 Filter the current agenda view with respect to a tag and/or effort estimates.
 The difference between this and a custom agenda command is that filtering is
 very fast, so that you can switch quickly between different filters without
-having to recreate the agenda@footnote{Custom commands can preset a filter by
+having to recreate the agenda.@footnote{Custom commands can preset a filter by
 binding the variable @code{org-agenda-filter-preset} as an option.  This
 filter will then be applied to the view and persist as a basic filter through
 refreshes and more secondary filtering.  The filter is a global property of
@@ -7744,7 +7766,7 @@ Instead of pressing @kbd{+} or @kbd{-} after @kbd{/}, you can also
 immediately use the @kbd{\} command.
 
 @vindex org-sort-agenda-noeffort-is-high
-In order to filter for effort estimates, you should set-up allowed
+In order to filter for effort estimates, you should set up allowed
 efforts globally, for example
 @lisp
 (setq org-global-properties
@@ -7886,9 +7908,9 @@ Decrease the priority of the current item.
 @c
 @orgcmdkkc{z,C-c C-z,org-agenda-add-note}
 @vindex org-log-into-drawer
-Add a note to the entry.  This note will be recorded, and then files to the
+Add a note to the entry.  This note will be recorded, and then filed to the
 same location where state change notes are put.  Depending on
-@code{org-log-into-drawer}, this maybe inside a drawer.
+@code{org-log-into-drawer}, this may be inside a drawer.
 @c
 @orgcmd{C-c C-a,org-attach}
 Dispatcher for all command related to attachments.
@@ -7949,7 +7971,8 @@ Jump to the running clock in another window.
 @cindex remote editing, bulk, from agenda
 
 @orgcmd{m,org-agenda-bulk-mark}
-Mark the entry at point for bulk action.
+Mark the entry at point for bulk action.  With prefix arg, mark that many
+successive entries.
 @c
 @orgcmd{u,org-agenda-bulk-unmark}
 Unmark entry for bulk action.
@@ -7975,6 +7998,8 @@ t  @r{Change TODO state.  This prompts for a single TODO keyword and}
 s  @r{Schedule all items to a new date.  To shift existing schedule dates}
    @r{by a fixed number of days, use something starting with double plus}
    @r{at the prompt, for example @samp{++8d} or @samp{++2w}.}
+S  @r{Reschedule randomly by N days.  N will be prompted for.  With prefix}
+   @r{arg (@kbd{C-u B S}), scatter only accross weekdays.}
 d  @r{Set deadline to a specific date.}
 @end example
 
@@ -8366,7 +8391,7 @@ or, if you need to modify some parameters@footnote{Quoting depends on the
 system you use, please check the FAQ for examples.}
 @example
 emacs -eval '(org-batch-store-agenda-views                      \
-              org-agenda-ndays 30                               \
+              org-agenda-span month                             \
               org-agenda-start-day "2007-11-01"                 \
               org-agenda-include-diary nil                      \
               org-agenda-files (quote ("~/org/project.org")))'  \
@@ -8731,7 +8756,7 @@ If the example is source code from a programming language, or any other text
 that can be marked up by font-lock in Emacs, you can ask for the example to
 look like the fontified Emacs buffer@footnote{This works automatically for
 the HTML backend (it requires version 1.34 of the @file{htmlize.el} package,
-which is distributed with Org.)  Fontified code chunks in LaTeX can be
+which is distributed with Org).  Fontified code chunks in LaTeX can be
 achieved using either the listings or the
 @url{http://code.google.com/p/minted, minted,} package. To use listings, turn
 on the variable @code{org-export-latex-listings} and ensure that the listings
@@ -8959,8 +8984,8 @@ variable @code{org-pretty-entities}, or on a per-file base with the
 @table @kbd
 @kindex C-c C-x \
 @item C-c C-x \
-Toggle display of entities as UTF8 characters.  This does not change the
-buffer content which remains plain ASCII, but it overlays the UTF8 character
+Toggle display of entities as UTF-8 characters.  This does not change the
+buffer content which remains plain ASCII, but it overlays the UTF-8 character
 for display purposes only.
 @end table
 
@@ -8976,7 +9001,7 @@ not necessary (but OK) to surround multi-character sub- and superscripts
 with curly braces.  For example
 
 @example
-The mass if the sun is M_sun = 1.989 x 10^30 kg.  The radius of
+The mass of the sun is M_sun = 1.989 x 10^30 kg.  The radius of
 the sun is R_@{sun@} = 6.96 x 10^8 m.
 @end example
 
@@ -8998,7 +9023,7 @@ subscript, but @samp{a_@{b@}} will.
 @table @kbd
 @kindex C-c C-x \
 @item C-c C-x \
-In addition to showing entities as UTF8 characters, this command will also
+In addition to showing entities as UTF-8 characters, this command will also
 format sub- and superscripts in a WYSIWYM way.
 @end table
 
@@ -9157,7 +9182,7 @@ after the backquote, a help window will pop up.
 @kindex '
 Pressing the single-quote @kbd{'} followed by another character modifies
 the symbol before point with an accent or a font.  If you wait more than
-1.5 seconds after the backquote, a help window will pop up.  Character
+1.5 seconds after the single-quote, a help window will pop up.  Character
 modification will work only inside La@TeX{} fragments, outside the quote
 is normal.
 @end itemize
@@ -9261,7 +9286,7 @@ Insert template with export options, see example below.
 @example
 #+TITLE:       the title to be shown (default is the buffer name)
 #+AUTHOR:      the author (default taken from @code{user-full-name})
-#+DATE:        a date, fixed, of a format string for @code{format-time-string}
+#+DATE:        a date, fixed, or a format string for @code{format-time-string}
 #+EMAIL:       his/her email address (default from @code{user-mail-address})
 #+DESCRIPTION: the page description, e.g. for the XHTML meta tag
 #+KEYWORDS:    the page keywords, e.g. for the XHTML meta tag
@@ -9363,7 +9388,7 @@ Like @kbd{C-c C-e}, but only export the text that is currently visible
 (i.e. not hidden by outline visibility).
 @orgcmd{C-u C-u C-c C-e,org-export}
 @vindex org-export-run-in-background
-Call an the exporter, but reverse the setting of
+Call the exporter, but reverse the setting of
 @code{org-export-run-in-background}, i.e. request background processing if
 not set, or force processing in the current Emacs process if set.
 @end table
@@ -9786,11 +9811,11 @@ sdepth:  @r{Maximum headline level that will still become an independent}
          @r{@code{org-export-headline-levels} (= the @code{H} switch in @code{#+OPTIONS}).}
          @r{If this is smaller than in @code{org-export-headline-levels}, each}
          @r{info/folding section can still contain child headlines.}
-toc:     @r{Should the table of content @emph{initially} be visible?}
+toc:     @r{Should the table of contents @emph{initially} be visible?}
          @r{Even when @code{nil}, you can always get to the "toc" with @kbd{i}.}
 tdepth:  @r{The depth of the table of contents.  The defaults are taken from}
          @r{the variables @code{org-export-headline-levels} and @code{org-export-with-toc}.}
-ftoc:    @r{Does the css of the page specify a fixed position for the "toc"?}
+ftoc:    @r{Does the CSS of the page specify a fixed position for the "toc"?}
          @r{If yes, the toc will never be displayed as a section.}
 ltoc:    @r{Should there be short contents (children) in each section?}
          @r{Make this @code{above} if the section should be above initial text.}
@@ -10223,7 +10248,7 @@ exported DocBook XML files invalid by not quoting DocBook code correctly.
 #+BEGIN_DOCBOOK
 <warning>
   <para>You should know what you are doing when quoting DocBook XML code
-  in your Org file.  Invalid DocBook XML file may be generated by
+  in your Org file.  Invalid DocBook XML may be generated by
   DocBook exporter if you are not careful!</para>
 </warning>
 #+END_DOCBOOK
@@ -11186,7 +11211,7 @@ can be used to map arbitrary language names to existing major modes.
 Controls the way Emacs windows are rearranged when the edit buffer is created.
 @item org-src-preserve-indentation
 This variable is especially useful for tangling languages such as
-python, in which whitespace indentation in the output is critical.
+Python, in which whitespace indentation in the output is critical.
 @item org-src-ask-before-returning-to-edit-buffer
 By default, Org will ask before returning to an open edit buffer. Set
 this variable to nil to switch without asking.
@@ -11228,7 +11253,7 @@ Neither the code block nor its results will be exported.
 @end table
 
 It is possible to inhibit the evaluation of code blocks during export.
-Setting the the @code{org-export-babel-evaluate} variable to @code{nil} will
+Setting the @code{org-export-babel-evaluate} variable to @code{nil} will
 ensure that no code blocks are evaluated as part of the export process.  This
 can be useful in situations where potentially untrusted Org-mode files are
 exported in an automated fashion, for example when Org-mode is used as the
@@ -11355,17 +11380,17 @@ Code blocks in the following languages are supported.
 @item @b{Language} @tab @b{Identifier} @tab @b{Language} @tab @b{Identifier}
 @item Asymptote @tab asymptote @tab C @tab C
 @item C++ @tab C++ @tab Clojure @tab clojure
-@item css @tab css @tab ditaa @tab ditaa
+@item CSS @tab css @tab ditaa @tab ditaa
 @item Graphviz @tab dot @tab Emacs Lisp @tab emacs-lisp
 @item gnuplot @tab gnuplot @tab Haskell @tab haskell
-@item LaTeX @tab latex @tab Matlab @tab matlab
+@item LaTeX @tab latex @tab MATLAB @tab matlab
 @item Mscgen @tab mscgen @tab Objective Caml @tab ocaml
-@item Octave @tab octave @tab OZ @tab oz
+@item Octave @tab octave @tab Oz @tab oz
 @item Perl @tab perl @tab Python @tab python
 @item R @tab R @tab Ruby @tab ruby
 @item Sass @tab sass @tab GNU Screen @tab screen
 @item shell @tab sh @tab SQL @tab sql
-@item Sqlite @tab sqlite
+@item SQLite @tab sqlite
 @end multitable
 
 Language-specific documentation is available for some languages.  If
@@ -11789,7 +11814,7 @@ should be collected from the code block.
 @item @code{value}
 This is the default.  The result is the value of the last statement in the
 code block.  This header argument places the evaluation in functional
-mode.  Note that in some languages, e.g., python, use of this result type
+mode.  Note that in some languages, e.g., Python, use of this result type
 requires that a @code{return} statement be included in the body of the source
 code block. E.g., @code{:results value}.
 @item @code{output}
@@ -11834,7 +11859,7 @@ Result are assumed to be parseable code and are enclosed in a code block.
 E.g., @code{:results value code}.
 @item @code{pp}
 The result is converted to pretty-printed code and is enclosed in a code
-block.  This option currently supports Emacs Lisp, python, and ruby.  E.g.,
+block.  This option currently supports Emacs Lisp, Python, and Ruby.  E.g.,
 @code{:results value pp}.
 @end itemize
 
@@ -11872,7 +11897,7 @@ Note that for some languages, including R, gnuplot, LaTeX and ditaa,
 graphical output is sent to the specified file without the file being
 referenced explicitly in the code block. See the documentation for the
 individual languages for details. In contrast, general purpose languages such
-as python and ruby require that the code explicitly create output
+as Python and Ruby require that the code explicitly create output
 corresponding to the path indicated by @code{:file}.
 
 
@@ -11925,7 +11950,7 @@ and a link of the following form will be inserted in the org buffer:
 Most of this functionality follows immediately from the fact that @code{:dir}
 sets the value of the Emacs variable @code{default-directory}, thanks to
 tramp. Those using XEmacs, or GNU Emacs prior to version 23 may need to
-install tramp separately in order for the these features to work correctly.
+install tramp separately in order for these features to work correctly.
 
 @subsubheading Further points
 
@@ -11971,7 +11996,7 @@ The @code{:tangle} header argument specifies whether or not the code
 block should be included in tangled extraction of source code files.
 
 @itemize @bullet
-@item @code{yes}
+@item @code{tangle}
 The code block is exported to a source code file named after the
 basename (name w/o extension) of the Org-mode file.  E.g., @code{:tangle
 yes}.
@@ -12088,7 +12113,7 @@ values: @code{yes} or @code{no}.
 The default.  No caching takes place, and the code block will be evaluated
 every time it is called.
 @item @code{yes}
-Every time the code block is run a sha1 hash of the code and arguments
+Every time the code block is run a SHA1 hash of the code and arguments
 passed to the block will be generated.  This hash is packed into the
 @code{#+results:} line and will be checked on subsequent
 executions of the code block.  If the code block has not
@@ -12266,9 +12291,9 @@ vector of strings or numbers) when appropriate.
 This is the default. Internally, the value is obtained by wrapping the code
 in a function definition in the external language, and evaluating that
 function. Therefore, code should be written as if it were the body of such a
-function. In particular, note that python does not automatically return a
+function. In particular, note that Python does not automatically return a
 value from a function unless a @code{return} statement is present, and so a
-@samp{return} statement will usually be required in python.
+@samp{return} statement will usually be required in Python.
 
 This is the only one of the four evaluation contexts in which the code is
 automatically wrapped in a function definition.
@@ -12279,12 +12304,12 @@ contents of the standard output stream are returned as text. (In certain
 languages this also contains the error output stream; this is an area for
 future work.)
 
-@subsection @code{:session}
+@subsection Session
 @subsubsection @code{:results value}
 The code is passed to the interpreter running as an interactive Emacs
 inferior process. The result returned is the result of the last evaluation
 performed by the interpreter. (This is obtained in a language-specific
-manner: the value of the variable @code{_} in python and ruby, and the value
+manner: the value of the variable @code{_} in Python and Ruby, and the value
 of @code{.Last.value} in R).
 
 @subsubsection @code{:results output}
@@ -12307,7 +12332,7 @@ process. For example, compare the following two blocks:
 : bye
 @end example
 
-In non-session mode, the '2' is not printed and does not appear.
+In non-session mode, the `2' is not printed and does not appear.
 @example
 #+begin_src python :results output :session
  print "hello"
@@ -12321,8 +12346,8 @@ In non-session mode, the '2' is not printed and does not appear.
 : bye
 @end example
 
-But in @code{:session} mode, the interactive interpreter receives input '2'
-and prints out its value, '2'. (Indeed, the other print statements are
+But in @code{:session} mode, the interactive interpreter receives input `2'
+and prints out its value, `2'. (Indeed, the other print statements are
 unnecessary here).
 
 @node Noweb reference syntax, Key bindings and useful functions, Results of evaluation, Working With Source Code
@@ -12585,7 +12610,7 @@ beginning of a headline, i.e. before the first star.  Configure the variable
 pre-defined list of commands, and you can add more such commands using the
 variable @code{org-speed-commands-user}.  Speed keys do not only speed up
 navigation and other commands, but they also provide an alternative way to
-execute commands bound to keys that are not or not easily available on a tty,
+execute commands bound to keys that are not or not easily available on a TTY,
 or on a small mobile device with a limited keyboard.
 
 To see which commands are available, activate the feature and press @kbd{?}
@@ -12689,7 +12714,7 @@ applies.
 @vindex org-table-formula-constants
 @vindex org-table-formula
 Set file-local values for constants to be used in table formulas.  This
-line set the local variable @code{org-table-formula-constants-local}.
+line sets the local variable @code{org-table-formula-constants-local}.
 The global version of this variable is
 @code{org-table-formula-constants}.
 @item #+FILETAGS: :tag1:tag2:tag3:
@@ -12710,7 +12735,7 @@ These lines (several are allowed) specify link abbreviations.
 @vindex org-default-priority
 This line sets the limits and the default for the priorities.  All three
 must be either letters A-Z or numbers 0-9.  The highest priority must
-have a lower ASCII number that the lowest priority.
+have a lower ASCII number than the lowest priority.
 @item #+PROPERTY: Property_Name Value
 This line sets a default inheritance value for entries in the current
 buffer, most useful for specifying the allowed values of a property.
@@ -12891,12 +12916,12 @@ hideblocks   @r{Hide all begin/end blocks on startup}
 nohideblocks @r{Do not hide blocks on startup}
 @end example
 @cindex org-pretty-entities
-The the display of entities as UTF8 characters is governed by the variable
+The display of entities as UTF-8 characters is governed by the variable
 @code{org-pretty-entities} and the keywords
 @cindex @code{entitiespretty}, STARTUP keyword
 @cindex @code{entitiesplain}, STARTUP keyword
 @example
-entitiespretty  @r{Show entities as UTF8 characters where possible}
+entitiespretty  @r{Show entities as UTF-8 characters where possible}
 entitiesplain   @r{Leave entities plain}
 @end example
 @item #+TAGS:  TAG1(c1) TAG2(c2)
@@ -13020,7 +13045,7 @@ individual files using
 #+STARTUP: indent
 @end example
 
-If you want a similar effect in earlier version of Emacs and/or Org, or if
+If you want a similar effect in an earlier version of Emacs and/or Org, or if
 you want the indentation to be hard space characters so that the plain text
 file looks as similar as possible to the Emacs display, Org supports you in
 the following way:
@@ -13283,7 +13308,7 @@ to have other replacement keys, look at the variable
 @item @file{yasnippet.el}
 @cindex @file{yasnippet.el}
 The way Org-mode binds the TAB key (binding to @code{[tab]} instead of
-@code{"\t"}) overrules yasnippets' access to this key.  The following code
+@code{"\t"}) overrules YASnippet's access to this key.  The following code
 fixed this problem:
 
 @lisp
@@ -13465,7 +13490,7 @@ can also set the @code{:description} property to provide a default for
 the link description when the link is later inserted into an Org
 buffer with @kbd{C-c C-l}.
 
-When is makes sense for your new link type, you may also define a function
+When it makes sense for your new link type, you may also define a function
 @code{org-PREFIX-complete-link} that implements special (e.g. completion)
 support for inserting such a link with @kbd{C-c C-l}.  Such a function should
 not accept any arguments, and return the full link with prefix.
@@ -13797,9 +13822,9 @@ others can benefit from your work.
 @cindex radio lists
 @cindex org-list-insert-radio-list
 
-Sending and receiving radio lists works exactly the same way than sending and
+Sending and receiving radio lists works exactly the same way as sending and
 receiving radio tables (@pxref{Radio tables}).  As for radio tables, you can
-insert radio lists templates in HTML, La@TeX{} and Texinfo modes by calling
+insert radio list templates in HTML, La@TeX{} and Texinfo modes by calling
 @code{org-list-insert-radio-list}.
 
 Here are the differences with radio tables:
@@ -13845,11 +13870,11 @@ specially marked regions that are updated by some user-written function.
 A good example for such a block is the clock table inserted by the
 command @kbd{C-c C-x C-r} (@pxref{Clocking work time}).
 
-Dynamic block are enclosed by a BEGIN-END structure that assigns a name
+Dynamic blocks are enclosed by a BEGIN-END structure that assigns a name
 to the block and can also specify parameters for the function producing
 the content of the block.
 
-#+BEGIN:dynamic block
+@cindex #+BEGIN:dynamic block
 @example
 #+BEGIN: myblock :parameter1 value1 :parameter2 value2 ...
 
@@ -14030,7 +14055,7 @@ You may also modify parameters on the fly like this:
 @example
 emacs -batch -l ~/.emacs                                      \
    -eval '(org-batch-agenda "a"                               \
-            org-agenda-ndays 30                               \
+            org-agenda-span month                             \
             org-agenda-include-diary nil                      \
             org-agenda-files (quote ("~/org/project.org")))'  \
    | lpr
@@ -14166,7 +14191,7 @@ values and check if VALUE is in this list.
 @end defun
 
 @defopt org-property-allowed-value-functions
-Hook for functions supplying allowed values for specific.
+Hook for functions supplying allowed values for a specific property.
 The functions must take a single argument, the name of the property, and
 return a flat list of allowed values.  If @samp{:ETC} is one of
 the values, use the values as completion help, but allow also other values
@@ -14318,7 +14343,7 @@ in-buffer settings, but it will understand the logistics of TODO state
 @node Setting up the staging area, Pushing to MobileOrg, MobileOrg, MobileOrg
 @section Setting up the staging area
 
-MobileOrg needs to interact with Emacs through directory on a server.  If you
+MobileOrg needs to interact with Emacs through a directory on a server.  If you
 are using a public server, you should consider to encrypt the files that are
 uploaded to the server.  This can be done with Org-mode 7.02 and with
 @i{MobileOrg 1.5} (iPhone version), and you need an @file{openssl}
@@ -14333,8 +14358,7 @@ variable.  Note that encryption will apply only to the contents of the
 The easiest way to create that directory is to use a free
 @uref{http://dropbox.com,Dropbox.com} account@footnote{If you cannot use
 Dropbox, or if your version of MobileOrg does not support it, you can use a
-webdav server.  For more information, check out the the documentation of
-MobileOrg and also this
+webdav server.  For more information, check out the documentation of MobileOrg and also this
 @uref{http://orgmode.org/worg/org-faq.php#mobileorg_webdav, FAQ entry}.}.
 When MobileOrg first connects to your Dropbox, it will create a directory
 @i{MobileOrg} inside the Dropbox.  After the directory has been created, tell
@@ -14354,7 +14378,7 @@ This operation copies all files currently listed in @code{org-mobile-files}
 to the directory @code{org-mobile-directory}.  By default this list contains
 all agenda files (as listed in @code{org-agenda-files}), but additional files
 can be included by customizing @code{org-mobiles-files}.  File names will be
-staged with path relative to @code{org-directory}, so all files should be
+staged with paths relative to @code{org-directory}, so all files should be
 inside this directory.  The push operation also creates a special Org file
 @file{agendas.org} with all custom agenda view defined by the
 user@footnote{While creating the agendas, Org-mode will force ID properties
@@ -14408,7 +14432,7 @@ another window and also push it onto the kill ring.  So you could use @kbd{?
 z C-y C-c C-c} to store that flagging note as a normal note in the entry.
 Pressing @kbd{?} twice in succession will offer to remove the
 @code{:FLAGGED:} tag along with the recorded flagging note (which is stored
-in a property).  In this way you indicate, that the intended processing for
+in a property).  In this way you indicate that the intended processing for
 this flagged entry is finished.
 @end table
 @end enumerate
@@ -14607,7 +14631,7 @@ and being able to quickly restrict the agenda to a subtree.
 @i{Tim O'Callaghan} suggested in-file links, search options for general
 file links, and TAGS.
 @item
-@i{Osamu Okano} wrote @file{orgcard2ref.pl}, a perl program to create a text
+@i{Osamu Okano} wrote @file{orgcard2ref.pl}, a Perl program to create a text
 version of the reference card.
 @item
 @i{Takeshi Okano} translated the manual and David O'Toole's tutorial

+ 29 - 25
doc/orgcard.tex

@@ -266,6 +266,11 @@ are preserved on all copies.
 \def\threecol#1#2#3{\hskip\keyindent\relax#1\hfil&\kbd{#2}\hfil\quad
   &\kbd{#3}\hfil\quad\cr}
 
+\def\noteone{{\small \hfill [1]}}
+\def\notetwo{{\small \hfill [2]}}
+\def\notethree{{\small \hfill [3]}}
+
+
 %**end of header
 
 
@@ -298,7 +303,7 @@ are preserved on all copies.
 \key{next/previous heading, same level}{C-c C-f/b}
 \key{backward to higher level heading}{C-c C-u}
 \key{jump to another place in document}{C-c C-j}
-\key{previous/next plain list item}{S-UP/DOWN$^3$}
+\key{previous/next plain list item}{S-UP/DOWN\notethree}
 
 \section{Structure Editing}
 
@@ -310,17 +315,16 @@ are preserved on all copies.
 \key{turn item/line into headline}{C-c *}
 \key{promote/demote heading}{M-LEFT/RIGHT}
 \metax{promote/demote current subtree}{M-S-LEFT/RIGHT}
-
 \metax{move subtree/list item up/down}{M-S-UP/DOWN}
 \metax{sort subtree/region/plain-list}{C-c \^{}}
 \metax{clone a subtree}{C-c C-x c}
-\metax{refile subtree}{C-c C-w}
 \metax{kill/copy subtree}{C-c C-x C-w/M-w}
 \metax{yank subtree}{C-c C-x C-y or C-y}
 \metax{narrow buffer to subtree / widen}{C-x n s/w}
 
-\section{Archiving}
-
+\section{Capture - Refile - Archiving}
+\key{capture a new item (C-u C-u = goto last)}{C-c c \noteone}
+\key{refile subtree (C-u C-u = goto last)}{C-c C-w}
 \key{archive subtree using the default command}{C-c C-x C-a}
 \key{move subtree to archive file}{C-c C-x C-s}
 \key{toggle ARCHIVE tag / to ARCHIVE sibling}{C-c C-x a/A}
@@ -330,7 +334,7 @@ are preserved on all copies.
 
 \key{construct a sparse tree by various criteria}{C-c /}
 \key{view TODO's in sparse tree}{C-c / t/T}
-\key{global TODO list in agenda mode}{C-c a t$^1$}
+\key{global TODO list in agenda mode}{C-c a t \noteone}
 \key{time sorted view of current org file}{C-c a L}
 
 \section{Tables}
@@ -428,7 +432,7 @@ formula, \kbd{:=} a field formula.
 
 \section{Links}
 
-\key{globally store link to the current location}{C-c l$^1$}
+\key{globally store link to the current location}{C-c l \noteone}
 \key{insert a link (TAB completes stored links)}{C-c C-l}
 \key{insert file link with file name completion}{C-u C-c C-l}
 \key{edit (also hidden part of) link at point}{C-c C-l}
@@ -447,7 +451,7 @@ formula, \kbd{:=} a field formula.
 % {\bf Internal Links}
 
 % \key{\kbd{<<My Target>>}}{\rm target}
-% \key{\kbd{<<<My Target>>>}}{\rm radio target$^2$}
+% \key{\kbd{<<<My Target>>>}}{\rm radio target \notetwo}
 % \key{\kbd{[[*this text]]}}{\rm find headline}
 % \metax{\kbd{[[this text]]}}{\rm find target or text in buffer}
 % \metax{\kbd{[[this text][description]]}}{\rm optional link text}
@@ -538,8 +542,8 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 
 \key{set the priority of the current item}{C-c , [ABC]}
 \key{remove priority cookie from current item}{C-c , SPC}
-\key{raise/lower priority of current item}{S-UP/DOWN$^3$}
-%\key{lower priority of current item}{S-DOWN$^3$}
+\key{raise/lower priority of current item}{S-UP/DOWN\notethree}
+%\key{lower priority of current item}{S-DOWN \notethree}
 
 %\key{\kbd{\#+SEQ_TODO: TODO TRY BLUFF DONE}}{\rm todo workflow}
 %\key{\kbd{\#+TYP_TODO: Phil home work DONE}}{\rm todo types}
@@ -585,8 +589,8 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 \key{insert SCHEDULED timestamp}{C-c C-s}
 \key{create sparse tree with all deadlines due}{C-c / d}
 \key{the time between 2 dates in a time range}{C-c C-y}
-\key{change timestamp at cursor by $\pm 1$ day}{S-RIGHT/LEFT$^3$}
-\key{change year/month/day at cursor by $\pm 1$}{S-UP/DOWN$^3$}
+\metax{change timestamp at cursor $\pm 1$ day}{S-RIGHT/LEFT\notethree}
+\key{change year/month/day at cursor by $\pm 1$}{S-UP/DOWN\notethree}
 \key{access the calendar for the current date}{C-c >}
 \key{insert timestamp matching date in calendar}{C-c <}
 \key{access agenda for current date}{C-c C-o}
@@ -615,15 +619,15 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 \key{cycle through agenda file list}{C-'}
 \key{set/remove restriction lock}{C-c C-x </>}
 
-\key{compile agenda for the current week}{C-c a a$^1$}
+\key{compile agenda for the current week}{C-c a a \noteone}
 \key{compile global TODO list}{C-c a t$^1$}
-\key{compile TODO list for specific keyword}{C-c a T$^1$}
-\key{match tags, TODO kwds, properties}{C-c a m$^1$}
-\key{match only in TODO entries}{C-c a M$^1$}
-\key{find stuck projects}{C-c a \#$^1$}
-\key{show timeline of current org file}{C-c a L$^1$}
-\key{configure custom commands}{C-c a C$^1$}
-%\key{configure stuck projects}{C-c a !$^1$}
+\key{compile TODO list for specific keyword}{C-c a T \noteone}
+\key{match tags, TODO kwds, properties}{C-c a m \noteone}
+\key{match only in TODO entries}{C-c a M \noteone}
+\key{find stuck projects}{C-c a \# \noteone}
+\key{show timeline of current org file}{C-c a L \noteone}
+\key{configure custom commands}{C-c a C \noteone}
+%\key{configure stuck projects}{C-c a ! \noteone}
 \key{agenda for date at cursor}{C-c C-o}
 
 {\bf Commands available in an agenda buffer}
@@ -664,10 +668,10 @@ after  ``{\tt :}'', and dictionary words elsewhere.
 \key{set/show tags of current headline}{: / T}
 \key{set effort property (prefix=nth)}{e}
 \key{set / compute priority of current item}{, / P}
-\key{raise/lower priority of current item}{S-UP/DOWN$^3$}
+\key{raise/lower priority of current item}{S-UP/DOWN\notethree}
 \key{run an attachment command}{C-c C-a}
 \key{schedule/set deadline for this item}{C-c C-s/d}
-\key{change timestamp to one day earlier/later}{S-LEFT/RIGHT$^3$}
+\metax{change timestamp one day earlier/later}{S-LEFT/RIGHT\notethree}
 \key{change timestamp to today}{>}
 \key{insert new entry into diary}{i}
 \newcolumn
@@ -763,13 +767,13 @@ never exported.
 \metax{update all dynamic blocks}{C-u C-c C-x C-u}
 
 \section{Notes}
-$^1$ This is only a suggestion for a binding of this command.  Choose
+[1] This is only a suggestion for a binding of this command.  Choose
 your own key as shown under INSTALLATION.
 
-$^2$ After changing a \kbd{\#+KEYWORD} or \kbd{<<<target>>>} line,
+[2] After changing a \kbd{\#+KEYWORD} or \kbd{<<<target>>>} line,
 press \kbd{C-c C-c} with the cursor still in the line to update.
 
-$^3$ Keybinding affected by {\tt org-support-shift-select} and
+[3] Keybinding affected by {\tt org-support-shift-select} and
  {\tt org-replace-disputed-keys}.
 
 \copyrightnotice

+ 3 - 3
doc/orgguide.texi

@@ -1931,9 +1931,9 @@ Delete other windows.
 Switch to day/week view. 
 @c
 @item f @r{and} b
-Go forward/backward in time to display the following @code{org-agenda-ndays}
-days.  For example, if the display covers a week, switch to the
-following/previous week.
+Go forward/backward in time to display the following
+@code{org-agenda-current-span} days.  For example, if the display covers a
+week, switch to the following/previous week.
 @c
 @item .
 Go to today.

+ 12 - 10
lisp/ob-R.el

@@ -276,16 +276,18 @@ last statement in BODY, as elisp."
       (butlast
        (delq nil
 	     (mapcar
-	      (lambda (line) ;; cleanup extra prompts left in output
-		(if (string-match
-		     "^\\([ ]*[>+][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line)
-		    (substring line (match-end 1))
-		  line))
-	      (org-babel-comint-with-output (session org-babel-R-eoe-output)
-		(insert (mapconcat #'org-babel-chomp
-				   (list body org-babel-R-eoe-indicator)
-				   "\n"))
-		(inferior-ess-send-input)))) 2) "\n"))))
+	      (lambda (line) (when (> (length line) 0) line))
+	      (mapcar
+	       (lambda (line) ;; cleanup extra prompts left in output
+		 (if (string-match
+		      "^\\([ ]*[>+][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line)
+		     (substring line (match-end 1))
+		   line))
+	       (org-babel-comint-with-output (session org-babel-R-eoe-output)
+		 (insert (mapconcat #'org-babel-chomp
+				    (list body org-babel-R-eoe-indicator)
+				    "\n"))
+		 (inferior-ess-send-input)))))) "\n"))))
 
 (defun org-babel-R-process-value-result (result column-names-p)
   "R-specific processing of return value.

+ 2 - 2
lisp/ob-clojure.el

@@ -28,7 +28,7 @@
 
 ;;; Requirements:
 
-;;; A working clojure install. This also implies a working java executable
+;;; - clojure (at least 1.2.0)
 ;;; - clojure-mode
 ;;; - slime
 ;;; - swank-clojure
@@ -63,7 +63,7 @@
     (if (or (member "code" result-params)
 	    (member "pp" result-params))
 	(format (concat "(let [org-mode-print-catcher (java.io.StringWriter.)]"
-			"(with-pprint-dispatch %s-dispatch"
+			"(clojure.pprint/with-pprint-dispatch %s-dispatch"
 			"(clojure.pprint/pprint %s org-mode-print-catcher)"
 			"(str org-mode-print-catcher)))")
 		(if (member "code" result-params) "code" "simple") body)

+ 0 - 1
lisp/ob-eval.el

@@ -28,7 +28,6 @@
 ;; shell commands.
 
 ;;; Code:
-(require 'ob)
 (eval-when-compile (require 'cl))
 
 (defvar org-babel-error-buffer-name "*Org-Babel Error Output*")

+ 21 - 17
lisp/ob-python.el

@@ -58,12 +58,13 @@ This function is called by `org-babel-execute-src-block'."
          (result-type (cdr (assoc :result-type params)))
 	 (return-val (when (and (eq result-type 'value) (not session))
 		       (cdr (assoc :return params))))
+	 (preamble (cdr (assoc :preamble params)))
          (full-body
 	  (org-babel-expand-body:generic
 	   (concat body (if return-val (format "return %s" return-val) ""))
 	   params (org-babel-variable-assignments:python params)))
          (result (org-babel-python-evaluate
-		  session full-body result-type result-params)))
+		  session full-body result-type result-params preamble)))
     (or (cdr (assoc :file params))
         (org-babel-reassemble-table
          result
@@ -181,35 +182,38 @@ def main():
 open('%s', 'w').write( pprint.pformat(main()) )")
 
 (defun org-babel-python-evaluate
-  (session body &optional result-type result-params)
+  (session body &optional result-type result-params preamble)
   "Evaluate BODY as python code."
   (if session
       (org-babel-python-evaluate-session
        session body result-type result-params)
     (org-babel-python-evaluate-external-process
-     body result-type result-params)))
+     body result-type result-params preamble)))
 
 (defun org-babel-python-evaluate-external-process
-  (body &optional result-type result-params)
+  (body &optional result-type result-params preamble)
   "Evaluate BODY in external python process.
 If RESULT-TYPE equals 'output then return standard output as a
 string. If RESULT-TYPE equals 'value then return the value of the
 last statement in BODY, as elisp."
   (case result-type
-    (output (org-babel-eval org-babel-python-command body))
+    (output (org-babel-eval org-babel-python-command
+			    (concat (if preamble (concat preamble "\n") "") body)))
     (value (let ((tmp-file (org-babel-temp-file "python-")))
 	     (org-babel-eval org-babel-python-command
-			     (format
-			      (if (member "pp" result-params)
-				  org-babel-python-pp-wrapper-method
-				org-babel-python-wrapper-method)
-			      (mapconcat
-			       (lambda (line) (format "\t%s" line))
-			       (split-string
-				(org-remove-indentation
-				 (org-babel-trim body))
-				"[\r\n]") "\n")
-			      (org-babel-process-file-name tmp-file 'noquote)))
+			     (concat
+			      (if preamble (concat preamble "\n") "")
+			      (format
+			       (if (member "pp" result-params)
+				   org-babel-python-pp-wrapper-method
+				 org-babel-python-wrapper-method)
+			       (mapconcat
+				(lambda (line) (format "\t%s" line))
+				(split-string
+				 (org-remove-indentation
+				  (org-babel-trim body))
+				 "[\r\n]") "\n")
+			       (org-babel-process-file-name tmp-file 'noquote))))
 	     ((lambda (raw)
 		(if (or (member "code" result-params)
 			(member "pp" result-params))
@@ -229,7 +233,7 @@ last statement in BODY, as elisp."
 	   (lambda (statement) (insert statement) (comint-send-input))
 	   (if pp
 	       (list
-		"import pp"
+		"import pprint"
 		(format "open('%s', 'w').write(pprint.pformat(_))"
 			(org-babel-process-file-name tmp-file 'noquote)))
 	     (list (format "open('%s', 'w').write(str(_))"

+ 34 - 2
lisp/ob-sql.el

@@ -47,9 +47,15 @@
 (eval-when-compile (require 'cl))
 
 (declare-function org-table-import "org-table" (file arg))
+(declare-function orgtbl-to-csv "org-table" (TABLE PARAMS))
 
 (defvar org-babel-default-header-args:sql '())
 
+(defun org-babel-expand-body:sql (body params)
+  "Expand BODY according to the values of PARAMS."
+  (org-babel-sql-expand-vars
+   body (mapcar #'cdr (org-babel-get-header params :var))))
+
 (defun org-babel-execute:sql (body params)
   "Execute a block of Sql code with Babel.
 This function is called by `org-babel-execute-src-block'."
@@ -60,6 +66,10 @@ This function is called by `org-babel-execute-src-block'."
          (out-file (or (cdr (assoc :out-file params))
                        (org-babel-temp-file "sql-out-")))
          (command (case (intern engine)
+                    ('msosql (format "osql %s -s \"\t\" -i %s -o %s"
+                                     (or cmdline "")
+                                     (org-babel-process-file-name in-file)
+                                     (org-babel-process-file-name out-file)))
                     ('mysql (format "mysql %s -e \"source %s\" > %s"
                                     (or cmdline "")
 				    (org-babel-process-file-name in-file)
@@ -70,11 +80,11 @@ This function is called by `org-babel-execute-src-block'."
 				    (or cmdline "")))
                     (t (error "no support for the %s sql engine" engine)))))
     (with-temp-file in-file
-      (insert (org-babel-expand-body:generic body params)))
+      (insert (org-babel-expand-body:sql body params)))
     (message command)
     (shell-command command)
     (with-temp-buffer
-      (org-table-import out-file nil)
+      (org-table-import out-file '(16))
       (org-babel-reassemble-table
        (org-table-to-lisp)
        (org-babel-pick-name (cdr (assoc :colname-names params))
@@ -82,6 +92,28 @@ This function is called by `org-babel-execute-src-block'."
        (org-babel-pick-name (cdr (assoc :rowname-names params))
 			    (cdr (assoc :rownames params)))))))
 
+(defun org-babel-sql-expand-vars (body vars)
+  "Expand the variables held in VARS in BODY."
+  (mapc
+   (lambda (pair)
+     (setq body
+	   (replace-regexp-in-string
+	    (format "\$%s" (car pair))
+	    ((lambda (val)
+	       (if (listp val)
+		   ((lambda (data-file)
+		      (with-temp-file data-file
+			(insert (orgtbl-to-csv
+				 val '(:fmt (lambda (el) (if (stringp el)
+							el
+						      (format "%S" el)))))))
+		      data-file)
+		    (org-babel-temp-file "sql-data-"))
+		 (if (stringp val) val (format "%S" val))))
+	     (cdr pair))
+	    body)))
+   vars)
+  body)
 
 (defun org-babel-prep-session:sql (session params)
   "Raise an error because Sql sessions aren't implemented."

+ 0 - 1
lisp/ob-sqlite.el

@@ -53,7 +53,6 @@
   "Execute a block of Sqlite code with Babel.
 This function is called by `org-babel-execute-src-block'."
   (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
-	(vars (org-babel-get-header params :var))
 	(db (cdr (assoc :db params)))
 	(separator (cdr (assoc :separator params)))
 	(nullvalue (cdr (assoc :nullvalue params)))

+ 13 - 10
lisp/ob.el

@@ -32,6 +32,7 @@
 (eval-when-compile
   (require 'org-list)
   (require 'cl))
+(require 'ob-eval)
 (require 'org-macs)
 
 (defvar org-babel-call-process-region-original)
@@ -78,7 +79,6 @@
 (declare-function org-list-to-generic "org-list" (LIST PARAMS))
 (declare-function org-list-bottom-point "org-list" ())
 
-(declare-function org-babel-eval-wipe-error-buffer "ob-eval" ())
 (defgroup org-babel nil
   "Code block evaluation and management in `org-mode' documents."
   :tag "Babel"
@@ -218,8 +218,10 @@ of potentially harmful code."
     (if (or (equal eval "never") (equal eval "no")
 	    (and query
 		 (not (yes-or-no-p
-		       (format "Evaluate this%scode on your system? "
-			       (if info (format " %s " (nth 0 info)) " "))))))
+		       (format "Evaluate this%scode block%son your system? "
+			       (if info (format " %s " (nth 0 info)) " ")
+			       (if (nth 4 info)
+				   (format " (%s) " (nth 4 info)) " "))))))
 	(prog1 nil (message "Evaluation %s"
 			    (if (or (equal eval "never") (equal eval "no"))
 				"Disabled" "Aborted")))
@@ -1440,7 +1442,7 @@ code ---- the results are extracted in the syntax of the source
 	   ((member "replace" result-params)
 	    (delete-region (point) (org-babel-result-end)))
 	   ((member "append" result-params)
-	    (goto-char (org-babel-result-end)) (setq beg (point)))
+	    (goto-char (org-babel-result-end)) (setq beg (point-marker)))
 	   ((member "prepend" result-params)))) ; already there
 	(setq results-switches
 	      (if results-switches (concat " " results-switches) ""))
@@ -1468,13 +1470,13 @@ code ---- the results are extracted in the syntax of the source
 	 ((member "file" result-params)
 	  (insert result))
 	 (t (goto-char beg) (insert result)))
-	(setq end (if (listp result) (org-table-end) (point)))
+	(when (listp result) (goto-char (org-table-end)))
+	(setq end (point-marker))
 	;; possibly wrap result
 	(flet ((wrap (start finish)
 		     (goto-char beg) (insert start)
-		     (goto-char
-		      (+ (if (and result (listp result)) 0 (length start)) end))
-		     (insert finish) (setq end (point))))
+		     (goto-char end) (insert finish)
+		     (setq end (point-marker))))
 	  (cond
 	   ((member "html" result-params)
 	    (wrap "#+BEGIN_HTML\n" "#+END_HTML"))
@@ -1492,7 +1494,8 @@ code ---- the results are extracted in the syntax of the source
 	      (org-babel-examplize-region beg end results-switches))
 	    (wrap "#+BEGIN_RESULT\n" "#+END_RESULT"))
 	   ((and (stringp result) (not (member "file" result-params)))
-	    (org-babel-examplize-region beg end results-switches))))
+	    (org-babel-examplize-region beg end results-switches)
+	    (setq end (point)))))
 	;; possibly indent the results to match the #+results line
 	(when (and indent (> indent 0)
 		   ;; in this case `table-align' does the work for us
@@ -1559,7 +1562,7 @@ file's directory then expand relative links."
 	     (insert (if results-switches
                          (format "#+begin_example%s\n" results-switches)
                        "#+begin_example\n"))
-	     (forward-char (- end beg))
+	     (if (markerp end) (goto-char end) (forward-char (- end beg)))
 	     (insert "#+end_example\n"))))))
 
 (defun org-babel-update-block-body (new-body)

+ 241 - 144
lisp/org-agenda.el

@@ -242,8 +242,12 @@ you can \"misuse\" it to also add other text to the header.  However,
 		  (const org-agenda-prefix-format :value "  %-12:c%?-12t% s")
 		  (string))
 	    (list :tag "Number of days in agenda"
-		  (const org-agenda-ndays)
-		  (integer :value 1))
+		  (const org-agenda-span)
+		  (choice (const :tag "Day" 'day)
+			  (const :tag "Week" 'week)
+			  (const :tag "Month" 'month)
+			  (const :tag "Year" 'year)
+			  (integer :tag "Custom")))
 	    (list :tag "Fixed starting date"
 		  (const org-agenda-start-day)
 		  (string :value "2007-11-01"))
@@ -562,6 +566,33 @@ See also the variable `org-agenda-tags-todo-honor-ignore-options'."
   :group 'org-agenda-todo-list
   :type 'boolean)
 
+(defcustom org-agenda-todo-ignore-timestamp nil
+  "Non-nil means don't show entries with a timestamp.
+This applies when creating the global todo list.
+Valid values are:
+
+past     Don't show entries for today or in the past.
+
+future   Don't show entries with a timestamp in the future.
+         The idea behind this is that if it has a future
+         timestamp, you don't want to think about it until the
+         date.
+
+all      Don't show any entries with a timestamp in the global todo list.
+         The idea behind this is that by setting a timestamp, you
+         have already \"taken care\" of this item.
+
+See also `org-agenda-todo-ignore-with-date'.
+See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
+to make his option also apply to the tags-todo list."
+  :group 'org-agenda-skip
+  :group 'org-agenda-todo-list
+  :type '(choice
+	  (const :tag "Ignore future timestamp todos" future)
+	  (const :tag "Ignore past or present timestamp todos" past)
+	  (const :tag "Ignore all timestamp todos" all)
+	  (const :tag "Show timestamp todos" nil)))
+
 (defcustom org-agenda-todo-ignore-scheduled nil
   "Non-nil means, ignore some scheduled TODO items when making TODO list.
 This applies when creating the global todo list.
@@ -632,7 +663,8 @@ to make his option also apply to the tags-todo list."
   "Non-nil means honor todo-list ...ignore options also in tags-todo search.
 The variables
    `org-agenda-todo-ignore-with-date',
-   `org-agenda-todo-ignore-scheduled'
+   `org-agenda-todo-ignore-timestamp',
+   `org-agenda-todo-ignore-scheduled',
    `org-agenda-todo-ignore-deadlines'
 make the global TODO list skip entries that have time stamps of certain
 kinds.  If this option is set, the same options will also apply for the
@@ -860,12 +892,25 @@ option will be ignored."
   :group 'org-agenda-windows
   :type 'boolean)
 
-(defcustom org-agenda-ndays 7
-  "Number of days to include in overview display.
+(defcustom org-agenda-ndays nil
+   "Number of days to include in overview display.
 Should be 1 or 7.
+Obsolete, see `org-agenda-span'."
+   :group 'org-agenda-daily/weekly
+   :type 'integer)
+
+(make-obsolete-variable 'org-agenda-ndays 'org-agenda-span "24.1")
+
+(defcustom org-agenda-span 'week
+  "Number of days to include in overview display.
+Can be day, week, month, year, or any number of days.
 Custom commands can set this variable in the options section."
   :group 'org-agenda-daily/weekly
-  :type 'integer)
+  :type '(choice (const :tag "Day" day)
+		 (const :tag "Week" week)
+		 (const :tag "Month" month)
+		 (const :tag "Year" year)
+		 (integer :tag "Custom")))
 
 (defcustom org-agenda-start-on-weekday 1
   "Non-nil means start the overview always on the specified weekday.
@@ -1797,19 +1842,19 @@ The following commands are available:
     ("View"
      ["Day View" org-agenda-day-view
       :active (org-agenda-check-type nil 'agenda)
-      :style radio :selected (equal org-agenda-ndays 1)
+      :style radio :selected (eq org-agenda-current-span 'day)
       :keys "v d  (or just d)"]
      ["Week View" org-agenda-week-view
       :active (org-agenda-check-type nil 'agenda)
-      :style radio :selected (equal org-agenda-ndays 7)
+      :style radio :selected (eq org-agenda-current-span 'week)
       :keys "v w  (or just w)"]
      ["Month View" org-agenda-month-view
       :active (org-agenda-check-type nil 'agenda)
-      :style radio :selected (member org-agenda-ndays '(28 29 30 31))
+      :style radio :selected (eq org-agenda-current-span 'month)
       :keys "v m"]
      ["Year View" org-agenda-year-view
       :active (org-agenda-check-type nil 'agenda)
-      :style radio :selected (member org-agenda-ndays '(365 366))
+      :style radio :selected (eq org-agenda-current-span 'year)
       :keys "v y"]
      "--"
      ["Include Diary" org-agenda-toggle-diary
@@ -3180,7 +3225,7 @@ dates."
 					 org-timeline-show-empty-dates))
 	 (org-deadline-warning-days 0)
 	 (org-agenda-only-exact-dates t)
-	 (today (org-agenda-today))
+	 (today (org-today))
 	 (past t)
 	 args
 	 s e rtn d emptyp)
@@ -3257,7 +3302,7 @@ When EMPTY is non-nil, also include days without any entries."
 	     (if inactive org-ts-regexp-both org-ts-regexp)))
 	 dates dates1 date day day1 day2 ts1 ts2)
     (if force-today
-	(setq dates (list (org-agenda-today))))
+	(setq dates (list (org-today))))
     (save-excursion
       (goto-char beg)
       (while (re-search-forward re end t)
@@ -3295,7 +3340,8 @@ When EMPTY is non-nil, also include days without any entries."
 (defvar org-agenda-last-arguments nil
   "The arguments of the previous call to `org-agenda'.")
 (defvar org-starting-day nil) ; local variable in the agenda buffer
-(defvar org-agenda-span nil) ; local variable in the agenda buffer
+(defvar org-agenda-current-span nil
+  "The current span used in the agenda view.") ; local variable in the agenda buffer
 (defvar org-include-all-loc nil) ; local variable
 
 (defvar org-agenda-entry-types '(:deadline :scheduled :timestamp :sexp)
@@ -3332,7 +3378,7 @@ somewhat less efficient) way of determining what is included in
 the daily/weekly agenda, see `org-agenda-skip-function'.")
 
 ;;;###autoload
-(defun org-agenda-list (&optional include-all start-day ndays)
+(defun org-agenda-list (&optional include-all start-day span)
   "Produce a daily/weekly view from all files in variable `org-agenda-files'.
 The view will be for the current day or week, but from the overview buffer
 you will be able to go to other days/weeks.
@@ -3343,35 +3389,36 @@ This feature is considered obsolete, please use the TODO list or a block
 agenda instead.
 
 With a numeric prefix argument in an interactive call, the agenda will
-span INCLUDE-ALL days.  Lisp programs should instead specify NDAYS to change
-the number of days.  NDAYS defaults to `org-agenda-ndays'.
+span INCLUDE-ALL days.  Lisp programs should instead specify SPAN to change
+the number of days.  SPAN defaults to `org-agenda-span'.
 
 START-DAY defaults to TODAY, or to the most recent match for the weekday
 given in `org-agenda-start-on-weekday'."
   (interactive "P")
   (if (and (integerp include-all) (> include-all 0))
-      (setq ndays include-all include-all nil))
-  (setq ndays (or ndays org-agenda-ndays)
-	start-day (or start-day org-agenda-start-day))
+      (setq span include-all include-all nil))
+  (setq start-day (or start-day org-agenda-start-day))
   (if org-agenda-overriding-arguments
       (setq include-all (car org-agenda-overriding-arguments)
 	    start-day (nth 1 org-agenda-overriding-arguments)
-	    ndays (nth 2 org-agenda-overriding-arguments)))
+	    span (nth 2 org-agenda-overriding-arguments)))
   (if (stringp start-day)
       ;; Convert to an absolute day number
       (setq start-day (time-to-days (org-read-date nil t start-day))))
-  (setq org-agenda-last-arguments (list include-all start-day ndays))
+  (setq org-agenda-last-arguments (list include-all start-day span))
   (org-compile-prefix-format 'agenda)
   (org-set-sorting-strategy 'agenda)
-  (let* ((org-agenda-start-on-weekday
-	  (if (or (equal ndays 7) (and (null ndays) (equal 7 org-agenda-ndays)))
-	      org-agenda-start-on-weekday nil))
+  (let* ((span (org-agenda-ndays-to-span (or span org-agenda-ndays org-agenda-span)))
+	 (today (org-today))
+	 (sd (or start-day today))
+	 (ndays (org-agenda-span-to-ndays span sd))
+	 (org-agenda-start-on-weekday
+	  (if (eq ndays 7)
+	      org-agenda-start-on-weekday))
 	 (thefiles (org-agenda-files nil 'ifmode))
 	 (files thefiles)
-	 (today (org-agenda-today))
-	 (sd (or start-day today))
 	 (start (if (or (null org-agenda-start-on-weekday)
-			(< org-agenda-ndays 7))
+			(< ndays 7))
 		    sd
 		  (let* ((nt (calendar-day-of-week
 			      (calendar-gregorian-from-absolute sd)))
@@ -3381,24 +3428,19 @@ given in `org-agenda-start-on-weekday'."
 	 (day-numbers (list start))
 	 (day-cnt 0)
 	 (inhibit-redisplay (not debug-on-error))
-	 s e rtn rtnall file date d start-pos end-pos todayp nd
+	 s e rtn rtnall file date d start-pos end-pos todayp
 	 clocktable-start clocktable-end filter)
     (setq org-agenda-redo-command
-	  (list 'org-agenda-list (list 'quote include-all) start-day ndays))
-    ;; Make the list of days
-    (setq ndays (or ndays org-agenda-ndays)
-	  nd ndays)
-    (while (> ndays 1)
-      (push (1+ (car day-numbers)) day-numbers)
-      (setq ndays (1- ndays)))
+	  (list 'org-agenda-list (list 'quote include-all) start-day (list 'quote span)))
+    (dotimes (n (1- ndays))
+      (push (1+ (car day-numbers)) day-numbers))
     (setq day-numbers (nreverse day-numbers))
     (setq clocktable-start (car day-numbers)
 	  clocktable-end (1+ (or (org-last day-numbers) 0)))
     (org-prepare-agenda "Day/Week")
     (org-set-local 'org-starting-day (car day-numbers))
     (org-set-local 'org-include-all-loc include-all)
-    (org-set-local 'org-agenda-span
-		   (org-agenda-ndays-to-span nd))
+    (org-set-local 'org-agenda-current-span (org-agenda-ndays-to-span span))
     (when (and (or include-all org-agenda-include-all-todo)
 	       (member today day-numbers))
       (setq files thefiles
@@ -3426,7 +3468,7 @@ given in `org-agenda-start-on-weekday'."
 	(if org-agenda-overriding-header
 	    (insert (org-add-props (copy-sequence org-agenda-overriding-header)
 			nil 'face 'org-agenda-structure) "\n")
-	  (insert (capitalize (symbol-name (org-agenda-ndays-to-span nd)))
+	  (insert (org-agenda-span-name span)
 		  "-agenda"
 		  (if (< (- d2 d1) 350)
 		      (if (= w1 w2)
@@ -3491,7 +3533,7 @@ given in `org-agenda-start-on-weekday'."
 	    (if rtnall (insert
 			(org-finalize-agenda-entries
 			 (org-agenda-add-time-grid-maybe
-			  rtnall nd todayp))
+			  rtnall ndays todayp))
 			"\n"))
 	    (put-text-property s (1- (point)) 'day d)
 	    (put-text-property s (1- (point)) 'org-day-cnt day-cnt))))
@@ -3532,7 +3574,31 @@ given in `org-agenda-start-on-weekday'."
     (message "")))
 
 (defun org-agenda-ndays-to-span (n)
-  (cond ((< n 7) 'day) ((= n 7) 'week) ((< n 32) 'month) (t 'year)))
+  "Return a span symbol for a span of N days, or N if none matches."
+  (cond ((symbolp n) n)
+	((= n 1) 'day)
+	((= n 7) 'week)
+	(t n)))
+
+(defun org-agenda-span-to-ndays (span start-day)
+  "Return ndays from SPAN starting at START-DAY."
+  (cond ((numberp span) span)
+	((eq span 'day) 1)
+	((eq span 'week) 7)
+	((eq span 'month)
+	 (let ((date (calendar-gregorian-from-absolute start-day)))
+	   (calendar-last-day-of-month (car date) (caddr date))))
+	((eq span 'year)
+	 (let ((date (calendar-gregorian-from-absolute start-day)))
+	   (if (calendar-leap-year-p (caddr date)) 366 365)))))
+
+(defun org-agenda-span-name (span)
+  "Return a SPAN name."
+  (if (null span)
+      ""
+    (if (symbolp span)
+	(capitalize (symbol-name span))
+      (format "%d days" span))))
 
 ;;; Agenda word search
 
@@ -3811,7 +3877,7 @@ for a keyword.  A numeric prefix directly selects the Nth keyword in
   (org-set-sorting-strategy 'todo)
   (org-prepare-agenda "TODO")
   (if (and (stringp arg) (not (string-match "\\S-" arg))) (setq arg nil))
-  (let* ((today (org-agenda-today))
+  (let* ((today (org-today))
 	 (date (calendar-gregorian-from-absolute today))
 	 (kwds org-todo-keywords-for-agenda)
 	 (completion-ignore-case t)
@@ -4435,7 +4501,8 @@ the documentation of `org-diary'."
   "Do we have a reason to ignore this TODO entry because it has a time stamp?"
   (when (or org-agenda-todo-ignore-with-date
 	    org-agenda-todo-ignore-scheduled
-	    org-agenda-todo-ignore-deadlines)
+	    org-agenda-todo-ignore-deadlines
+	    org-agenda-todo-ignore-timestamp)
     (setq end (or end (save-excursion (outline-next-heading) (point))))
     (save-excursion
       (or (and org-agenda-todo-ignore-with-date
@@ -4458,7 +4525,29 @@ the documentation of `org-diary'."
 		 (> (org-days-to-time (match-string 1)) 0))
 		((eq org-agenda-todo-ignore-deadlines 'past)
 		 (<= (org-days-to-time (match-string 1)) 0))
-		(t (org-deadline-close (match-string 1)))))))))
+		(t (org-deadline-close (match-string 1)))))
+	  (and org-agenda-todo-ignore-timestamp
+	       (let ((buffer (current-buffer))
+		     (regexp
+		      (concat
+		       org-scheduled-time-regexp "\\|" org-deadline-time-regexp))
+		     (start (point)))
+		 ;; Copy current buffer into a temporary one
+		 (with-temp-buffer
+		   (insert-buffer-substring buffer start end)
+		   (goto-char (point-min))
+		   ;; Delete SCHEDULED and DEADLINE items
+		   (while (re-search-forward regexp end t)
+		     (delete-region (match-beginning 0) (match-end 0)))
+		   (goto-char (point-min))
+		   ;; No search for timestamp left
+		   (when (re-search-forward org-ts-regexp nil t)
+		     (cond
+		      ((eq org-agenda-todo-ignore-timestamp 'future)
+		       (> (org-days-to-time (match-string 1)) 0))
+		      ((eq org-agenda-todo-ignore-timestamp 'past)
+		       (<= (org-days-to-time (match-string 1)) 0))
+		      (t))))))))))
 
 (defconst org-agenda-no-heading-message
   "No heading for this item in buffer or region.")
@@ -5044,7 +5133,9 @@ Any match of REMOVE-RE will be removed from TXT."
 	       org-agenda-show-inherited-tags
 	       org-agenda-hide-tags-regexp))
     (let* ((category (or category
-			 org-category
+			 (if (stringp org-category)
+			     org-category
+			   (and org-category (symbol-name org-category)))
 			 (if buffer-file-name
 			     (file-name-sans-extension
 			      (file-name-nondirectory buffer-file-name))
@@ -5947,11 +6038,10 @@ Negative selection means regexp must not match for selection of an entry."
     (cond
      (tdpos (goto-char tdpos))
      ((eq org-agenda-type 'agenda)
-      (let* ((sd (org-agenda-today))
-	     (comp (org-agenda-compute-time-span sd org-agenda-span))
+      (let* ((sd (org-agenda-compute-starting-span
+		  (org-today) (or org-agenda-ndays org-agenda-span)))
 	     (org-agenda-overriding-arguments org-agenda-last-arguments))
-	(setf (nth 1 org-agenda-overriding-arguments) (car comp))
-	(setf (nth 2 org-agenda-overriding-arguments) (cdr comp))
+	(setf (nth 1 org-agenda-overriding-arguments) sd)
 	(org-agenda-redo)
 	(org-agenda-find-same-or-today-or-agenda)))
      (t (error "Cannot find today")))))
@@ -5968,28 +6058,28 @@ Negative selection means regexp must not match for selection of an entry."
 With prefix ARG, go forward that many times the current span."
   (interactive "p")
   (org-agenda-check-type t 'agenda)
-  (let* ((span org-agenda-span)
+  (let* ((span org-agenda-current-span)
 	 (sd org-starting-day)
 	 (greg (calendar-gregorian-from-absolute sd))
 	 (cnt (org-get-at-bol 'org-day-cnt))
-	 greg2 nd)
+	 greg2)
     (cond
      ((eq span 'day)
-      (setq sd (+ arg sd) nd 1))
+      (setq sd (+ arg sd)))
      ((eq span 'week)
-      (setq sd (+ (* 7 arg) sd) nd 7))
+      (setq sd (+ (* 7 arg) sd)))
      ((eq span 'month)
       (setq greg2 (list (+ (car greg) arg) (nth 1 greg) (nth 2 greg))
 	    sd (calendar-absolute-from-gregorian greg2))
-      (setcar greg2 (1+ (car greg2)))
-      (setq nd (- (calendar-absolute-from-gregorian greg2) sd)))
+      (setcar greg2 (1+ (car greg2))))
      ((eq span 'year)
       (setq greg2 (list (car greg) (nth 1 greg) (+ arg (nth 2 greg)))
 	    sd (calendar-absolute-from-gregorian greg2))
-      (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2)))
-      (setq nd (- (calendar-absolute-from-gregorian greg2) sd))))
+      (setcar (nthcdr 2 greg2) (1+ (nth 2 greg2))))
+     (t
+      (setq sd (+ (* span arg) sd))))
     (let ((org-agenda-overriding-arguments
-	   (list (car org-agenda-last-arguments) sd nd t)))
+	   (list (car org-agenda-last-arguments) sd span t)))
       (org-agenda-redo)
       (org-agenda-find-same-or-today-or-agenda cnt))))
 
@@ -6032,7 +6122,6 @@ With prefix ARG, go backward that many times the current span."
   "Switch to daily view for agenda.
 With argument DAY-OF-YEAR, switch to that day of the year."
   (interactive "P")
-  (setq org-agenda-ndays 1)
   (org-agenda-change-time-span 'day day-of-year))
 (defun org-agenda-week-view (&optional iso-week)
   "Switch to daily view for agenda.
@@ -6042,7 +6131,6 @@ week.  Any digits before this encode a year.  So 200712 means
 week 12 of year 2007.  Years in the range 1938-2037 can also be
 written as 2-digit years."
   (interactive "P")
-  (setq org-agenda-ndays 7)
   (org-agenda-change-time-span 'week iso-week))
 (defun org-agenda-month-view (&optional month)
   "Switch to monthly view for agenda.
@@ -6067,70 +6155,61 @@ written as 2-digit years."
   "Change the agenda view to SPAN.
 SPAN may be `day', `week', `month', `year'."
   (org-agenda-check-type t 'agenda)
-  (if (and (not n) (equal org-agenda-span span))
+  (if (and (not n) (equal org-agenda-current-span span))
       (error "Viewing span is already \"%s\"" span))
   (let* ((sd (or (org-get-at-bol 'day)
 		org-starting-day))
-	 (computed (org-agenda-compute-time-span sd span n))
+	 (sd (org-agenda-compute-starting-span sd span n))
 	 (org-agenda-overriding-arguments
-	  (list (car org-agenda-last-arguments)
-		(car computed) (cdr computed) t)))
+	  (list (car org-agenda-last-arguments) sd span t)))
     (org-agenda-redo)
     (org-agenda-find-same-or-today-or-agenda))
   (org-agenda-set-mode-name)
   (message "Switched to %s view" span))
 
-(defun org-agenda-compute-time-span (sd span &optional n)
-  "Compute starting date and number of days for agenda.
+(defun org-agenda-compute-starting-span (sd span &optional n)
+  "Compute starting date for agenda.
 SPAN may be `day', `week', `month', `year'.  The return value
 is a cons cell with the starting date and the number of days,
 so that the date SD will be in that range."
   (let* ((greg (calendar-gregorian-from-absolute sd))
 	 (dg (nth 1 greg))
 	 (mg (car greg))
-	 (yg (nth 2 greg))
-	 nd w1 y1 m1 thisweek)
+	 (yg (nth 2 greg)))
     (cond
      ((eq span 'day)
       (when n
 	(setq sd (+ (calendar-absolute-from-gregorian
 		     (list mg 1 yg))
-		    n -1)))
-      (setq nd 1))
+		    n -1))))
      ((eq span 'week)
       (let* ((nt (calendar-day-of-week
 		  (calendar-gregorian-from-absolute sd)))
 	     (d (if org-agenda-start-on-weekday
 		    (- nt org-agenda-start-on-weekday)
-		  0)))
+		  0))
+	     y1)
 	(setq sd (- sd (+ (if (< d 0) 7 0) d)))
 	(when n
 	  (require 'cal-iso)
-	  (setq thisweek (car (calendar-iso-from-absolute sd)))
 	  (when (> n 99)
 	    (setq y1 (org-small-year-to-year (/ n 100))
 		  n (mod n 100)))
 	  (setq sd
 		(calendar-absolute-from-iso
 		 (list n 1
-		       (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))
-	(setq nd 7)))
+		       (or y1 (nth 2 (calendar-iso-from-absolute sd)))))))))
      ((eq span 'month)
-      (when (and n (> n 99))
-	(setq y1 (org-small-year-to-year (/ n 100))
-	      n (mod n 100)))
-      (setq sd (calendar-absolute-from-gregorian
-		(list (or n mg) 1 (or y1 yg)))
-	    nd (- (calendar-absolute-from-gregorian
-		   (list (1+ (or n mg)) 1 (or y1 yg)))
-		  sd)))
+      (let (y1)
+	(when (and n (> n 99))
+	  (setq y1 (org-small-year-to-year (/ n 100))
+		n (mod n 100)))
+	(setq sd (calendar-absolute-from-gregorian
+		  (list (or n mg) 1 (or y1 yg))))))
      ((eq span 'year)
       (setq sd (calendar-absolute-from-gregorian
-		(list 1 1 (or n yg)))
-	    nd (- (calendar-absolute-from-gregorian
-		   (list 1 1 (1+ (or n yg))))
-		  sd))))
-    (cons sd nd)))
+		(list 1 1 (or n yg))))))
+    sd))
 
 (defun org-agenda-next-date-line (&optional arg)
   "Jump to the next line indicating a date in agenda buffer."
@@ -6261,7 +6340,7 @@ When called with a prefix argument, include all archive files as well."
 	   (if org-agenda-include-diary "on" "off")))
 
 (defun org-agenda-toggle-deadlines ()
-  "Toggle diary inclusion in an agenda buffer."
+  "Toggle inclusion of entries with a deadline in an agenda buffer."
   (interactive)
   (org-agenda-check-type t 'agenda)
   (setq org-agenda-include-deadlines (not org-agenda-include-deadlines))
@@ -6283,36 +6362,36 @@ When called with a prefix argument, include all archive files as well."
 (defun org-agenda-set-mode-name ()
   "Set the mode name to indicate all the small mode settings."
   (setq mode-name
-	(concat "Org-Agenda"
-		(if (get 'org-agenda-files 'org-restrict) " []" "")
-		(if (equal org-agenda-ndays 1) " Day"    "")
-		(if (equal org-agenda-ndays 7) " Week"   "")
-		(if org-agenda-follow-mode     " Follow" "")
-		(if org-agenda-entry-text-mode " ETxt"   "")
-		(if org-agenda-include-diary   " Diary"  "")
-		(if org-agenda-include-deadlines " Ddl"  "")
-		(if org-agenda-use-time-grid   " Grid"   "")
-		(if (and (boundp 'org-habit-show-habits)
-			 org-habit-show-habits) " Habit"   "")
-		(if (consp org-agenda-show-log) " LogAll"
-		  (if org-agenda-show-log " Log" ""))
-		(if (or org-agenda-filter (get 'org-agenda-filter
-					       :preset-filter))
-		    (concat " {" (mapconcat
-				  'identity
-				  (append (get 'org-agenda-filter
-					       :preset-filter)
-					  org-agenda-filter) "") "}")
-		  "")
-		(if org-agenda-archives-mode
-		    (if (eq org-agenda-archives-mode t)
-			" Archives"
-		      (format " :%s:" org-archive-tag))
-		  "")
-		(if org-agenda-clockreport-mode
-		    (if (eq org-agenda-clockreport-mode 'with-filter)
-			" Clock{}" " Clock")
-		  "")))
+	(list "Org-Agenda"
+	      (if (get 'org-agenda-files 'org-restrict) " []" "")
+	      " "
+	      '(:eval (org-agenda-span-name org-agenda-current-span))
+	      (if org-agenda-follow-mode     " Follow" "")
+	      (if org-agenda-entry-text-mode " ETxt"   "")
+	      (if org-agenda-include-diary   " Diary"  "")
+	      (if org-agenda-include-deadlines " Ddl"  "")
+	      (if org-agenda-use-time-grid   " Grid"   "")
+	      (if (and (boundp 'org-habit-show-habits)
+		       org-habit-show-habits) " Habit"   "")
+	      (if (consp org-agenda-show-log) " LogAll"
+		(if org-agenda-show-log " Log" ""))
+	      (if (or org-agenda-filter (get 'org-agenda-filter
+					     :preset-filter))
+		  (concat " {" (mapconcat
+				'identity
+				(append (get 'org-agenda-filter
+					     :preset-filter)
+					org-agenda-filter) "") "}")
+		"")
+	      (if org-agenda-archives-mode
+		  (if (eq org-agenda-archives-mode t)
+		      " Archives"
+		    (format " :%s:" org-archive-tag))
+		"")
+	      (if org-agenda-clockreport-mode
+		  (if (eq org-agenda-clockreport-mode 'with-filter)
+		      " Clock{}" " Clock")
+		"")))
   (force-mode-line-update))
 
 (defun org-agenda-post-command-hook ()
@@ -7662,25 +7741,26 @@ This is a command that has to be installed in `calendar-mode-map'."
   (eq (get-char-property (point-at-bol) 'type)
       'org-marked-entry-overlay))
 
-(defun org-agenda-bulk-mark ()
+(defun org-agenda-bulk-mark (&optional arg)
   "Mark the entry at point for future bulk action."
-  (interactive)
-  (org-agenda-check-no-diary)
-  (let* ((m (org-get-at-bol 'org-hd-marker))
-	 ov)
-    (unless (org-agenda-bulk-marked-p)
-      (unless m (error "Nothing to mark at point"))
-      (push m org-agenda-bulk-marked-entries)
-      (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
-      (org-overlay-display ov "> "
-			   (org-get-todo-face "TODO")
-			   'evaporate)
-      (overlay-put ov 'type 'org-marked-entry-overlay))
-    (beginning-of-line 2)
-    (while (and (get-char-property (point) 'invisible) (not (eobp)))
-      (beginning-of-line 2))
-    (message "%d entries marked for bulk action"
-	     (length org-agenda-bulk-marked-entries))))
+  (interactive "p")
+  (dotimes (i (max arg 1))
+    (unless (org-get-at-bol 'org-agenda-diary-link)
+      (let* ((m (org-get-at-bol 'org-hd-marker))
+	     ov)
+	(unless (org-agenda-bulk-marked-p)
+	  (unless m (error "Nothing to mark at point"))
+	  (push m org-agenda-bulk-marked-entries)
+	  (setq ov (make-overlay (point-at-bol) (+ 2 (point-at-bol))))
+	  (org-overlay-display ov "> "
+			       (org-get-todo-face "TODO")
+			       'evaporate)
+	  (overlay-put ov 'type 'org-marked-entry-overlay))
+	(beginning-of-line 2)
+	(while (and (get-char-property (point) 'invisible) (not (eobp)))
+	  (beginning-of-line 2))
+	(message "%d entries marked for bulk action"
+		 (length org-agenda-bulk-marked-entries))))))
 
 (defun org-agenda-bulk-unmark ()
   "Unmark the entry at point for future bulk action."
@@ -7730,7 +7810,7 @@ The prefix arg is passed through to the command if possible."
   (interactive "P")
   (unless org-agenda-bulk-marked-entries
     (error "No entries are marked"))
-  (message "Bulk: [r]efile [$]archive [A]rch->sib [t]odo [+/-]tag [s]chedule [d]eadline")
+  (message "Bulk: [r]efile [$]arch [A]rch->sib [t]odo [+/-]tag [s]chd [S]catter [d]eadline")
   (let* ((action (read-char-exclusive))
 	 (org-log-refile (if org-log-refile 'time nil))
 	 (entries (reverse org-agenda-bulk-marked-entries))
@@ -7792,6 +7872,29 @@ The prefix arg is passed through to the command if possible."
 		       (if bound
 			   (fset 'read-string old)
 			 (fmakunbound 'read-string)))))))
+
+     ((eq action '?S)
+      (let ((days (read-number
+		   (format "Scatter tasks across how many %sdays: "
+			   (if arg "week" "")) 7)))
+	(setq cmd
+	      `(let ((distance (random ,(1+ days))))
+		 (if arg
+		     (let ((dist distance)
+			   (day-of-week
+			    (calendar-day-of-week
+			     (calendar-gregorian-from-absolute (org-today)))))
+		       (dotimes (i (1+ dist))
+			 (while (member day-of-week org-agenda-weekend-days)
+			   (incf distance)
+			   (incf day-of-week)
+			   (if (= day-of-week 7)
+			       (setq day-of-week 0)))
+			 (incf day-of-week)
+			 (if (= day-of-week 7)
+			     (setq day-of-week 0)))))
+		 (org-agenda-date-later distance)))))
+
      (t (error "Invalid bulk action")))
 
     ;; Sort the markers, to make sure that parents are handled before children
@@ -7903,7 +8006,7 @@ belonging to the \"Work\" category."
   (let* ((cnt 0) ; count added events
 	 (org-agenda-new-buffers nil)
 	 (org-deadline-warning-days 0)
-	 ;; Do not use `org-agenda-today' here because appt only takes
+	 ;; Do not use `org-today' here because appt only takes
 	 ;; time and without date as argument, so it may pass wrong
 	 ;; information otherwise
 	 (today (org-date-to-gregorian
@@ -7946,15 +8049,9 @@ belonging to the \"Work\" category."
 	(message "No event to add")
       (message "Added %d event%s for today" cnt (if (> cnt 1) "s" "")))))
 
-(defun org-agenda-today ()
-  "Return today date, considering `org-extend-today-until'."
-  (time-to-days
-   (time-subtract (current-time)
-		  (list 0 (* 3600 org-extend-today-until) 0))))
-
 (defun org-agenda-todayp (date)
   "Does DATE mean today, when considering `org-extend-today-until'?"
-  (let ((today (org-agenda-today))
+  (let ((today (org-today))
 	(date (if (and date (listp date)) (calendar-absolute-from-gregorian date)
 		date)))
     (eq date today)))

+ 16 - 13
lisp/org-capture.el

@@ -473,9 +473,11 @@ bypassed."
      (t (setq txt "* Invalid capture template")))
     (org-capture-put :template txt)))
 
-(defun org-capture-finalize ()
-  "Finalize the capture process."
-  (interactive)
+(defun org-capture-finalize (&optional stay-with-capture)
+  "Finalize the capture process.
+With prefix argument STAY-WITH-CAPTURE, jump to the location of the
+captured item after finalizing."
+  (interactive "P")
   (unless (and org-capture-mode
 	       (buffer-base-buffer (current-buffer)))
     (error "This does not seem to be a capture buffer for Org-mode"))
@@ -562,17 +564,23 @@ bypassed."
       (set-window-configuration return-wconf))
 
     (run-hooks 'org-capture-after-finalize-hook)
-    (when abort-note
+    ;; Special cases
+    (cond
+     (abort-note
       (cond
        ((equal abort-note 'clean)
 	(message "Capture process aborted and target buffer cleaned up"))
        ((equal abort-note 'dirty)
-	(error "Capture process aborted, but target buffer could not be cleaned up correctly"))))))
+	(error "Capture process aborted, but target buffer could not be cleaned up correctly"))))
+     (stay-with-capture
+      (org-capture-goto-last-stored)))
+    ;; Return if we did store something
+    (not abort-note)))
 
 (defun org-capture-refile ()
   "Finalize the current capture and then refile the entry.
 Refiling is done from the base buffer, because the indirect buffer is then
-already gone."
+already gone.  Any prefix argument will be passed to the refile comand."
   (interactive)
   (unless (eq (org-capture-get :type 'local) 'entry)
     (error
@@ -671,15 +679,10 @@ already gone."
 	    ;; prompt for date
 	    (time-to-days (org-read-date 
 			   nil t nil "Date for tree entry:"
-			   (time-subtract (current-time)
-					  (list 0 (* 3600 
-						     org-extend-today-until)
-						0)))))
+			   (days-to-time (org-today)))))
 	   (t
 	    ;; current date, possible corrected for late night workers
-	    (time-to-days
-	     (time-subtract (current-time)
-			    (list 0 (* 3600 org-extend-today-until) 0))))))))
+	    (org-today))))))
        
        ((eq (car target) 'file+function)
 	(set-buffer (org-capture-target-buffer (nth 1 target)))

+ 187 - 55
lisp/org-clock.el

@@ -1654,6 +1654,62 @@ buffer and update it."
 	   (>= (match-end 0) pos)
 	   start))))
 
+(defun org-day-of-week (day month year)
+  "Returns the day of the week as an integer."
+  (nth 6
+       (decode-time
+	(date-to-time
+	 (format "%d-%02d-%02dT00:00:00" year month day)))))
+
+(defun org-quarter-to-date (quarter year)
+  "Get the date (week day year) of the first day of a given quarter."
+  (let (startday)
+    (cond
+     ((= quarter 1)
+      (setq startday (org-day-of-week 1 1 year))
+      (cond
+       ((= startday 0)
+	(list 52 7 (- year 1)))
+       ((= startday 6)
+	(list 52 6 (- year 1)))
+       ((<= startday 4)
+	(list 1 startday year))
+       ((> startday 4)
+	(list 53 startday (- year 1)))
+       )
+      )
+     ((= quarter 2)
+      (setq startday (org-day-of-week 1 4 year))
+      (cond
+       ((= startday 0)
+	(list 13 startday year))
+       ((< startday 4)
+	(list 14 startday year))
+       ((>= startday 4)
+	(list 13 startday year))
+       )
+      )
+     ((= quarter 3)
+      (setq startday (org-day-of-week 1 7 year))
+      (cond
+       ((= startday 0)
+	(list 26 startday year))
+       ((< startday 4)
+	(list 27 startday year))
+       ((>= startday 4)
+	(list 26 startday year))
+       )
+      )
+     ((= quarter 4)
+      (setq startday (org-day-of-week 1 10 year))
+      (cond
+       ((= startday 0)
+	(list 39 startday year))
+       ((<= startday 4)
+	(list 40 startday year))
+       ((> startday 4)
+	(list 39 startday year)))))))
+
 (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',
@@ -1670,7 +1726,12 @@ the returned times will be formatted strings."
 	 (dow (nth 6 tm))
 	 (skey (symbol-name key))
 	 (shift 0)
-	 s1 m1 h1 d1 month1 y1 diff ts te fm txt w date)
+         (q (cond ((>= (nth 4 tm) 10) 4)
+                  ((>= (nth 4 tm) 7) 3)
+                  ((>= (nth 4 tm) 4) 2)
+                  ((>= (nth 4 tm) 1) 1)))
+	 s1 m1 h1 d1 month1 y1 diff ts te fm txt w date
+	 interval tmp shiftedy shiftedm shiftedq)
     (cond
      ((string-match "^[0-9]+$" skey)
       (setq y (string-to-number skey) m 1 d 1 key 'year))
@@ -1687,6 +1748,15 @@ the returned times will be formatted strings."
       (setq d (nth 1 date) month (car date) y (nth 2 date)
 	    dow 1
 	    key 'week))
+      ((string-match "^\\([0-9]+\\)-[qQ]\\([1-4]\\)$" skey)
+       (require 'cal-iso)
+       (setq y (string-to-number (match-string 1 skey)))
+       (setq q (string-to-number (match-string 2 skey)))
+       (setq date (calendar-gregorian-from-absolute
+                   (calendar-absolute-from-iso (org-quarter-to-date q y))))
+       (setq d (nth 1 date) month (car date) y (nth 2 date)
+            dow 1
+            key 'quarter))
      ((string-match "^\\([0-9]+\\)-\\([0-9]\\{1,2\\}\\)-\\([0-9]\\{1,2\\}\\)$" skey)
       (setq y (string-to-number (match-string 1 skey))
 	    month (string-to-number (match-string 2 skey))
@@ -1694,12 +1764,17 @@ the returned times will be formatted strings."
 	    key 'day))
      ((string-match "\\([-+][0-9]+\\)$" skey)
       (setq shift (string-to-number (match-string 1 skey))
-	    key (intern (substring skey 0 (match-beginning 1))))))
+            key (intern (substring skey 0 (match-beginning 1))))
+       (if(and (memq key '(quarter thisq)) (> shift 0))
+         (error "Looking forward with quarters isn't implemented.")
+        ())))
+
     (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 ((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))
+            ((eq key 'lastq)     (setq key 'quarter shift -1))))
     (cond
      ((memq key '(day today))
       (setq d (+ d shift) h 0 m 0 h1 24 m1 0))
@@ -1708,6 +1783,28 @@ the returned times will be formatted strings."
 	    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 '(quarter thisq))
+      ; compute if this shift remains in this year
+      ; if not, compute how many years and quarters we have to shift (via floor*)
+      ; and compute the shifted years, months and quarters
+      (cond
+       ((< (+ (- q 1) shift) 0) ; shift not in this year
+       (setq interval (* -1 (+ (- q 1) shift)))
+       ; set tmp to ((years to shift) (quarters to shift))
+       (setq tmp (org-floor* interval 4))
+       ; due to the use of floor, 0 quarters actually means 4
+       (if (= 0 (nth 1 tmp))
+           (setq shiftedy (- y (nth 0 tmp))
+                 shiftedm 1
+                 shiftedq 1)
+         (setq shiftedy (- y (+ 1 (nth 0 tmp)))
+               shiftedm (- 13 (* 3 (nth 1 tmp)))
+               shiftedq (- 5 (nth 1 tmp))))
+       (setq d 1 h 0 m 0 d1 1 month shiftedm month1 (+ 3 shiftedm) h1 0 m1 0 y shiftedy))
+       ((> (+ q shift) 0) ; shift is whitin this year
+       (setq shiftedq (+ q shift))
+       (setq shiftedy y)
+       (setq d 1 h 0 m 0 d1 1 month (+ 1 (* 3 (- (+ q shift) 1))) month1 (+ 4 (* 3 (- (+ q shift) 1))) 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)))
@@ -1723,11 +1820,21 @@ the returned times will be formatted strings."
      ((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))))
+      (setq txt (format-time-string "the year %Y" ts)))
+     ((memq key '(quarter thisq))
+      (setq txt (concatenate 'string (org-count-quarter shiftedq) " quarter of " (number-to-string shiftedy))))
+     )
     (if as-strings
 	(list (format-time-string fm ts) (format-time-string fm te) txt)
       (list ts te txt))))
 
+(defun org-count-quarter (n)
+  (cond
+   ((= n 1) "1st")
+   ((= n 2) "2nd")
+   ((= n 3) "3rd")
+   ((= n 4) "4th")))
+
 (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
@@ -1750,45 +1857,63 @@ the currently selected interval size."
 	 ((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)))))
+	 ((equal s "lastyear") (setq s "thisyear-1"))
+	 ((equal s "lastq") (setq s "thisq-1")))
+
+       (cond
+        ((string-match "^\\(today\\|thisweek\\|thismonth\\|thisyear\\|thisq\\)\\([-+][0-9]+\\)?$" s)
+         (setq block (match-string 1 s)
+               shift (if (match-end 2)
+                         (string-to-number (match-string 2 s))
+                       0))
+         (setq shift (+ shift n))
+         (setq ins (if (= shift 0) block (format "%s%+d" block shift))))
+	((string-match "\\([0-9]+\\)\\(-\\([wWqQ]?\\)\\([0-9]\\{1,2\\}\\)\\(-\\([0-9]\\{1,2\\}\\)\\)?\\)?" s)
+        ;;               1        1  2   3       3  4                  4  5   6                6  5   2
+         (setq y (string-to-number (match-string 1 s))
+               wp (and (match-end 3) (match-string 3 s))
+               mw (and (match-end 4) (string-to-number (match-string 4 s)))
+	       d (and (match-end 6) (string-to-number (match-string 6 s))))
+	 (cond
+	  (d (setq ins (format-time-string
+                        "%Y-%m-%d"
+                        (encode-time 0 0 0 (+ d n) m y))))
+          ((and wp (string-match "w\\|W" wp) mw (> (length wp) 0))
+           (require 'cal-iso)
+           (setq date (calendar-gregorian-from-absolute (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)))))
+	  ((and wp (string-match "q\\|Q" wp) mw (> (length wp) 0))
+           (require 'cal-iso)
+	   ; if the 4th + 1 quarter is requested we flip to the 1st quarter of the next year
+           (if (> (+ mw n) 4)
+               (setq mw 0
+                     y (+ 1 y))
+	     ())
+	   ; if the 1st - 1 quarter is requested we flip to the 4th quarter of the previous year
+           (if (= (+ mw n) 0)
+               (setq mw 5
+                     y (- y 1))
+             ())
+           (setq date (calendar-gregorian-from-absolute (calendar-absolute-from-iso (org-quarter-to-date (+ mw n) y))))
+           (setq ins (format-time-string
+                      (concatenate 'string (number-to-string y) "-Q" (number-to-string (+ mw n)))
+                      (encode-time 0 0 0 (nth 1 date) (car date) (nth 2 date)))))
+          (mw
+           (setq ins (format-time-string
+                      "%Y-%m"
+		      (encode-time 0 0 0 1 (+ mw n) y))))
+	  (y
+	   (setq ins (number-to-string (+ y n))))))
+	(t (error "Cannot shift clocktable block")))
+       (when ins
+	 (goto-char b)
+	 (insert ins)
+	 (delete-region (point) (+ (point) (- e b)))
+	 (beginning-of-line 1)
+	 (org-update-dblock)
+	 t)))))
 
 (defun org-dblock-write:clocktable (params)
   "Write the standard clocktable."
@@ -1905,7 +2030,7 @@ from the dynamic block defintion."
 	 (indent (plist-get params :indent))
 	 range-text total-time tbl level hlc formula pcol
 	 file-time entries entry headline
-	 recalc content narrow-cut-p)
+	 recalc content narrow-cut-p tcol)
 
     ;; Implement abbreviations
     (when (plist-get params :compact)
@@ -2038,18 +2163,25 @@ from the dynamic block defintion."
       (if (setq formula (plist-get params :formula))
 	  (cond
 	   ((eq formula '%)
-	    (setq pcol (+ 3
+	    ;; compute the column where the % numbers need to go
+	    (setq pcol (+ 2
+			  (if multifile 1 0)
+			  (if level-p 1 0)
+			  (if timestamp 1 0)
+			  (min maxlevel (or ntcol 100))))
+	    ;; compute the column where the total time is
+	    (setq tcol (+ 2
 			  (if multifile 1 0)
-			  (min maxlevel (or ntcol 100))
+			  (if level-p 1 0)
 			  (if timestamp 1 0)))
 	    (insert
 	     (format
 	      "\n#+TBLFM: $%d='(org-clock-time%% @%d$%d $%d..$%d);%%.1f"
-	      pcol
-	      (+ 2 (if narrow 1 0))
-	      (+ 3 (if multifile 1 0))
-	      (+ (if multifile 1 0) 3)
-	      (1- pcol)))
+	      pcol            ; the column where the % numbers should go
+	      (if (and narrow (not narrow-cut-p)) 3 2) ; row of the total time
+	      tcol            ; column of the total time
+	      tcol (1- pcol)  ; range of columns where times can be found
+	      ))
 	    (setq recalc t))
 	   ((stringp formula)
 	    (insert "\n#+TBLFM: " formula)
@@ -2071,7 +2203,7 @@ from the dynamic block defintion."
       (when recalc
 	(if (eq formula '%)
 	    (save-excursion
-	      (if narrow (beginning-of-line 2))
+	      (if (and narrow (not narrow-cut-p)) (beginning-of-line 2))
 	      (org-table-goto-column pcol nil 'force)
 	      (insert "%")))
 	(org-table-recalculate 'all))

+ 6 - 0
lisp/org-compat.el

@@ -418,6 +418,12 @@ LIMIT."
 	      (looking-at (concat "\\(?:"  regexp "\\)\\'")))))
       (not (null pos)))))
 
+(defun org-floor* (x &optional y)
+  "Return a list of the floor of X and the fractional part of X.
+With two arguments, return floor and remainder of their quotient."
+  (let ((q (floor x y)))
+    (list q (- x (if y (* y q) q)))))
+
 (provide 'org-compat)
 
 ;; arch-tag: a0a0579f-e68c-4bdf-9e55-93768b846bbe

+ 18 - 0
lisp/org-complete.el

@@ -35,6 +35,16 @@
 (require 'org-macs)
 (require 'pcomplete)
 
+(declare-function org-split-string "org" (string &optional separators))
+(declare-function org-get-current-options "org-exp" ())
+(declare-function org-make-org-heading-search-string "org"
+		  (&optional string heading))
+(declare-function org-get-buffer-tags "org" ())
+(declare-function org-get-tags "org" ())
+(declare-function org-buffer-property-keys "org"
+		  (&optional include-specials include-defaults include-columns))
+(declare-function org-entry-properties "org" (&optional pom which specific))
+
 ;;;; Customization variables
 
 (defgroup org-complete nil
@@ -119,6 +129,7 @@ When completing for #+STARTUP, for example, this function returns
 		 (car (org-thing-at-point)))
 		pcomplete-default-completion-function))))
 
+(defvar org-additional-option-like-keywords)
 (defun pcomplete/org-mode/file-option ()
   "Complete against all valid file options."
   (require 'org-exp)
@@ -138,6 +149,7 @@ When completing for #+STARTUP, for example, this function returns
 		    org-additional-option-like-keywords)))))
    (substring pcomplete-stub 2)))
   
+(defvar org-startup-options)
 (defun pcomplete/org-mode/file-option/startup ()
   "Complete arguments for the #+STARTUP file option."
   (while (pcomplete-here
@@ -158,12 +170,15 @@ When completing for #+STARTUP, for example, this function returns
      (lambda (a) (if (boundp a) (setq vars (cons (symbol-name a) vars)))))
     (pcomplete-here vars)))
 
+(defvar org-link-abbrev-alist-local)
+(defvar org-link-abbrev-alist)
 (defun pcomplete/org-mode/link ()
   "Complete against defined #+LINK patterns."
   (pcomplete-here
    (pcomplete-uniqify-list (append (mapcar 'car org-link-abbrev-alist-local)
 				   (mapcar 'car org-link-abbrev-alist)))))
 
+(defvar org-entities)
 (defun pcomplete/org-mode/tex ()
   "Complete against TeX-style HTML entity names."
   (require 'org-entities)
@@ -171,10 +186,12 @@ When completing for #+STARTUP, for example, this function returns
 	  (pcomplete-uniqify-list (remove nil (mapcar 'car-safe org-entities)))
 	  (substring pcomplete-stub 1))))
 
+(defvar org-todo-keywords-1)
 (defun pcomplete/org-mode/todo ()
   "Complete against known TODO keywords."
   (pcomplete-here (pcomplete-uniqify-list org-todo-keywords-1)))
 
+(defvar org-todo-line-regexp)
 (defun pcomplete/org-mode/searchhead ()
   "Complete against all headings.
 This needs more work, to handle headings with lots of spaces in them."
@@ -190,6 +207,7 @@ This needs more work, to handle headings with lots of spaces in them."
 	(pcomplete-uniqify-list tbl)))
     (substring pcomplete-stub 1))))
 
+(defvar org-tag-alist)
 (defun pcomplete/org-mode/tag ()
   "Complete a tag name.  Omit tags already set."
   (while (pcomplete-here

+ 1 - 4
lisp/org-habit.el

@@ -197,10 +197,7 @@ This list represents a \"habit\" for the rest of this module."
   "Determine the relative priority of a habit.
 This must take into account not just urgency, but consistency as well."
   (let ((pri 1000)
-	(now (time-to-days
-	      (or moment
-		  (time-subtract (current-time)
-				 (list 0 (* 3600 org-extend-today-until) 0)))))
+	(now (if moment (time-to-days moment) (org-today)))
 	(scheduled (org-habit-scheduled habit))
 	(deadline (org-habit-deadline habit)))
     ;; add 10 for every day past the scheduled date, and subtract for every

+ 1 - 1
lisp/org-latex.el

@@ -2383,7 +2383,7 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
 			   "\n"
 			   (match-string 1 res))
 		   t t res)))
-      (insert res "\n"))))
+      (insert res))))
 
 (defconst org-latex-entities
  '("\\!"

+ 5 - 1
lisp/org-list.el

@@ -518,7 +518,11 @@ List ending is determined by the indentation of text. See
 	      (setq ind-ref ind)
 	      (forward-line 1))
 	     ((<= ind ind-ref)
-	      (throw 'exit (point-at-bol)))
+	      (throw 'exit (progn
+			     ;; Again, ensure bottom is just after a
+			     ;; non-blank line.
+			     (skip-chars-backward " \r\t\n")
+			     (min (point-max) (1+ (point-at-eol))))))
 	     ((looking-at "#\\+begin_")
 	      (re-search-forward "[ \t]*#\\+end_")
 	      (forward-line 1))

+ 6 - 5
lisp/org-macs.el

@@ -49,11 +49,12 @@
 	 (with-no-warnings (called-interactively-p ,kind)) ;; defined with no argument in <=23.1
        (interactive-p))))
 
-(if (or (< emacs-major-version 23)
-	(and (<= emacs-major-version 23)
-	     (< emacs-minor-version 2)))
-    (defmacro with-silent-modifications
-      (org-unmodified)))
+(if (and (not (fboundp 'with-silent-modifications))
+	 (or (< emacs-major-version 23)
+	     (and (= emacs-major-version 23)
+		  (< emacs-minor-version 2))))
+    (defmacro with-silent-modifications (&rest body)
+      `(org-unmodified ,@body)))
 
 (defmacro org-bound-and-true-p (var)
   "Return the value of symbol VAR if it is bound, else nil."

+ 2 - 2
lisp/org-mouse.el

@@ -1100,10 +1100,10 @@ This means, between the beginning of line and the point."
 	 "--"
 	 ["Day View" org-agenda-day-view
 	  :active (org-agenda-check-type nil 'agenda)
-	  :style radio :selected (equal org-agenda-ndays 1)]
+	  :style radio :selected (eq org-agenda-current-span 'day)]
 	 ["Week View" org-agenda-week-view
 	  :active (org-agenda-check-type nil 'agenda)
-	  :style radio :selected (equal org-agenda-ndays 7)]
+	  :style radio :selected (eq org-agenda-current-span 'week)]
 	 "--"
 	 ["Show Logbook entries" org-agenda-log-mode
 	  :style toggle :selected org-agenda-show-log

+ 28 - 12
lisp/org.el

@@ -72,11 +72,10 @@
 
 (eval-when-compile
   (require 'cl)
-  (require 'gnus-sum)
-)
+  (require 'gnus-sum))
 
 (require 'calendar)
-(require 'pcomplete)
+
 ;; Emacs 22 calendar compatibility:  Make sure the new variables are available
 (when (fboundp 'defvaralias)
   (unless (boundp 'calendar-view-holidays-initially-flag)
@@ -1386,12 +1385,15 @@ nil   Never use an ID to make a link, instead link using a text search for
 (defcustom org-context-in-file-links t
   "Non-nil means file links from `org-store-link' contain context.
 A search string will be added to the file name with :: as separator and
-used to find the context when the link is activated by the command
-`org-open-at-point'.
+used to find the context when the link is activated by the command 
+`org-open-at-point'. When this option is t, the entire active region 
+will be placed in the search string of the file link. If set to a 
+positive integer, only the first n lines of context will be stored.
+
 Using a prefix arg to the command \\[org-store-link] (`org-store-link')
 negates this setting for the duration of the command."
   :group 'org-link-store
-  :type 'boolean)
+  :type '(choice boolean integer))
 
 (defcustom org-keep-stored-link-after-insertion nil
   "Non-nil means keep link in list for entire session.
@@ -2732,10 +2734,10 @@ To disable these tags on a per-file basis, insert anywhere in the file:
 (defcustom org-complete-tags-always-offer-all-agenda-tags nil
   "If non-nil, always offer completion for all tags of all agenda files.
 Instead of customizing this variable directly, you might want to
-set it locally for remember buffers, because there no list of
+set it locally for capture buffers, because there no list of
 tags in that file can be created dynamically (there are none).
 
-  (add-hook 'org-remember-mode-hook
+  (add-hook 'org-capture-mode-hook
             (lambda ()
               (set (make-local-variable
                     'org-complete-tags-always-offer-all-agenda-tags)
@@ -4798,6 +4800,12 @@ The following commands are available:
 		       (nthcdr 2 time))))
     (current-time)))
 
+(defun org-today ()
+  "Return today date, considering `org-extend-today-until'."
+  (time-to-days
+   (time-subtract (current-time)
+		  (list 0 (* 3600 org-extend-today-until) 0))))
+
 ;;;; Font-Lock stuff, including the activators
 
 (defvar org-mouse-map (make-sparse-keymap))
@@ -6068,8 +6076,8 @@ With a numeric prefix, show all headlines up to that level."
   (interactive)
   (let (org-show-entry-below state)
     (save-excursion
-      (goto-char (point-max))
-      (while (re-search-backward
+      (goto-char (point-min))
+      (while (re-search-forward
 	      "^[ \t]*:VISIBILITY:[ \t]+\\([a-z]+\\)"
 	      nil t)
 	(setq state (match-string 1))
@@ -7598,7 +7606,7 @@ and still retain the repeater to cover future instances of the task."
 	    (and idprop (if org-clone-delete-id
 			    (org-entry-delete nil "ID")
 			  (org-id-get-create t)))
-	    (while (re-search-forward org-property-drawer-re nil t)
+	    (while (re-search-forward org-property-start-re nil t)
 	      (org-remove-empty-drawer-at "PROPERTIES" (point)))
 	    (goto-char (point-min))
 	    (when doshift
@@ -8496,7 +8504,8 @@ according to FMT (default from `org-email-link-description-format')."
 (defun org-make-org-heading-search-string (&optional string heading)
   "Make search string for STRING or current headline."
   (interactive)
-  (let ((s (or string (org-get-heading))))
+  (let ((s (or string (org-get-heading)))
+	(lines org-context-in-file-links))
     (unless (and string (not heading))
       ;; We are using a headline, clean up garbage in there.
       (if (string-match org-todo-regexp s)
@@ -8510,6 +8519,13 @@ according to FMT (default from `org-email-link-description-format')."
       (while (string-match org-ts-regexp s)
 	(setq s (replace-match "" t t s))))
     (or string (setq s (concat "*" s)))  ; Add * for headlines
+    (when (and string (integerp lines) (> lines 0))
+      (let ((slines (org-split-string s "\n")))
+	(when (< lines (length slines))
+	  (setq s (mapconcat 
+		   'identity
+		   (reverse (nthcdr (- (length slines) lines) 
+				    (reverse slines))) "\n")))))
     (mapconcat 'identity (org-split-string s "[ \t]+") " ")))
 
 (defun org-make-link (&rest strings)

+ 8 - 0
testing/lisp/test-org.el

@@ -84,6 +84,14 @@
     "àâçèéêîôùû"
     (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB"))))
 
+(ert-deftest test-org/org-link-escape-url-with-escaped-char ()
+  "Escape and unscape a URL that includes an escaped char.
+http://article.gmane.org/gmane.emacs.orgmode/21459/"
+  (should
+   (string=
+    "http://some.host.com/form?&id=blah%2Bblah25"
+    (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
+
 (provide 'test-org)
 
 ;;; test-org.el ends here